added GetHashKey function to hash a given board
This commit is contained in:
1 parent
869af6662b
commit
436f2d7164
2 files changed
+34
-2
No files matched your search
+32
-2
@@ -1,6 +1,4 @@
|
|||||||
#include "tt.h"
|
#include "tt.h"
|
||||||
#include "types.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
static inline U64 initialSeed = 0x60919C48E57863B9;
|
static inline U64 initialSeed = 0x60919C48E57863B9;
|
||||||
|
|
||||||
@@ -43,3 +41,35 @@ void InitZobrist() {
|
|||||||
// init side key
|
// init side key
|
||||||
zSide = RandomNum();
|
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;
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
void InitZobrist();
|
void InitZobrist();
|
||||||
|
U64 GetHashKey(Board &board);
|
||||||
Reference in new issue
Block a user