-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashkeys.c
More file actions
30 lines (24 loc) · 731 Bytes
/
hashkeys.c
File metadata and controls
30 lines (24 loc) · 731 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
#include "hashkeys.h"
uint64_t generatePosKey(const S_BOARD *pos) {
int sq = 0;
uint64_t 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;
}