2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 uint64_t hash_code
[2][7][64];
31 int color
, piece
, square
;
33 for (color
= WHITE
; color
<= BLACK
; color
++)
34 for (piece
= PAWN
; piece
<= KING
; piece
++)
35 for (square
= 0; square
< 64; square
++) {
36 p
= piece
* 2 - color
- 1;
37 hash_code
[color
][piece
][square
] = \
38 p_hash_piece
[64 * p
+ _RANK(square
) * 8 + _FILE(square
)];
41 for (square
= 0; square
< 8; square
++)
42 hash_ep
[square
] = p_hash_ep
[square
];
44 hash_wck
= p_hash_castle
[0];
45 hash_wcq
= p_hash_castle
[1];
46 hash_bck
= p_hash_castle
[2];
47 hash_bcq
= p_hash_castle
[3];
48 hash_side
= p_hash_side
[0];
52 calc_zobrist(uint64_t *hash_key
, uint64_t *hash_pawn_key
)
57 *hash_key
= *hash_pawn_key
= 0ULL;
59 for (color
= WHITE
; color
<= BLACK
; color
++) {
60 for (piece
= PAWN
; piece
<= KING
; piece
++) {
61 b
= piece_boards
[color
][piece
];
65 *hash_key
^= hash_code
[color
][piece
][sq
];
67 *hash_pawn_key
^= hash_code
[color
][piece
][sq
];
71 if (brd
.castle_mask
& WHITE_CASTLE_KINGSIDE
)
72 *hash_key
^= hash_wck
;
73 if (brd
.castle_mask
& WHITE_CASTLE_QUEENSIDE
)
74 *hash_key
^= hash_wcq
;
75 if (brd
.castle_mask
& BLACK_CASTLE_KINGSIDE
)
76 *hash_key
^= hash_bck
;
77 if (brd
.castle_mask
& BLACK_CASTLE_QUEENSIDE
)
78 *hash_key
^= hash_bcq
;
81 *hash_key
^= hash_ep
[_FILE(brd
.ep
)];
83 *hash_key
^= hash_side
;