Skip to content
Browse files

Add new classes

  • Loading branch information...
1 parent c327d43 commit 76dac42e6f5a087a0f9b5256993c8bdd131b0e0c Kestutis-Z committed Nov 6, 2012
Showing with 417 additions and 27 deletions.
  1. +28 −0 endgame-oracle/src/main/java/tablebases/EndgameTablebasesProbingCodeAPI.java
  2. +97 −0 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesLibrary.java
  3. +34 −0 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesProbingCodeAPI.java
  4. +33 −0 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesQueryForResultAndDTM.java
  5. +33 −0 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesQueryForResultOnly.java
  6. +124 −0 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesQueryTemplate.java
  7. +7 −7 endgame-oracle/src/test/java/chess/ChessPositionTest.java
  8. +20 −20 endgame-oracle/src/test/java/chess/SquareTest.java
  9. +41 −0 endgame-oracle/src/test/java/tablebases/GaviotaTablebasesQueryTemplateTest.java
  10. BIN endgame-oracle/target/classes/chess/ChessPositionEvaluation$ChessPositionEvaluationWithDTM.class
  11. BIN endgame-oracle/target/classes/chess/ChessPositionEvaluation.class
  12. BIN endgame-oracle/target/classes/tablebases/EndgameTablebasesProbingCodeAPI.class
  13. BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesLibrary.class
  14. BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesProbingCodeAPI.class
  15. BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryForResultAndDTM.class
  16. BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryForResultOnly.class
  17. BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate$TB_castling.class
  18. BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate$TB_pieces.class
  19. BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate$TB_sides.class
  20. BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate$TB_squares.class
  21. BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate.class
  22. BIN endgame-oracle/target/test-classes/chess/ChessPositionTest.class
  23. BIN endgame-oracle/target/test-classes/chess/SquareTest.class
  24. BIN endgame-oracle/target/test-classes/tablebases/GaviotaTablebasesQueryTemplateTest.class
