@Test public void testMakeMove() throws Exception { double[] stateValues = BoardUtils.getValues(initialState.getBoard()); List<OthelloMove> moves = othelloRules.findMoves(initialState); for (OthelloMove move : moves) { OthelloState afterState = othelloRules.makeMove(initialState, move); double[] afterStateValues = BoardUtils.getValues(afterState.getBoard()); int numDiffLocations = 0; for (int i = 0; i < stateValues.length; i++) { if (stateValues[i] != afterStateValues[i]) { numDiffLocations++; } } Assert.assertEquals(2, numDiffLocations); } }
@Override public OthelloState makeMove(OthelloState state, OthelloMove action) { OthelloBoard board = state.getBoard(); if (action == null) { return new OthelloState(board.clone(), opponent(state.getPlayerToMove())); } OthelloBoard nextBoard = board.createAfterState(action.getRow(), action.getCol(), state.getPlayerToMove()); return new OthelloState(nextBoard, opponent(state.getPlayerToMove())); }
OthelloRules implements GameRules<OthelloState, OthelloMove> { @Override public OthelloState makeMove(OthelloState state, OthelloMove action) { OthelloBoard board = state.getBoard(); if (action == null) { return new OthelloState(board.clone(), opponent(state.getPlayerToMove())); } OthelloBoard nextBoard = board.createAfterState(action.getRow(), action.getCol(), state.getPlayerToMove()); return new OthelloState(nextBoard, opponent(state.getPlayerToMove())); } }
OthelloRules implements GameRules<OthelloState, OthelloMove> { @Override public OthelloState makeMove(OthelloState state, OthelloMove action) { OthelloBoard board = state.getBoard(); if (action == null) { return new OthelloState(board.clone(), opponent(state.getPlayerToMove())); } OthelloBoard nextBoard = board.createAfterState(action.getRow(), action.getCol(), state.getPlayerToMove()); return new OthelloState(nextBoard, opponent(state.getPlayerToMove())); }  }
OthelloRules implements GameRules<OthelloState, OthelloMove> { @Override public OthelloState makeMove(OthelloState state, OthelloMove action) { OthelloBoard board = state.getBoard(); if (action == null) { return new OthelloState(board.clone(), opponent(state.getPlayerToMove())); } OthelloBoard nextBoard = board.createAfterState(action.getRow(), action.getCol(), state.getPlayerToMove()); return new OthelloState(nextBoard, opponent(state.getPlayerToMove())); }  @Override OthelloState createInitialState(); @Override boolean isTerminal(OthelloState state); @Override List<OthelloMove> findMoves(OthelloState state); @Override int getOutcome(OthelloState state); @Override OthelloState makeMove(OthelloState state, OthelloMove action); boolean canPlace(OthelloBoard board, int row, int col, int player); @Override boolean isMaxPlayer(int currentPlayer); @Override double getReward(OthelloState state); }
OthelloRules implements GameRules<OthelloState, OthelloMove> { @Override public OthelloState makeMove(OthelloState state, OthelloMove action) { OthelloBoard board = state.getBoard(); if (action == null) { return new OthelloState(board.clone(), opponent(state.getPlayerToMove())); } OthelloBoard nextBoard = board.createAfterState(action.getRow(), action.getCol(), state.getPlayerToMove()); return new OthelloState(nextBoard, opponent(state.getPlayerToMove())); }  @Override OthelloState createInitialState(); @Override boolean isTerminal(OthelloState state); @Override List<OthelloMove> findMoves(OthelloState state); @Override int getOutcome(OthelloState state); @Override OthelloState makeMove(OthelloState state, OthelloMove action); boolean canPlace(OthelloBoard board, int row, int col, int player); @Override boolean isMaxPlayer(int currentPlayer); @Override double getReward(OthelloState state);  }