BitBoard { static public final int getDirection(int from, int to) { int offs = to + (to|7) - from - (from|7) + 0x77; return dirTable[offs]; }  static long bishopAttacks(int sq, long occupied); static long rookAttacks(int sq, long occupied); static final int getDirection(int from, int to); static int getDistance(int from, int to); static long southFill(long mask); static long northFill(long mask); static final int numberOfTrailingZeros(long mask); static final long[] kingAttacks; static final long[] knightAttacks; static final long[] wPawnAttacks; static final long maskAToGFiles; static final long maskBToHFiles; static final long maskAToFFiles; static final long maskCToHFiles; static final long[] maskFile; static final long maskRow1; static final long maskRow2; static final long maskRow3; static final long maskRow4; static final long maskRow5; static final long maskRow6; static final long maskRow7; static final long maskRow8; static final long maskRow1Row8; static final long maskDarkSq; static final long maskLightSq; static final long maskCorners; static final long[][] squaresBetween; }
@Test public void testSquaresBetween() { System.out.println("squaresBetween"); for (int sq1 = 0; sq1 < 64; sq1++) { for (int sq2 = 0; sq2 < 64; sq2++) { int d = BitBoard.getDirection(sq1, sq2); if (d == 0) { assertEquals(0, BitBoard.squaresBetween[sq1][sq2]); } else { int dx = Position.getX(sq1) - Position.getX(sq2); int dy = Position.getY(sq1) - Position.getY(sq2); if (Math.abs(dx * dy) == 2) { assertEquals(0, BitBoard.squaresBetween[sq1][sq2]); } else { if ((Math.abs(dx) > 1) || (Math.abs(dy) > 1)) { assertTrue(BitBoard.squaresBetween[sq1][sq2] != 0); } else { assertEquals(0, BitBoard.squaresBetween[sq1][sq2]); } } } } } assertEquals(0x0040201008040200L, BitBoard.squaresBetween[0][63]); assertEquals(0x000000001C000000L, BitBoard.squaresBetween[TextIO.getSquare("b4")][TextIO.getSquare("f4")]); }
@Test public void testGetDirection() { System.out.println("getDirection"); for (int from = 0; from < 64; from++) { for (int to = 0; to < 64; to++) { assertEquals(computeDirection(from, to), BitBoard.getDirection(from, to)); } } }