added GetHashKey function to hash a given board

This commit is contained in:
rektdie committed 2024-06-29 16:56:43 +02:00
1 parent 869af6662b
commit 436f2d7164
2 files changed
+34 -2

No files matched your search

+32 -2
View File
@@ -1,6 +1,4 @@
#include "tt.h"
#include "types.h"
#include <iostream>
static inline U64 initialSeed = 0x60919C48E57863B9;
@@ -43,3 +41,35 @@ void InitZobrist() {
// init side key
zSide = RandomNum();
}
U64 GetHashKey(Board &board) {
U64 key;
// XORing pieces
for (int color = White; color <= Black; color++) {
for (int piece = Pawn; piece <= King; piece++) {
Bitboard pieceSet = board.pieces[piece];
while (pieceSet) {
int square = pieceSet.getLS1BIndex();
key ^= zKeys[color][piece][square];
pieceSet.PopBit(square);
}
}
}
// XORing en passant
if (board.enPassantTarget != -1) {
key ^= zEnPassant[board.enPassantTarget % 8];
}
// XORing castling rights
key ^= zCastle[board.castlingRights];
// XORing side to move
if (board.sideToMove) key ^= zSide;
return key;
}