Position { @Override public int hashCode() { return (int)hashKey; } Position();  Position(Position other); @Override boolean equals(Object o); @Override int hashCode(); final long zobristHash(); final long pawnZobristHash(); final long kingZobristHash(); final long historyHash(); final boolean drawRuleEquals(Position other); final void setWhiteMove(boolean whiteMove); static int getSquare(int x, int y); static int getX(int square); static int getY(int square); static boolean darkSquare(int x, int y); final int getPiece(int square); final void setPiece(int square, int piece); final boolean a1Castle(); final boolean h1Castle(); final boolean a8Castle(); final boolean h8Castle(); final int getCastleMask(); final void setCastleMask(int castleMask); final int getEpSquare(); final void setEpSquare(int epSquare); final int getKingSq(boolean white); final void makeMove(Move move, UndoInfo ui); final void unMakeMove(Move move, UndoInfo ui); final void makeSEEMove(Move move, UndoInfo ui); final void unMakeSEEMove(Move move, UndoInfo ui); final String toString(); public int[] squares; public long[] pieceTypeBB; public long whiteBB; public short[] psScore1; public boolean whiteMove; static final int A1_CASTLE; static final int H1_CASTLE; static final int A8_CASTLE; static final int H8_CASTLE; public int fullMoveCounter; public int wKingSq; public int wMtrl; public int bMtrl; public int wMtrlPawns; public int bMtrlPawns; }
@Test public void testHashCode() throws ChessParseError { System.out.println("hashCode"); Position pos = TextIO.readFEN(TextIO.startPosFEN); long h1 = pos.zobristHash(); assertEquals(h1, pos.computeZobristHash()); UndoInfo ui = new UndoInfo(); Move move = TextIO.stringToMove(pos, "e4"); pos.makeMove(move, ui); assertTrue(h1 != pos.zobristHash()); pos.unMakeMove(move, ui); assertTrue(h1 == pos.zobristHash()); pos.setWhiteMove(!pos.whiteMove); long h4 = pos.zobristHash(); assertEquals(h4, pos.computeZobristHash()); assertTrue(h1 != pos.zobristHash()); pos.setWhiteMove(!pos.whiteMove); assertTrue(h1 == pos.zobristHash()); pos.setCastleMask(0); assertTrue(h1 != pos.zobristHash()); pos = TextIO.readFEN("rnbqkbnr/pppp1ppp/8/2P1p3/8/8/PP1PPPPP/RNBQKBNR b KQkq - 0 1"); h1 = pos.zobristHash(); assertEquals(h1, pos.computeZobristHash()); String[] moves = { "b5", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "Nf6", "Nb1", "Ng8", "Nc3", "d5", "cxd6", "Qxd6", "h4", "Be6", "h5", "Nc6", "h6", "o-o-o", "hxg7", "Nf6", "gxh8Q", "Be7" }; List<UndoInfo> uiList = new ArrayList<>(); List<Long> hashList = new ArrayList<>(); List<Move> moveList = new ArrayList<>(); for (int i = 0; i < moves.length; i++) { uiList.add(new UndoInfo()); Move m = TextIO.stringToMove(pos, moves[i]); moveList.add(m); pos.makeMove(m, uiList.get(i)); long h = pos.zobristHash(); assertEquals(h, pos.computeZobristHash()); hashList.add(h); } assertTrue(!hashList.get(0).equals(hashList.get(4))); assertTrue(hashList.get(4).equals(hashList.get(8))); for (int i = moves.length - 1; i >= 0; i--) { pos.unMakeMove(moveList.get(i), uiList.get(i)); long h = pos.zobristHash(); assertEquals(h, pos.computeZobristHash()); assertEquals(h, i > 0 ? (long)hashList.get(i - 1) : h1); } }