diff options
Diffstat (limited to 'src/zobrist.cpp')
| -rw-r--r-- | src/zobrist.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/zobrist.cpp b/src/zobrist.cpp index c06f1a2..afef3e6 100644 --- a/src/zobrist.cpp +++ b/src/zobrist.cpp @@ -348,6 +348,39 @@ void InitZobrist() { SideKey = PolyglotRandom64[idx]; } +void xorCastleKey(bool color, bool IS_KING_SIDE, Game *g) { + const bool WHITE = true; + + if (color == WHITE && IS_KING_SIDE && g->whiteCastleKing) { + g->hash ^= CastleKeys[0]; + }; + if (color == WHITE && !IS_KING_SIDE && g->whiteCastleQueen) { + g->hash ^= CastleKeys[1]; + }; + if (color == !WHITE && IS_KING_SIDE && g->blackCastleKing) { + g->hash ^= CastleKeys[2]; + }; + if (color == !WHITE && !IS_KING_SIDE && g->blackCastleQueen) { + g->hash ^= CastleKeys[3]; + }; +} +void xorSidekey(Game *g) { g->hash ^= SideKey; } +void xorEnpassantKey(Game *g) { + if (g->canEnpassant && IsEnpassantLegal(g)) { + g->hash ^= EnPassantKeys[g->enPassant.file]; + } +} +void xorSquare(uint8_t square, Game *g) { + Piece p = g->pieces[square]; + if (p.type == NONEPIECE) { + return; + } + g->hash ^= PieceKeys[p.color][p.type][square]; +} + +/* + * should be only called at start of game + */ uint64_t GenerateZobristKey(Game *b) { uint64_t key = 0; |
