@Test public void testMoves() { Connect4Board board = createTestBoard(); Connect4Board testBoard = new Connect4Board(); testBoard.makeMove(2, BLACK); testBoard.makeMove(3, WHITE); testBoard.makeMove(6, BLACK); testBoard.makeMove(4, WHITE); testBoard.makeMove(3, BLACK); testBoard.makeMove(5, WHITE); testBoard.makeMove(4, BLACK); testBoard.makeMove(5, WHITE); testBoard.makeMove(4, BLACK); testBoard.makeMove(5, WHITE); assertEquals(board, testBoard); }
public Connect4Board makeMove(int col, int player) { Preconditions.checkArgument(player == Board.BLACK || player == Board.WHITE); Preconditions.checkArgument(!gameOver); final int pos = moveToPos(col); if (!isEmpty(pos)) { throw new IllegalStateException("Attempt to override board state with move: " + pos); } buffer[pos] = player; colHeights[col]++; if (Connect4.isConnect4(pos, player, this)) { gameOver = true; winner = player; } return this; }
Connect4Board implements Board { public Connect4Board makeMove(int col, int player) { Preconditions.checkArgument(player == Board.BLACK || player == Board.WHITE); Preconditions.checkArgument(!gameOver); final int pos = moveToPos(col); if (!isEmpty(pos)) { throw new IllegalStateException("Attempt to override board state with move: " + pos); } buffer[pos] = player; colHeights[col]++; if (Connect4.isConnect4(pos, player, this)) { gameOver = true; winner = player; } return this; } }
Connect4Board implements Board { public Connect4Board makeMove(int col, int player) { Preconditions.checkArgument(player == Board.BLACK || player == Board.WHITE); Preconditions.checkArgument(!gameOver); final int pos = moveToPos(col); if (!isEmpty(pos)) { throw new IllegalStateException("Attempt to override board state with move: " + pos); } buffer[pos] = player; colHeights[col]++; if (Connect4.isConnect4(pos, player, this)) { gameOver = true; winner = player; } return this; } Connect4Board();  Connect4Board(int[][] board);  Connect4Board(double[] board, int rows, int cols); private  Connect4Board(int[] buffer, int[] colHeights, boolean gameOver, int winner); }
Connect4Board implements Board { public Connect4Board makeMove(int col, int player) { Preconditions.checkArgument(player == Board.BLACK || player == Board.WHITE); Preconditions.checkArgument(!gameOver); final int pos = moveToPos(col); if (!isEmpty(pos)) { throw new IllegalStateException("Attempt to override board state with move: " + pos); } buffer[pos] = player; colHeights[col]++; if (Connect4.isConnect4(pos, player, this)) { gameOver = true; winner = player; } return this; } Connect4Board();  Connect4Board(int[][] board);  Connect4Board(double[] board, int rows, int cols); private  Connect4Board(int[] buffer, int[] colHeights, boolean gameOver, int winner); @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); int getValueInv(int row, int col); @Override int getValue(int pos); @Override void invert(); @Override Connect4Board createAfterState(int row, int col, int player); Connect4Board makeMove(int col, int player); int moveToPos(int col); boolean isEmpty(int row, int col); IntArrayList getValidMoves(); boolean isValidMove(int col); int[] getOccupiedCells(int playerColor); boolean isGameOver(); int getWinner(); @Override boolean equals(Object obj); @Override int hashCode(); @Override Connect4Board clone(); @Override String toString(); static double playerValue(int player); int[][] toThillBoard(); static Connect4Board fromThillBoard(int[][] thillBoard); }
Connect4Board implements Board { public Connect4Board makeMove(int col, int player) { Preconditions.checkArgument(player == Board.BLACK || player == Board.WHITE); Preconditions.checkArgument(!gameOver); final int pos = moveToPos(col); if (!isEmpty(pos)) { throw new IllegalStateException("Attempt to override board state with move: " + pos); } buffer[pos] = player; colHeights[col]++; if (Connect4.isConnect4(pos, player, this)) { gameOver = true; winner = player; } return this; } Connect4Board();  Connect4Board(int[][] board);  Connect4Board(double[] board, int rows, int cols); private  Connect4Board(int[] buffer, int[] colHeights, boolean gameOver, int winner); @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); int getValueInv(int row, int col); @Override int getValue(int pos); @Override void invert(); @Override Connect4Board createAfterState(int row, int col, int player); Connect4Board makeMove(int col, int player); int moveToPos(int col); boolean isEmpty(int row, int col); IntArrayList getValidMoves(); boolean isValidMove(int col); int[] getOccupiedCells(int playerColor); boolean isGameOver(); int getWinner(); @Override boolean equals(Object obj); @Override int hashCode(); @Override Connect4Board clone(); @Override String toString(); static double playerValue(int player); int[][] toThillBoard(); static Connect4Board fromThillBoard(int[][] thillBoard); static final int BOARD_HEIGHT; static final int BOARD_WIDTH; static final RectSize SIZE; static final RectSize BOARD_SIZE; static final int NUM_VALUES; static final int BUFFER_SIZE; }