@Override public List<DiscreteGameState> availableStates() { List<Position> availableMoves = board.getOpenPositions(); List<DiscreteGameState> availableStates = new ArrayList<DiscreteGameState>(availableMoves.size()); for (Position move : availableMoves) { TicTacToeGameState newState = new TicTacToeGameState(this); newState.play(move.getRow(), move.getCol()); newState.switchPlayer(); availableStates.add(newState); } return availableStates; }
/** * Creates a deep copy of the given TicTacToe game state. * * @param other the TicTacToe game state to copy */ public TicTacToeGameState(TicTacToeGameState other) { this.board = new GameBoard(other.board); this.currentPlayer = other.getCurrentPlayer(); this.lastMove = other.lastMove; }