Line data Source code
1 : #pragma once
2 :
3 : #include "definition.hpp"
4 :
5 : struct Position;
6 :
7 : /*!
8 : * A simple Zobrist hash implementation
9 : */
10 : namespace Zobrist {
11 : extern array2d<Hash,NbSquare,14> ZT; // should be 13 but last ray is for castling[0 7 56 63][13] and ep [k][13] and Color [3 4][13]
12 : extern array1d<Hash,16> ZTCastling; // castling
13 :
14 : void initHash();
15 :
16 : // Compute hash for a move using from/to squares
17 : // Uses unused ZT slot [5][NbPiece] to add variation
18 44704 : [[nodiscard]] constexpr Hash hashMove(MiniMove m) {
19 44704 : const Square from = Move2From(m);
20 44704 : const Square to = Move2To(m);
21 44704 : return ZT[from][NbPiece] ^ ZT[to][NbPiece] ^ ZT[5][NbPiece];
22 : }
23 : } // namespace Zobrist
24 :
25 : // Position hash is computed only once and then updated on the fly
26 : // But this encapsulating function is usefull for debugging
27 : [[nodiscard]] Hash computeHash(const Position &p);
28 :
29 : // Same holds from K+P hash (used for pawn hash table)
30 : [[nodiscard]] Hash computePHash(const Position &p);
|