# Kestutis-Z/Endgame-Oracle

1 parent 8d444fe commit c327d437848bdeb5fbf7c13a64877a746a33f529 Kestutis-Z committed Nov 6, 2012
74 endgame-oracle/src/main/java/chess/ChessPosition.java
 @@ -10,8 +10,13 @@ import tablebases.Tablebase; -/** Representation of chess position: side to move, White and Black - * pieces, and their respective squares. */ +/** + * Representation of chess position: side to move, White and Black + * pieces, and their respective squares. + * + * @author Kestutis + * + */ public class ChessPosition { private BiMap piecesWithSquares; private SideToMove sideToMove; @@ -41,6 +46,7 @@ private ChessPosition(Tablebase tablebase, this.sideToMove = sideToMove; } + /** Checks if there are no duplicate squares in the list. */ private static boolean allSquaresAreDifferent(List squareList) { Set squareSet = new HashSet<>(squareList); return squareList.size() == squareSet.size(); @@ -72,38 +78,6 @@ public void setSideToMove(SideToMove sideToMove) { this.sideToMove = sideToMove; } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime - * result - + ((piecesWithSquares == null) ? 0 : piecesWithSquares - .hashCode()); - result = prime * result - + ((sideToMove == null) ? 0 : sideToMove.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ChessPosition other = (ChessPosition) obj; - if (piecesWithSquares == null) { - if (other.piecesWithSquares != null) - return false; - } else if (!piecesWithSquares.equals(other.piecesWithSquares)) - return false; - if (sideToMove != other.sideToMove) - return false; - return true; - } - public List getWhitePieces() { List whitePieces = new ArrayList<>(); for (Piece p : piecesWithSquares.keySet()) { @@ -139,4 +113,36 @@ public boolean equals(Object obj) { return blackSquares; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime + * result + + ((piecesWithSquares == null) ? 0 : piecesWithSquares + .hashCode()); + result = prime * result + + ((sideToMove == null) ? 0 : sideToMove.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ChessPosition other = (ChessPosition) obj; + if (piecesWithSquares == null) { + if (other.piecesWithSquares != null) + return false; + } else if (!piecesWithSquares.equals(other.piecesWithSquares)) + return false; + if (sideToMove != other.sideToMove) + return false; + return true; + } + }
16 endgame-oracle/src/main/java/chess/ChessPositionEvaluation.java
 @@ -1,14 +1,24 @@ package chess; -/** Game-theoretical value of position obtained from tablebase. */ +/** + * Game-theoretical value of position obtained from tablebase. + * + * @author Kestutis + * + */ public enum ChessPositionEvaluation { DRAW, WHITE_WINS, BLACK_WINS, ILLEGAL, NOT_EVALUATED; - /** Simple data structure representing the evaluation of + /** + * Simple data structure representing the evaluation of * some chess position, which include the additional data member - - * distance-to-mate. */ + * distance-to-mate. + * + * @author Kestutis + * + */ public static class ChessPositionEvaluationWithDTM { private ChessPositionEvaluation chessPositionEvaluation; /** A non-negative number of moves to mate in a position, theoretically won
9 endgame-oracle/src/main/java/chess/Square.java
 @@ -6,10 +6,15 @@ import java.util.List; import java.util.Set; -/** Chessboard square that can be empty or occupied by one of the chess +/** + * Chessboard square that can be empty or occupied by one of the chess * pieces. There are 64 squares on the chessboard. Each square can be * uniquely identified by its file (a, b, c, d, e, f, g, or h, corresponding - * to integers from 1 to 8) and rank (1, 2, ..., 8). */ + * to integers from 1 to 8) and rank (1, 2, ..., 8). + + * @author Kestutis + * + */ public enum Square { A8(18), B8(28), C8(38), D8(48), E8(58), F8(68), G8(78), H8(88),
BIN endgame-oracle/target/classes/chess/ChessPosition.class
Binary file not shown.
BIN endgame-oracle/target/classes/chess/Square\$Direction.class
Binary file not shown.
BIN endgame-oracle/target/classes/chess/Square.class
Binary file not shown.