Instead of by square. This is a more conventional
approach, as reported also in:
http://chessprogramming.wikispaces.com/Zobrist+Hashing
We shrink zobEp[] from 64 to 8 keys at the cost of an extra
'and 7' at runtime to get the file out of the ep square.
No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
using std::endl;
Key Position::zobrist[2][8][64];
using std::endl;
Key Position::zobrist[2][8][64];
-Key Position::zobEp[64];
Key Position::zobCastle[16];
Key Position::zobSideToMove;
Key Position::zobExclusion;
Key Position::zobCastle[16];
Key Position::zobSideToMove;
Key Position::zobExclusion;
// Reset en passant square
if (st->epSquare != SQ_NONE)
{
// Reset en passant square
if (st->epSquare != SQ_NONE)
{
- k ^= zobEp[st->epSquare];
+ k ^= zobEp[file_of(st->epSquare)];
st->epSquare = SQ_NONE;
}
st->epSquare = SQ_NONE;
}
&& (attacks_from<PAWN>(from + pawn_push(us), us) & pieces(PAWN, them)))
{
st->epSquare = Square((from + to) / 2);
&& (attacks_from<PAWN>(from + pawn_push(us), us) & pieces(PAWN, them)))
{
st->epSquare = Square((from + to) / 2);
- k ^= zobEp[st->epSquare];
+ k ^= zobEp[file_of(st->epSquare)];
// Clear en passant square
if (st->epSquare != SQ_NONE)
{
// Clear en passant square
if (st->epSquare != SQ_NONE)
{
- st->key ^= zobEp[st->epSquare];
+ st->key ^= zobEp[file_of(st->epSquare)];
st->epSquare = SQ_NONE;
}
st->epSquare = SQ_NONE;
}
if (Do)
{
if (st->epSquare != SQ_NONE)
if (Do)
{
if (st->epSquare != SQ_NONE)
- st->key ^= zobEp[st->epSquare];
+ st->key ^= zobEp[file_of(st->epSquare)];
st->key ^= zobSideToMove;
prefetch((char*)TT.first_entry(st->key));
st->key ^= zobSideToMove;
prefetch((char*)TT.first_entry(st->key));
result ^= zobrist[color_of(piece_on(s))][type_of(piece_on(s))][s];
if (ep_square() != SQ_NONE)
result ^= zobrist[color_of(piece_on(s))][type_of(piece_on(s))][s];
if (ep_square() != SQ_NONE)
- result ^= zobEp[ep_square()];
+ result ^= zobEp[file_of(ep_square())];
if (sideToMove == BLACK)
result ^= zobSideToMove;
if (sideToMove == BLACK)
result ^= zobSideToMove;
for (Square s = SQ_A1; s <= SQ_H8; s++)
zobrist[c][pt][s] = rk.rand<Key>();
for (Square s = SQ_A1; s <= SQ_H8; s++)
zobrist[c][pt][s] = rk.rand<Key>();
- for (Square s = SQ_A1; s <= SQ_H8; s++)
- zobEp[s] = rk.rand<Key>();
+ for (File f = FILE_A; f <= FILE_H; f++)
+ zobEp[f] = rk.rand<Key>();
for (int cr = CASTLES_NONE; cr <= ALL_CASTLES; cr++)
{
for (int cr = CASTLES_NONE; cr <= ALL_CASTLES; cr++)
{
// Static variables
static Score pieceSquareTable[16][64]; // [piece][square]
static Key zobrist[2][8][64]; // [color][pieceType][square]/[piece count]
// Static variables
static Score pieceSquareTable[16][64]; // [piece][square]
static Key zobrist[2][8][64]; // [color][pieceType][square]/[piece count]
- static Key zobEp[64]; // [square]
+ static Key zobEp[8]; // [file]
static Key zobCastle[16]; // [castleRight]
static Key zobSideToMove;
static Key zobExclusion;
static Key zobCastle[16]; // [castleRight]
static Key zobSideToMove;
static Key zobExclusion;