package comp1110.ass2; /** * Object to store the game state * This stores the state of the game in a way that is easy to access and modify * It stores the board height, number of players, current player, current phase, islands, stones, * unclaimed resources and players (with their data) * */ public class State { final int boardHeight; private int numPlayers; private int currentPlayer; private int currentPhase; // 0 for exploration, 1 for settlement private Island[] islands; private Coord[] stonesCoords; private Resource[] unclaimedResources; private Player[] players; /** * Constructor for the state object * This takes a string containing the state of the game and initialises the object * @param stateString String containing the state of the game */ public State(String stateString) { // Split the state string into its components String[] components = stateString.split(";"); // For the game initialisation part String[] gameInitComponents = components[0].trim().split(" "); boardHeight = Integer.parseInt(gameInitComponents[1]); numPlayers = Integer.parseInt(gameInitComponents[2]); // Current state part String[] currentStateComponents = components[1].trim().split(" "); currentPlayer = Integer.parseInt(currentStateComponents[1]); if (currentStateComponents[2].equals("E")) currentPhase = 0; else currentPhase = 1; // Islands part int islandcount = 0; for (int i=2; i< components.length; i++) { // Split island part String[] islandComponents = components[i].trim().split(" "); // Check if the component is still an island if (!islandComponents[0].equals("i")) break; Island tmpIsland = new Island(Integer.parseInt(islandComponents[1])); // Add each coord for (int j=2; j