diff --git a/src/comp1110/ass2/BlueLagoon.java b/src/comp1110/ass2/BlueLagoon.java index 5e06e02..f7bc865 100644 --- a/src/comp1110/ass2/BlueLagoon.java +++ b/src/comp1110/ass2/BlueLagoon.java @@ -1,5 +1,6 @@ package comp1110.ass2; +import java.lang.module.FindException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -625,6 +626,24 @@ public class BlueLagoon { return state.toString(); } + public static void main(String[] args) { + applyMove(GameData.DEFAULT_GAME, "S 0,2"); + } + + /** + * Given a state string and a move string, apply the move to the board. + *
+ * If the move ends the phase, apply the end of phase rules. + *
+ * Advance current player to the next player in turn order that has a valid + * move they can make. + * + * @param stateString a string representing a game state + * @param moveString a string representing the current player's move + * @return a string representing the new state after the move is applied to the board + */ + + // 2 phases, exploration and settlement /** * Given a state string and a move string, apply the move to the board. *
@@ -644,23 +663,96 @@ public class BlueLagoon { int x = Integer.parseInt(coordStr.split(",")[0]); int y = Integer.parseInt(coordStr.split(",")[1]); Coord coord = new Coord(x, y); - state.placePiece(coord, pieceType); + + if ( isMoveValid(stateString, moveString)) state.placePiece(coord, pieceType); if (state.isPhaseOver()){ - state.scorePhase(); if (state.getCurrentPhase() == 'E') { + state.scorePhase(); state.cleanBoard(); state.distributeResources(); + state.nextPhase(); + } + else if (state.getCurrentPhase() == 'S') { + state.scorePhase(); + state.nextPlayer(); } } + state.nextPlayer(); - while (!state.getCurrentPlayer().canPlay(state)) { - state.nextPlayer(); - } +// while (!state.getCurrentPlayer().canPlay(state)) { +// state.nextPlayer(); +// } return state.toString(); } + + // /** + // * Get the current phase + // * Returns 'E' for exploration, 'S' for settlement, 'O' for game over + // * @return char current phase + // */ + // public char getCurrentPhase() { + // if (currentPhase == 0) return 'E'; + // else if (currentPhase == 1) return 'S'; + // else return 'O'; // Return 'O' for game over + // } + + //* A phase is over when either of the following conditions hold: + // * - All resources (not including statuettes) have been collected. + // * - No player has any remaining valid moves. + + ///** + // * Given a state string, determine whether it represents an end of phase state. + // *
+ // * A phase is over when either of the following conditions hold: + // * - All resources (not including statuettes) have been collected. + // * - No player has any remaining valid moves. + // * + // * @param stateString a string representing a game state + // * @return true if the state is at the end of either phase and false otherwise + // */ + // public static boolean isPhaseOver(String stateString){ + // State state = new State(stateString); + // return state.isPhaseOver(); + // } + + ///** + // * Score for that phase + // * This does not automatically move to the next phase + // */ + // public void scorePhase() { + // for (Player p: players) { + // p.addScore(createScore(p.getPlayerID())); + // } + // } + + ///** + // * Place a piece on the board. Uses current turn's player + // * This does not check if the move is valid (Use isValidMove() first) + // * @param coord Coord coordinate to place piece + // * @param type char type of piece + // */ + // public void placePiece(Coord coord, char type) { + // if (type == 'S') { + // players[currentPlayer].addSettler(coord); + // } + // else if (type == 'V' || type == 'T') { + // players[currentPlayer].addVillage(coord); + // } + // + // // Claim resource if it is a stone circle + // if (isStone(coord)) { + // for (Resource resource : resources) { + // if (resource.getCoord().equals(coord) && resource.isAvailable()) { + // players[currentPlayer].addResource(1, resource.getType()); + // resource.setClaimed(); + // } + // } + // } + // } + /** * Given a state string, returns a valid move generated by your AI. *