@Test public void testSymmetric() throws Exception { Board board = new OthelloBoard(new int[][] { {1,1,1,1,1,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,0,0,0,0,0,0,}, {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, }); List<int[][]> symmetric = BoardUtils.createSymmetricBoards(board, new RotationMirrorSymmetryExpander(OthelloBoard.SIZE)); List<int[][]> expected = Arrays.asList(new int[][] { {1,1,1,1,1,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,0,0,0,0,0,0,}, {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, }, new int[][] { {1,1,1,1,1,1,1,1,}, {1,1,1,2,1,1,1,1,}, {1,1,1,2,1,1,1,1,}, {1,1,1,2,1,1,1,1,}, {1,1,1,2,1,1,1,1,}, {0,0,0,0,0,0,1,1,}, {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, }, new int[][] { {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, {1,1,0,0,0,0,0,0,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,2,1,1,1,}, {1,1,1,1,1,1,1,1,}, }, new int[][] { {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, {0,0,0,0,0,0,1,1,}, {1,1,1,2,1,1,1,1,}, {1,1,1,2,1,1,1,1,}, {1,1,1,2,1,1,1,1,}, {1,1,1,2,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, }, new int[][] { {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,0,1,1,}, {1,1,1,1,1,0,1,1,}, {1,2,2,2,2,0,1,1,}, {1,1,1,1,1,0,1,1,}, {1,1,1,1,1,0,1,1,}, {1,1,1,1,1,0,1,1,}, }, new int[][] { {1,1,1,1,1,0,1,1,}, {1,1,1,1,1,0,1,1,}, {1,1,1,1,1,0,1,1,}, {1,2,2,2,2,0,1,1,}, {1,1,1,1,1,0,1,1,}, {1,1,1,1,1,0,1,1,}, {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, }, new int[][] { {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, {1,1,0,1,1,1,1,1,}, {1,1,0,1,1,1,1,1,}, {1,1,0,2,2,2,2,1,}, {1,1,0,1,1,1,1,1,}, {1,1,0,1,1,1,1,1,}, {1,1,0,1,1,1,1,1,}, }, new int[][] { {1,1,0,1,1,1,1,1,}, {1,1,0,1,1,1,1,1,}, {1,1,0,1,1,1,1,1,}, {1,1,0,2,2,2,2,1,}, {1,1,0,1,1,1,1,1,}, {1,1,0,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, {1,1,1,1,1,1,1,1,}, }); for (int i =0; i<8; ++i) { Assert.assertArrayEquals(ArrayUtils.flatten(expected.get(i)), ArrayUtils.flatten(symmetric.get(i))); } }
public static List<int[][]> createSymmetricBoards(Board board, SymmetryExpander expander) { IntArrayList fakeNTuple = new IntArrayList(); for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) fakeNTuple.add(toMarginPos(board.getWidth(), r, c)); List<int[][]> symmetricBoards = new ArrayList<>(); List<int[]> symmetries = SymmetryUtils.createSymmetric(fakeNTuple.toArray(), expander); for (int[] symmetric : symmetries) { int[][] newBoard = new int[board.getHeight()][board.getWidth()]; for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) newBoard[r][c] = board.getValue(symmetric[board.getWidth() * r + c]); symmetricBoards.add(newBoard); } return symmetricBoards; }
BoardUtils { public static List<int[][]> createSymmetricBoards(Board board, SymmetryExpander expander) { IntArrayList fakeNTuple = new IntArrayList(); for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) fakeNTuple.add(toMarginPos(board.getWidth(), r, c)); List<int[][]> symmetricBoards = new ArrayList<>(); List<int[]> symmetries = SymmetryUtils.createSymmetric(fakeNTuple.toArray(), expander); for (int[] symmetric : symmetries) { int[][] newBoard = new int[board.getHeight()][board.getWidth()]; for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) newBoard[r][c] = board.getValue(symmetric[board.getWidth() * r + c]); symmetricBoards.add(newBoard); } return symmetricBoards; } }
BoardUtils { public static List<int[][]> createSymmetricBoards(Board board, SymmetryExpander expander) { IntArrayList fakeNTuple = new IntArrayList(); for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) fakeNTuple.add(toMarginPos(board.getWidth(), r, c)); List<int[][]> symmetricBoards = new ArrayList<>(); List<int[]> symmetries = SymmetryUtils.createSymmetric(fakeNTuple.toArray(), expander); for (int[] symmetric : symmetries) { int[][] newBoard = new int[board.getHeight()][board.getWidth()]; for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) newBoard[r][c] = board.getValue(symmetric[board.getWidth() * r + c]); symmetricBoards.add(newBoard); } return symmetricBoards; } private  BoardUtils(); }
BoardUtils { public static List<int[][]> createSymmetricBoards(Board board, SymmetryExpander expander) { IntArrayList fakeNTuple = new IntArrayList(); for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) fakeNTuple.add(toMarginPos(board.getWidth(), r, c)); List<int[][]> symmetricBoards = new ArrayList<>(); List<int[]> symmetries = SymmetryUtils.createSymmetric(fakeNTuple.toArray(), expander); for (int[] symmetric : symmetries) { int[][] newBoard = new int[board.getHeight()][board.getWidth()]; for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) newBoard[r][c] = board.getValue(symmetric[board.getWidth() * r + c]); symmetricBoards.add(newBoard); } return symmetricBoards; } private  BoardUtils(); static double[] getValues(Board board); static int countDepth(Board board); static int countPieces(Board board); static int countPieces(Board board, int color); static int countPieces(Board board, Set<Integer> colors); static int toMarginPos(int boardWidth, int row, int col); static int toMarginPos(RectSize boardSize, int row, int col); static int toMarginPos(RectSize boardSize, int zeroBasedPos); static int toMarginPos(RectSize boardSize, BoardPos pos); static int marginPosToPos(int pos, int boardSize); static int marginPosToPos(int pos, int rows, int cols); static boolean isValidPosition(int pos, int boardSize); static boolean isValidPosition(int pos, int rows, int cols); static int rowFromPos(int pos, int boardWidth); static int colFromPos(int pos, int boardWidth); static char pieceToChar(int piece); static String posToString(int pos, Board board); static String toString(Board board); static List<int[][]> createSymmetricBoards(Board board, SymmetryExpander expander); static int[][] boardFromString(String string, int height, int width); static int[][] boardFromString(String string, RectSize size); }
BoardUtils { public static List<int[][]> createSymmetricBoards(Board board, SymmetryExpander expander) { IntArrayList fakeNTuple = new IntArrayList(); for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) fakeNTuple.add(toMarginPos(board.getWidth(), r, c)); List<int[][]> symmetricBoards = new ArrayList<>(); List<int[]> symmetries = SymmetryUtils.createSymmetric(fakeNTuple.toArray(), expander); for (int[] symmetric : symmetries) { int[][] newBoard = new int[board.getHeight()][board.getWidth()]; for (int r = 0; r < board.getHeight(); ++r) for (int c = 0; c < board.getWidth(); ++c) newBoard[r][c] = board.getValue(symmetric[board.getWidth() * r + c]); symmetricBoards.add(newBoard); } return symmetricBoards; } private  BoardUtils(); static double[] getValues(Board board); static int countDepth(Board board); static int countPieces(Board board); static int countPieces(Board board, int color); static int countPieces(Board board, Set<Integer> colors); static int toMarginPos(int boardWidth, int row, int col); static int toMarginPos(RectSize boardSize, int row, int col); static int toMarginPos(RectSize boardSize, int zeroBasedPos); static int toMarginPos(RectSize boardSize, BoardPos pos); static int marginPosToPos(int pos, int boardSize); static int marginPosToPos(int pos, int rows, int cols); static boolean isValidPosition(int pos, int boardSize); static boolean isValidPosition(int pos, int rows, int cols); static int rowFromPos(int pos, int boardWidth); static int colFromPos(int pos, int boardWidth); static char pieceToChar(int piece); static String posToString(int pos, Board board); static String toString(Board board); static List<int[][]> createSymmetricBoards(Board board, SymmetryExpander expander); static int[][] boardFromString(String string, int height, int width); static int[][] boardFromString(String string, RectSize size); static final int MARGIN_WIDTH; static final int TOTAL_MARGIN; }