-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashkey.c
35 lines (26 loc) · 898 Bytes
/
hashkey.c
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
#include "ark.h"
// This Function gives the posKey of the current board
U64 generatePosKey(const S_BOARD *board){
U64 finalKey = 0;
// Piece Position Information
for(int sq = 0; sq < BRD_SQ_NUM; sq++){
int pieceData = board->pieces[sq];
if(pieceData != NO_SQ && pieceData != EMPTY && pieceData != OFF_BOARD){
ASSERT(pieceData >= wP && pieceData <= bK);
finalKey ^= pieceKey[pieceData][sq];
}
}
// Side Information
if(board->side == WHITE){
finalKey ^= sideKey;
}
// enPass Information
if(board->enPass != NO_SQ){
ASSERT(board->enPass >= 0 && board->enPass < BRD_SQ_NUM);
finalKey ^= pieceKey[EMPTY][board->enPass];
}
// Castle Information
ASSERT(board->castlePerm >= 0 && board->castlePerm <= 15);
finalKey ^= castlePemKey[board->castlePerm];
return finalKey;
}