15 static uint64 Castle64[16];
19 static uint64 hash_castle_key_debug (int flags);
29 for (i = 0; i < 16; i++) Castle64[i] = hash_castle_key_debug(i);
34 uint64 hash_key(const board_t * board) {
41 ASSERT(board_is_ok(board));
49 for (colour = 1; colour <= 2; colour++) { // HACK
50 for (ptr = board->list[colour]; (sq=*ptr) != SquareNone; ptr++) {
51 piece = board->square[sq];
52 key ^= hash_piece_key(piece,sq);
58 key ^= hash_castle_key(board_flags(board));
62 sq = board->ep_square;
63 if (sq != SquareNone) key ^= hash_ep_key(sq);
67 key ^= hash_turn_key(board->turn);
74 uint64 hash_piece_key(int piece, int square) {
76 ASSERT(piece_is_ok(piece));
77 ASSERT(square_is_ok(square));
79 return random_64(RandomPiece+piece_to_12(piece)*64+square_to_64(square));
84 uint64 hash_castle_key(int flags) {
86 ASSERT((flags&~0xF)==0);
88 return Castle64[flags];
91 // hash_castle_key_debug()
93 static uint64 hash_castle_key_debug(int flags) {
98 ASSERT((flags&~0xF)==0);
102 for (i = 0; i < 4; i++) {
103 if ((flags & (1<<i)) != 0) key ^= random_64(RandomCastle+i);
111 uint64 hash_ep_key(int square) {
113 ASSERT(square_is_ok(square));
115 return random_64(RandomEnPassant+square_file(square));
120 uint64 hash_turn_key(int colour) {
122 ASSERT(colour_is_ok(colour));
124 return (colour_is_white(colour)) ? random_64(RandomTurn) : 0;