player: Fixed isPhaseOver bug
This commit is contained in:
parent
f6f3f4a6a1
commit
8a4e83b9a7
@ -241,15 +241,13 @@ public class Player {
|
|||||||
public boolean canPlay(State state) {
|
public boolean canPlay(State state) {
|
||||||
|
|
||||||
// Check if the player has placed all their settlers or villages
|
// Check if the player has placed all their settlers or villages
|
||||||
int startNumSettlers = switch (state.getNumPlayers()) {
|
int numSettlers = 30 - ((state.getNumPlayers() - 2) * 5);
|
||||||
case 2 -> 30;
|
boolean hasSettler = (settlers.length < numSettlers);
|
||||||
case 3 -> 25;
|
|
||||||
case 4 -> 20;
|
|
||||||
default -> 0;
|
|
||||||
};
|
|
||||||
boolean hasSettler = (settlers.length < startNumSettlers);
|
|
||||||
boolean hasVillage = (settlers.length < 5);
|
boolean hasVillage = (settlers.length < 5);
|
||||||
if (!hasSettler && !(hasVillage && state.getCurrentPhase() == 'E')) return false;
|
if (state.getCurrentPhase() != 'E'){
|
||||||
|
if (!hasSettler && !hasVillage) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Add used coords
|
// Add used coords
|
||||||
ArrayList<String> settlerCoords = new ArrayList<>(); // Placed Settler Coordinates
|
ArrayList<String> settlerCoords = new ArrayList<>(); // Placed Settler Coordinates
|
||||||
@ -265,7 +263,6 @@ public class Player {
|
|||||||
villageCoords.add(c.toString());
|
villageCoords.add(c.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Coord c: settlers){
|
for (Coord c: settlers){
|
||||||
playerSettlerCoords.add(c.toString());
|
playerSettlerCoords.add(c.toString());
|
||||||
}
|
}
|
||||||
@ -305,24 +302,13 @@ public class Player {
|
|||||||
else if(y > state.boardHeight - 1) continue;
|
else if(y > state.boardHeight - 1) continue;
|
||||||
switch (state.getCurrentPhase()) {
|
switch (state.getCurrentPhase()) {
|
||||||
case 'E' -> {
|
case 'E' -> {
|
||||||
if (!islandCoords.contains(cord)) {
|
if (!islandCoords.contains(cord)) return true;
|
||||||
if (hasSettler) return true;
|
if ((isAdjacent(cord, playerVillageCoords) || isAdjacent(cord, playerSettlerCoords))) return true;
|
||||||
break;
|
|
||||||
}
|
|
||||||
// If the Village is being placed on the sea return false
|
|
||||||
if ((isAdjacent(cord, playerVillageCoords) || isAdjacent(cord, playerSettlerCoords))) {
|
|
||||||
// Add the move to the set
|
|
||||||
if (hasVillage) return true;
|
|
||||||
if (hasSettler) return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Settlement Phase
|
// Settlement Phase
|
||||||
case 'S' -> {
|
case 'S' -> {
|
||||||
// if the settler is not adjacent with any of the pieces return false
|
// if the settler is adjacent with any of the pieces return true
|
||||||
if ((isAdjacent(cord, playerVillageCoords) || isAdjacent(cord, playerSettlerCoords))) {
|
if ((isAdjacent(cord, playerVillageCoords) || isAdjacent(cord, playerSettlerCoords))) return true;
|
||||||
// Add the move to the set
|
|
||||||
if (hasSettler) return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user