-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashkeys.c
More file actions
36 lines (27 loc) · 764 Bytes
/
hashkeys.c
File metadata and controls
36 lines (27 loc) · 764 Bytes
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
34
35
36
//
// Created by Eric Silverman on 12/10/2018.
//
#include "defs.h"
U64 GeneratePosKey(const S_BOARD *pos) {
int sq = 0;
U64 finalKey = 0;
int piece = EMPTY;
// pieces
for(sq = 0; sq < BRD_SQ_NUM; ++sq) {
piece = pos->pieces[sq];
if(piece!=NO_SQ && piece!=EMPTY && piece !=OFFBOARD) {
ASSERT(piece>=wP && piece<=bK);
finalKey ^= PieceKeys[piece][sq];
}
}
if(pos->side == WHITE) {
finalKey ^= SideKey;
}
if(pos->enPas != NO_SQ) {
ASSERT(pos->enPas>=0 && pos->enPas<BRD_SQ_NUM);
finalKey ^= PieceKeys[EMPTY][pos->enPas];
}
ASSERT(pos->castlePerm>=0 && pos->castlePerm<=15);
finalKey ^= CastleKeys[pos->castlePerm];
return finalKey;
}