View
28 endgame-oracle/src/main/java/tablebases/EndgameTablebasesProbingCodeAPI.java
@@ -0,0 +1,28 @@
+package tablebases;
+
+import chess.ChessPosition;
+import chess.ChessPositionEvaluation;
+import chess.ChessPositionEvaluation.ChessPositionEvaluationWithDTM;
+
+/**
+ * Software, typically written in C/C++, to generate,
+ * compress, access and probe endgame tablebases.
+ *
+ * @author Kestutis
+ *
+ */
+public interface EndgameTablebasesProbingCodeAPI {
+
+ /** Probes tablebase for the specified chess position.
+ * @return basic evaluation (one of "White wins" /
+ * "Black wins" / "Draw" / "Illegal position") only. */
+ public abstract ChessPositionEvaluation
+ queryTablebaseForResultOnly(ChessPosition chessPosition);
+
+ /** Probes tablebase for the specified chess position.
+ * @return evaluation and distance to mate (a non-negative
+ * number in case the evaluation is "White wins" / "Black wins"). */
+ public abstract ChessPositionEvaluationWithDTM
+ queryTablebaseForResultAndDTM(ChessPosition chessPosition);
+
+}
View
97 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesLibrary.java
@@ -0,0 +1,97 @@
+package tablebases;
+
+import chess.ChessPositionEvaluation;
+import chess.ChessPositionEvaluation.ChessPositionEvaluationWithDTM;
+
+/**
+ * Container for native methods to initialize and probe the Gaviota tablebases.
+ *
+ * @author Kestutis
+ *
+ */
+public class GaviotaTablebasesLibrary {
+
+ static {
+ try {
+ System.loadLibrary("GaviotaTablebasesLibrary");
+ } catch (Exception e) {
+ System.out.println("GaviotaTablebasesLibrary could not be loaded.");
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Prepares the Gaviota tablebases API for probing.
+ *
+ * @param path
+ * full path to the directory where tablebases are located. If
+ * there are multiple paths, separate them with semicolons, for
+ * example, "C:/tablebases/path1;C:/tablebases/path2".
+ */
+ public static native void initializeGaviotaTablebases(String path);
+
+ /**
+ * Queries the Gaviota tablebases for the game-theoretical result
+ * ("White wins" / "Black wins" / "Draw") only.
+ *
+ * @param sideToMove
+ * - integer corresponding to one of the TB_return_values in the
+ * the Gaviota Tablebases API
+ * @param enpassantSquare
+ * - integer corresponding to one of the TB_squares in the the
+ * Gaviota Tablebases API
+ * @param castlingOption
+ * - integer corresponding to one of the TB_castling options in
+ * the the Gaviota Tablebases API
+ * @param whiteSquares
+ * - integer array corresponding to the array of TB_squares in
+ * the the Gaviota Tablebases API
+ * @param blackSquares
+ * - integer array corresponding to the array of TB_squares in
+ * the the Gaviota Tablebases API
+ * @param whitePieces
+ * - byte array corresponding to the array of TB_pieces in the
+ * the Gaviota Tablebases API
+ * @param blackPieces
+ * - byte array corresponding to the array of TB_pieces in the
+ * the Gaviota Tablebases API
+ * @return game-theoretical result
+ */
+ public static native ChessPositionEvaluation queryGaviotaTablebasesForResultOnly(
+ int sideToMove, int enpassantSquare, int castlingOption,
+ int[] whiteSquares, int[] blackSquares, byte[] whitePieces,
+ byte[] blackPieces);
+
+ /**
+ * Queries the Gaviota tablebases for the game-theoretical result
+ * ("White wins" / "Black wins" / "Draw") and distance-to-mate information.
+ *
+ * @param sideToMove
+ * - integer corresponding to one of the TB_return_values in the
+ * the Gaviota Tablebases API
+ * @param enpassantSquare
+ * - integer corresponding to one of the TB_squares in the the
+ * Gaviota Tablebases API
+ * @param castlingOption
+ * - integer corresponding to one of the TB_castling options in
+ * the the Gaviota Tablebases API
+ * @param whiteSquares
+ * - integer array corresponding to the array of TB_squares in
+ * the the Gaviota Tablebases API
+ * @param blackSquares
+ * - integer array corresponding to the array of TB_squares in
+ * the the Gaviota Tablebases API
+ * @param whitePieces
+ * - byte array corresponding to the array of TB_pieces in the
+ * the Gaviota Tablebases API
+ * @param blackPieces
+ * - byte array corresponding to the array of TB_pieces in the
+ * the Gaviota Tablebases API
+ * @return game-theoretical result and distance-to-mate in moves.
+ */
+ public static native ChessPositionEvaluationWithDTM queryGaviotaTablebasesForResultAndDistanceToMate(
+ int sideToMove, int enpassantSquare, int castlingOption,
+ int[] whiteSquares, int[] blackSquares, byte[] whitePieces,
+ byte[] blackPieces);
+
+}
View
34 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesProbingCodeAPI.java
@@ -0,0 +1,34 @@
+package tablebases;
+
+import chess.ChessPosition;
+import chess.ChessPositionEvaluation;
+import chess.ChessPositionEvaluation.ChessPositionEvaluationWithDTM;
+
+/**
+ * Software to generate, compress, access and probe Gaviota Tablebases. <br/>
+ * See <a href="https://github.com/michiguel/Gaviota-Tablebases">
+ * https://github.com/michiguel/Gaviota-Tablebases</a>
+ *
+ * @author Kestutis
+ *
+ */
+public class GaviotaTablebasesProbingCodeAPI implements EndgameTablebasesProbingCodeAPI {
+
+ @Override
+ public ChessPositionEvaluation queryTablebaseForResultOnly(
+ ChessPosition chessPosition) {
+ GaviotaTablebasesQueryTemplate<ChessPositionEvaluation> query =
+ new GaviotaTablebasesQueryForResultOnly(chessPosition);
+ return query.tablebaseEvaluation;
+
+ }
+
+ @Override
+ public ChessPositionEvaluationWithDTM queryTablebaseForResultAndDTM(
+ ChessPosition chessPosition) {
+ GaviotaTablebasesQueryTemplate<ChessPositionEvaluationWithDTM> query =
+ new GaviotaTablebasesQueryForResultAndDTM(chessPosition);
+ return query.tablebaseEvaluation;
+ }
+
+}
View
33 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesQueryForResultAndDTM.java
@@ -0,0 +1,33 @@
+package tablebases;
+
+import chess.ChessPosition;
+import chess.ChessPositionEvaluation.ChessPositionEvaluationWithDTM;
+
+/**
+ * Algorithm to query (probe) Gaviota Tablebases,
+ * with the game-theoretical chess position evaluation
+ * <b>and</b> distance-to-mate information expected as query result.
+ *
+ * @author Kestutis
+ *
+ */
+public class GaviotaTablebasesQueryForResultAndDTM extends
+ GaviotaTablebasesQueryTemplate<ChessPositionEvaluationWithDTM> {
+
+ GaviotaTablebasesQueryForResultAndDTM(ChessPosition chessPosition) {
+ super(chessPosition);
+ }
+
+ @Override
+ public ChessPositionEvaluationWithDTM queryGaviotaTablebases() {
+ return GaviotaTablebasesLibrary.queryGaviotaTablebasesForResultAndDistanceToMate(
+ sideToMoveForGaviotaTablebases,
+ enpassantSquareForGaviotaTablebases,
+ castlingOptionForGaviotaTablebases,
+ whiteSquaresForGaviotaTablebases,
+ blackSquaresForGaviotaTablebases,
+ whitePiecesForGaviotaTablebases,
+ blackPiecesForGaviotaTablebases);
+ }
+
+}
View
33 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesQueryForResultOnly.java
@@ -0,0 +1,33 @@
+package tablebases;
+
+import chess.ChessPosition;
+import chess.ChessPositionEvaluation;
+
+/**
+ * Algorithm to query (probe) Gaviota Tablebases,
+ * with only the game-theoretical chess position evaluation
+ * expected as query result.
+ *
+ * @author Kestutis
+ *
+ */
+public class GaviotaTablebasesQueryForResultOnly extends
+ GaviotaTablebasesQueryTemplate<ChessPositionEvaluation> {
+
+ GaviotaTablebasesQueryForResultOnly(ChessPosition chessPosition) {
+ super(chessPosition);
+ }
+
+ @Override
+ public ChessPositionEvaluation queryGaviotaTablebases() {
+ return GaviotaTablebasesLibrary.queryGaviotaTablebasesForResultOnly(
+ sideToMoveForGaviotaTablebases,
+ enpassantSquareForGaviotaTablebases,
+ castlingOptionForGaviotaTablebases,
+ whiteSquaresForGaviotaTablebases,
+ blackSquaresForGaviotaTablebases,
+ whitePiecesForGaviotaTablebases,
+ blackPiecesForGaviotaTablebases);
+ }
+
+}
View
124 endgame-oracle/src/main/java/tablebases/GaviotaTablebasesQueryTemplate.java
@@ -0,0 +1,124 @@
+package tablebases;
+
+import java.util.List;
+
+import chess.ChessPosition;
+import chess.Piece;
+import chess.SideToMove;
+import chess.Square;
+
+/**
+ * Algorithm to query (probe) Gaviota Tablebases.
+ *
+ * @author Kestutis
+ *
+ * @param <T> the nature of query (what information it should return)
+ */
+public abstract class GaviotaTablebasesQueryTemplate<T> {
+ protected int sideToMoveForGaviotaTablebases;
+ protected int enpassantSquareForGaviotaTablebases;
+ protected int castlingOptionForGaviotaTablebases;
+ protected int[] whiteSquaresForGaviotaTablebases;
+ protected int[] blackSquaresForGaviotaTablebases;
+ protected byte[] whitePiecesForGaviotaTablebases;
+ protected byte[] blackPiecesForGaviotaTablebases;
+ protected T tablebaseEvaluation;
+
+ /* ====================================================================== */
+ /* Enums corresponding to the gtb_probe.h in Gaviota Tablebases API */
+ /* ====================================================================== */
+
+ /** Maximum number of pieces that one side (White/Black) can have (includes
+ * the NOPIECE option). Required for the Gaviota Tablebases queries. */
+ private static final int MAX_PIECES = 17;
+ private static final String GTB_ENUM_PREFIX = "tb_";
+
+ private enum TB_pieces {
+ tb_NOPIECE, tb_PAWN, tb_KNIGHT, tb_BISHOP, tb_ROOK, tb_QUEEN, tb_KING
+ }
+
+ enum TB_sides {
+ tb_WHITE_TO_MOVE, tb_BLACK_TO_MOVE
+ }
+
+ enum TB_squares {
+ tb_A1, tb_B1, tb_C1, tb_D1, tb_E1, tb_F1, tb_G1, tb_H1,
+ tb_A2, tb_B2, tb_C2, tb_D2, tb_E2, tb_F2, tb_G2, tb_H2,
+ tb_A3, tb_B3, tb_C3, tb_D3, tb_E3, tb_F3, tb_G3, tb_H3,
+ tb_A4, tb_B4, tb_C4, tb_D4, tb_E4, tb_F4, tb_G4, tb_H4,
+ tb_A5, tb_B5, tb_C5, tb_D5, tb_E5, tb_F5, tb_G5, tb_H5,
+ tb_A6, tb_B6, tb_C6, tb_D6, tb_E6, tb_F6, tb_G6, tb_H6,
+ tb_A7, tb_B7, tb_C7, tb_D7, tb_E7, tb_F7, tb_G7, tb_H7,
+ tb_A8, tb_B8, tb_C8, tb_D8, tb_E8, tb_F8, tb_G8, tb_H8,
+ tb_NOSQUARE
+ }
+
+ enum TB_castling {
+ tb_NOCASTLE(0), tb_WOO(8), tb_WOOO(4), tb_BOO(2), tb_BOOO(1);
+
+ private int value;
+
+ private TB_castling(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ }
+
+ /* ====================================================================== */
+
+
+ GaviotaTablebasesQueryTemplate(ChessPosition chessPosition) {
+ sideToMoveForGaviotaTablebases = chessPosition.getSideToMove() == SideToMove.WHITE ? TB_sides.tb_WHITE_TO_MOVE
+ .ordinal() : TB_sides.tb_BLACK_TO_MOVE.ordinal();
+ enpassantSquareForGaviotaTablebases = TB_squares.tb_NOSQUARE.ordinal(); // TODO Expand
+ castlingOptionForGaviotaTablebases = TB_castling.tb_NOCASTLE.value;
+
+ List<Square> whiteSquares = chessPosition.getWhiteSquares();
+ List<Square> blackSquares = chessPosition.getBlackSquares();
+ List<Piece> whitePieces = chessPosition.getWhitePieces();
+ List<Piece> blackPieces = chessPosition.getBlackPieces();
+
+ whiteSquaresForGaviotaTablebases = new int[MAX_PIECES];
+ blackSquaresForGaviotaTablebases = new int[MAX_PIECES];
+ whitePiecesForGaviotaTablebases = new byte[MAX_PIECES];
+ blackPiecesForGaviotaTablebases = new byte[MAX_PIECES];
+
+ whiteSquaresForGaviotaTablebases = convertSquaresToGaviotaTablebasesInts(whiteSquares);
+ blackSquaresForGaviotaTablebases = convertSquaresToGaviotaTablebasesInts(blackSquares);
+ whitePiecesForGaviotaTablebases = convertPiecesToGaviotaTablebasesInts(whitePieces);
+ blackPiecesForGaviotaTablebases = convertPiecesToGaviotaTablebasesInts(blackPieces);
+
+ tablebaseEvaluation = queryGaviotaTablebases();
+ }
+
+ protected static int[] convertSquaresToGaviotaTablebasesInts(List<Square> squares) {
+ int[] squaresForGTB = new int[MAX_PIECES];
+ int len = squares.size();
+ for (int i = 0; i < len; i++) {
+ Square sq = squares.get(i);
+ String sqForGTB = GTB_ENUM_PREFIX + sq.name();
+ squaresForGTB[i] = TB_squares.valueOf(sqForGTB).ordinal();
+ }
+ squaresForGTB[len] = TB_squares.tb_NOSQUARE.ordinal();
+ return squaresForGTB;
+ }
+
+ protected static byte[] convertPiecesToGaviotaTablebasesInts(List<Piece> pieces) {
+ byte[] piecesForGTB = new byte[MAX_PIECES];
+ int len = pieces.size();
+ for (int i = 0; i < len; i++) {
+ Piece pc = pieces.get(i);
+ String pcForGTB = GTB_ENUM_PREFIX + pc.getPieceType().name();
+ piecesForGTB[i] = (byte) TB_pieces.valueOf(pcForGTB).ordinal();
+ }
+ piecesForGTB[len] = (byte) TB_pieces.tb_NOPIECE.ordinal();
+ return piecesForGTB;
+ }
+
+ public abstract T queryGaviotaTablebases();
+
+}
View
14 endgame-oracle/src/test/java/chess/ChessPositionTest.java
@@ -48,13 +48,13 @@ public void setUp() throws Exception {
}
@Test
- public void getPiecesAndSquaresMapTest1() {
+ public void testGetPiecesAndSquaresMap() {
mockedChessPosition.getPiecesWithSquares();
verify(mockedChessPosition).getPiecesWithSquares();
}
@Test(expected = IllegalArgumentException.class)
- public void getSquaresToPiecesMapThrowsIllegalArgumentExceptionTest1() {
+ public void testGetSquaresToPiecesMapThrowsIllegalArgumentException() {
List<Square> squares2 = new ArrayList<>();
squares2.add(Square.E5);
squares2.add(Square.E5);
@@ -70,7 +70,7 @@ public void getSquaresToPiecesMapThrowsIllegalArgumentExceptionTest1() {
}
@Test(expected = IllegalArgumentException.class)
- public void getPiecesToSquaresThrowsIllegalArgumentExceptionTest2() {
+ public void testGetPiecesToSquaresThrowsIllegalArgumentException() {
List<Square> squares3 = new ArrayList<>();
squares3.add(Square.E3);
squares3.add(Square.D5);
@@ -86,7 +86,7 @@ public void getPiecesToSquaresThrowsIllegalArgumentExceptionTest2() {
}
@Test
- public void getWhitePiecesTest() {
+ public void testGetWhitePieces() {
List<Piece> expectedWhitePiecesKRPKR = new ArrayList<>();
expectedWhitePiecesKRPKR.add(Piece.WHITE_KING);
expectedWhitePiecesKRPKR.add(Piece.WHITE_ROOK);
@@ -107,7 +107,7 @@ public void getWhitePiecesTest() {
}
@Test
- public void getBlackPiecesTest() {
+ public void testGetBlackPieces() {
List<Piece> expectedBlackPiecesKRPKR = new ArrayList<>();
expectedBlackPiecesKRPKR.add(Piece.BLACK_KING);
expectedBlackPiecesKRPKR.add(Piece.BLACK_ROOK);
@@ -128,7 +128,7 @@ public void getBlackPiecesTest() {
}
@Test
- public void getWhiteSquaresTest() {
+ public void testGetWhiteSquares() {
List<Square> expectedWhiteSquaresKRPKR = new ArrayList<>();
expectedWhiteSquaresKRPKR.add(Square.E5);
expectedWhiteSquaresKRPKR.add(Square.E3);
@@ -149,7 +149,7 @@ public void getWhiteSquaresTest() {
}
@Test
- public void getBlackSquaresTest() {
+ public void testGetBlackSquares() {
List<Square> expectedBlackSquaresKRPKR = new ArrayList<>();
expectedBlackSquaresKRPKR.add(Square.H8);
expectedBlackSquaresKRPKR.add(Square.D1);
View
40 endgame-oracle/src/test/java/chess/SquareTest.java
@@ -43,7 +43,7 @@ public void setUp() throws Exception {
}
@Test
- public void getSquareIDTest() {
+ public void testGetSquareID() {
int[] expectedIDs = new int[] { 11, 53, 88 };
int[] actualIDs = new int[testedSquaresCount];
for (int i = 0; i < testedSquaresCount; i++) {
@@ -54,7 +54,7 @@ public void getSquareIDTest() {
}
@Test
- public void getSquareFileTest() {
+ public void testGetSquareFile() {
int[] expectedFiles = new int[] { 1, 5, 8 };
int[] actualFiles = new int[testedSquaresCount];
for (int i = 0; i < testedSquaresCount; i++) {
@@ -65,7 +65,7 @@ public void getSquareFileTest() {
}
@Test
- public void getSquareRankTest() {
+ public void testGetSquareRank() {
int[] expectedRanks = new int[] { 1, 3, 8 };
int[] actualRanks = new int[testedSquaresCount];
for (int i = 0; i < testedSquaresCount; i++) {
@@ -76,7 +76,7 @@ public void getSquareRankTest() {
}
@Test
- public void getSquareFromFileAndRankTest() {
+ public void testGetSquareFromFileAndRank() {
Square[] expectedSquares = testedSquares;
Square[] actualSquares = new Square[] {
Square.getSquareFromFileAndRank(1, 1),
@@ -88,12 +88,12 @@ public void getSquareFromFileAndRankTest() {
}
@Test(expected = IllegalArgumentException.class)
- public void getSquareFromFileAndRankThrowsIllegalArgumentExceptionTest() {
+ public void testGetSquareFromFileAndRankThrowsIllegalArgumentException() {
Square.getSquareFromFileAndRank(0, 1);
}
@Test
- public void getSquareFromID() {
+ public void testGetSquareFromID() {
Square[] expectedSquares = testedSquares;
Square[] actualSquares = new Square[] {
Square.getSquareFromID(11),
@@ -105,12 +105,12 @@ public void getSquareFromID() {
}
@Test(expected = IllegalArgumentException.class)
- public void getSquareFromIDThrowsIllegalArgumentExceptionTest() {
+ public void testGetSquareFromIDThrowsIllegalArgumentException() {
Square.getSquareFromID(0);
}
@Test
- public void hasAdjacentSquareToTest() {
+ public void testThisSquareHasAdjacentSquare() {
for (Direction dir : allDirectionsClockwiseFromEastToNorthEast) {
assertTrue(squareE3.hasAdjacentSquareTo(dir));
}
@@ -135,7 +135,7 @@ public void hasAdjacentSquareToTest() {
}
@Test
- public void getAdjacentSquareTest() {
+ public void testGetAdjacentSquare() {
Square[] expectedSquaresToTheEast = new Square[] { Square.B1, Square.F3 };
Square[] actualSquaresToTheEast = new Square[] {
squareA1.getAdjacentSquare(Direction.EAST),
@@ -144,14 +144,14 @@ public void getAdjacentSquareTest() {
}
@Test
- public void containsPieceTest() {
+ public void testSquareContainsPiece() {
assertFalse(squareA1.containsPiece(chessPosition1));
assertFalse(squareE3.containsPiece(chessPosition1));
assertTrue(squareH8.containsPiece(chessPosition1));
}
@Test
- public void rangeOfSquaresEndsWithPieceTest() {
+ public void testRangeOfSquaresEndsWithPiece() {
List<Square> expectedRange = new ArrayList<>();
expectedRange.add(Square.B1);
expectedRange.add(Square.C1);
@@ -163,7 +163,7 @@ public void rangeOfSquaresEndsWithPieceTest() {
}
@Test
- public void rangeOfSquaresEndsChessboardEdgeTest() {
+ public void testRangeOfSquaresEndsChessboardEdge() {
List<Square> expectedRange = new ArrayList<>();
expectedRange.add(Square.F2);
expectedRange.add(Square.G1);
@@ -175,7 +175,7 @@ public void rangeOfSquaresEndsChessboardEdgeTest() {
}
@Test
- public void rangeOfSquaresIsEmptyTest() {
+ public void testRangeOfSquaresIsEmpty() {
List<Square> expectedRange = new ArrayList<>();
List<Square> actualRange = squareH8.rangeOfSquares(chessPosition1, Direction.NORTHWEST);
@@ -188,7 +188,7 @@ public void rangeOfSquaresIsEmptyTest() {
}
@Test
- public void getSquareAtTheEndOfRangeTest() {
+ public void testGetSquareAtTheEndOfRange() {
Square[] expectedSquares = { Square.E5, Square.H8, Square.B8, Square.A8 };
Square sq1 = null, sq2 = null, sq3 = null, sq4 = null;
@@ -206,7 +206,7 @@ public void getSquareAtTheEndOfRangeTest() {
}
@Test(expected = SquareHasNoAdjacentSquareException.class)
- public void getSquareAtTheEndOfRangeThrowsSquareHasNoAdjacentSquareExceptionTest()
+ public void testGetSquareAtTheEndOfRangeThrowsSquareHasNoAdjacentSquareException()
throws SquareHasNoAdjacentSquareException {
Square sq = null;
try {
@@ -220,7 +220,7 @@ public void getSquareAtTheEndOfRangeThrowsSquareHasNoAdjacentSquareExceptionTest
}
@Test
- public void getPieceTest() {
+ public void testGetPiece() {
Piece[] expectedPieces = { Piece.WHITE_KING, Piece.BLACK_KING, Piece.BLACK_ROOK };
Piece pc1 = null, pc2 = null, pc3 = null;
@@ -237,7 +237,7 @@ public void getPieceTest() {
}
@Test(expected = SquareContainsNoPiecesException.class)
- public void getPieceThrowsSquareContainsNoPiecesExceptionTest()
+ public void testGetPieceThrowsSquareContainsNoPiecesException()
throws SquareContainsNoPiecesException {
Piece pc = null;
try {
@@ -251,7 +251,7 @@ public void getPieceThrowsSquareContainsNoPiecesExceptionTest()
}
@Test
- public void getPieceAtTheEndOfRangeTest()
+ public void testGetPieceAtTheEndOfRange()
throws SquareHasNoAdjacentSquareException, SquareContainsNoPiecesException {
Piece[] expectedPieces = { Piece.WHITE_KING, Piece.WHITE_KING, Piece.BLACK_ROOK };
@@ -264,13 +264,13 @@ public void getPieceAtTheEndOfRangeTest()
}
@Test
- public void isAdjacentTest() {
+ public void testSquareIsAdjacentToOtherSquare() {
assertTrue(squareA1.isAdjacent(Square.A2));
assertFalse(squareA1.isAdjacent(squareE3));
}
@Test
- public void getRectangleZoneTest() {
+ public void testGetRectangleZone() {
Set<Square> expectedSquares = new HashSet<Square>();
expectedSquares.add(Square.A1);
expectedSquares.add(Square.A2);
View
41 endgame-oracle/src/test/java/tablebases/GaviotaTablebasesQueryTemplateTest.java
@@ -0,0 +1,41 @@
+package tablebases;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import chess.ChessPosition;
+import chess.SideToMove;
+import chess.Square;
+
+public class GaviotaTablebasesQueryTemplateTest {
+
+ private List<Square> squares = new ArrayList<>();
+
+ @Before
+ public void setUp() throws Exception {
+ squares.add(Square.A1);
+ squares.add(Square.G1);
+ squares.add(Square.A7);
+ squares.add(Square.D3);
+ squares.add(Square.F8);
+ ChessPosition.createFromTablebase(Tablebase.KRPKR, squares, SideToMove.BLACK);
+
+ }
+
+ @Test
+ public void testConvertionFromSquaresAndPiecesToGaviotaTablebasesInts() {
+ int[] expectedGTBInts_Sq = new int[] { 0, 6, 48, 19, 61, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ int[] actualGTBInts_Sq = GaviotaTablebasesQueryTemplate.convertSquaresToGaviotaTablebasesInts(squares);
+ assertArrayEquals(expectedGTBInts_Sq, actualGTBInts_Sq);
+
+ byte[] expectedGTBInts_Pc = new byte[] { 6, 4, 1, 6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] actualGTBInts_Pc = GaviotaTablebasesQueryTemplate.convertPiecesToGaviotaTablebasesInts(Tablebase.KRPKR.getAllPieces());
+ assertArrayEquals(expectedGTBInts_Pc, actualGTBInts_Pc);
+ }
+
+}
View
BIN ...-oracle/target/classes/chess/ChessPositionEvaluation$ChessPositionEvaluationWithDTM.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/chess/ChessPositionEvaluation.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/EndgameTablebasesProbingCodeAPI.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesLibrary.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesProbingCodeAPI.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryForResultAndDTM.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryForResultOnly.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate$TB_castling.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate$TB_pieces.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate$TB_sides.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate$TB_squares.class
Binary file not shown.
View
BIN endgame-oracle/target/classes/tablebases/GaviotaTablebasesQueryTemplate.class
Binary file not shown.
View
BIN endgame-oracle/target/test-classes/chess/ChessPositionTest.class
Binary file not shown.
View
BIN endgame-oracle/target/test-classes/chess/SquareTest.class
Binary file not shown.
View
BIN endgame-oracle/target/test-classes/tablebases/GaviotaTablebasesQueryTemplateTest.class
Binary file not shown.

0 comments on commit 76dac42

Please sign in to comment.
Something went wrong with that request. Please try again.