-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashkeys.cpp
33 lines (24 loc) · 856 Bytes
/
hashkeys.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "defs.h"
/*This file is used to determine the posKey. To get a unique key for each position. This can be used to determine if a 3 fold repitiion has occured.*/
// a ^ b ^ c (if you want to take out c then xor it again) => a ^ b = a ^ b ^ c ^ c
U64 GeneratePosKey(const S_BOARD *pos)
{
U64 finalKey = 0ULL;
for (int sq = 0; sq < 120; sq++)
{
int piece = pos->board[sq];
if (sq != NO_SQ && piece != EMPTY && piece != 120)
{
ASSERT(piece >= wP && piece <= bK);
finalKey ^= PieceKeys[piece][sq];
}
}
if (pos->enPas != NO_SQ)
{
ASSERT(pos->enPas >= 0 && pos->enPas < 120);
finalKey ^= PieceKeys[EMPTY][pos->enPas];
}
ASSERT(pos->castlePerm >= 0 && pos->castlePerm <= 15);
finalKey ^= CastleKeys[pos->castlePerm];
return finalKey;
}