@Test public final void testIsValidMove() throws Exception { RandomDataGenerator random = new RandomDataGenerator(new MersenneTwister(123)); int[] players = new int[] { Board.BLACK, Board.WHITE }; for (int i = 0; i < 30; ++i) { OthelloBoard board = createRandomBoard(random); for (int j = 0; j < OthelloBoard.SIZE.rows(); ++j) { for (int k = 0; k < OthelloBoard.SIZE.columns(); ++k) { for (int p : players) { int move = BoardUtils.toMarginPos(OthelloBoard.SIZE, j, k); Assert.assertEquals(board.simulateMove(move, p) != null, board.isValidMove(move, p)); } } } } }
public boolean isValidMove(int move, int player) { if (!isEmpty(move)) { return false; } for (int dir : DIRS) { int pos = move + dir; while (buffer[pos] == opponent(player)) { pos += dir; } if (buffer[pos] == player && buffer[pos - dir] == opponent(player)) { return true; } } return false; }
OthelloBoard implements Board, Serializable { public boolean isValidMove(int move, int player) { if (!isEmpty(move)) { return false; } for (int dir : DIRS) { int pos = move + dir; while (buffer[pos] == opponent(player)) { pos += dir; } if (buffer[pos] == player && buffer[pos - dir] == opponent(player)) { return true; } } return false; } }
OthelloBoard implements Board, Serializable { public boolean isValidMove(int move, int player) { if (!isEmpty(move)) { return false; } for (int dir : DIRS) { int pos = move + dir; while (buffer[pos] == opponent(player)) { pos += dir; } if (buffer[pos] == player && buffer[pos - dir] == opponent(player)) { return true; } } return false; } OthelloBoard();  OthelloBoard(int[][] board); private  OthelloBoard(int[] buffer); }
OthelloBoard implements Board, Serializable { public boolean isValidMove(int move, int player) { if (!isEmpty(move)) { return false; } for (int dir : DIRS) { int pos = move + dir; while (buffer[pos] == opponent(player)) { pos += dir; } if (buffer[pos] == player && buffer[pos - dir] == opponent(player)) { return true; } } return false; } OthelloBoard();  OthelloBoard(int[][] board); private  OthelloBoard(int[] buffer); OthelloBoard inverted(); @Override void invert(); @Override int getWidth(); @Override int getHeight(); @Override void setValue(int row, int col, int color); @Override void setValue(int pos, int color); @Override int getValue(int row, int col); @Override int getValue(int pos); boolean isEmpty(int row, int col); boolean isEmpty(int pos); IntArrayList simulateMove(int move, int player); boolean isValidMove(int move, int player); void makeMove(int move, int player); void makeMove(IntArrayList piecesToMove, int player); static int toPos(int row, int col); static int opponent(int player); static String posToString(int pos); @Override String toString(); @Override boolean equals(Object obj); boolean equalsBySymmetry(OthelloBoard board); @Override int hashCode(); String toJavaArrayString(); @Override OthelloBoard clone(); @Override OthelloBoard createAfterState(int row, int col, int player); double[] getFeatures(); static double playerValue(int player); List<OthelloBoard> createSymmetricBoards(); }
OthelloBoard implements Board, Serializable { public boolean isValidMove(int move, int player) { if (!isEmpty(move)) { return false; } for (int dir : DIRS) { int pos = move + dir; while (buffer[pos] == opponent(player)) { pos += dir; } if (buffer[pos] == player && buffer[pos - dir] == opponent(player)) { return true; } } return false; } OthelloBoard();  OthelloBoard(int[][] board); private  OthelloBoard(int[] buffer); OthelloBoard inverted(); @Override void invert(); @Override int getWidth(); @Override int getHeight(); @Override void setValue(int row, int col, int color); @Override void setValue(int pos, int color); @Override int getValue(int row, int col); @Override int getValue(int pos); boolean isEmpty(int row, int col); boolean isEmpty(int pos); IntArrayList simulateMove(int move, int player); boolean isValidMove(int move, int player); void makeMove(int move, int player); void makeMove(IntArrayList piecesToMove, int player); static int toPos(int row, int col); static int opponent(int player); static String posToString(int pos); @Override String toString(); @Override boolean equals(Object obj); boolean equalsBySymmetry(OthelloBoard board); @Override int hashCode(); String toJavaArrayString(); @Override OthelloBoard clone(); @Override OthelloBoard createAfterState(int row, int col, int player); double[] getFeatures(); static double playerValue(int player); List<OthelloBoard> createSymmetricBoards(); static final RectSize SIZE; static final int NUM_VALUES; static final int NUM_FIELDS; static final int MARGIN_WIDTH; static final int DIRS; static final int BUFFER_SIZE; final int[] buffer; }