1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-02 09:39:36 +00:00

Index en-passant zobrist keys by file

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>
This commit is contained in:
Marco Costalba 2012-02-19 11:28:42 +01:00
parent 3441e0075d
commit ec5b9994b5
2 changed files with 9 additions and 9 deletions

View file

@ -36,7 +36,7 @@ using std::cout;
using std::endl; using std::endl;
Key Position::zobrist[2][8][64]; Key Position::zobrist[2][8][64];
Key Position::zobEp[64]; Key Position::zobEp[8];
Key Position::zobCastle[16]; Key Position::zobCastle[16];
Key Position::zobSideToMove; Key Position::zobSideToMove;
Key Position::zobExclusion; Key Position::zobExclusion;
@ -835,7 +835,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
// Reset en passant square // Reset en passant square
if (st->epSquare != SQ_NONE) if (st->epSquare != SQ_NONE)
{ {
k ^= zobEp[st->epSquare]; k ^= zobEp[file_of(st->epSquare)];
st->epSquare = SQ_NONE; st->epSquare = SQ_NONE;
} }
@ -873,7 +873,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
&& (attacks_from<PAWN>(from + pawn_push(us), us) & pieces(PAWN, them))) && (attacks_from<PAWN>(from + pawn_push(us), us) & pieces(PAWN, them)))
{ {
st->epSquare = Square((from + to) / 2); st->epSquare = Square((from + to) / 2);
k ^= zobEp[st->epSquare]; k ^= zobEp[file_of(st->epSquare)];
} }
if (is_promotion(m)) if (is_promotion(m))
@ -1146,7 +1146,7 @@ void Position::do_castle_move(Move m) {
// Clear en passant square // Clear en passant square
if (st->epSquare != SQ_NONE) 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;
} }
@ -1195,7 +1195,7 @@ void Position::do_null_move(StateInfo& backupSt) {
if (Do) if (Do)
{ {
if (st->epSquare != SQ_NONE) if (st->epSquare != SQ_NONE)
st->key ^= zobEp[st->epSquare]; st->key ^= zobEp[file_of(st->epSquare)];
st->key ^= zobSideToMove; st->key ^= zobSideToMove;
prefetch((char*)TT.first_entry(st->key)); prefetch((char*)TT.first_entry(st->key));
@ -1396,7 +1396,7 @@ Key Position::compute_key() const {
result ^= zobrist[color_of(piece_on(s))][type_of(piece_on(s))][s]; result ^= zobrist[color_of(piece_on(s))][type_of(piece_on(s))][s];
if (ep_square() != SQ_NONE) if (ep_square() != SQ_NONE)
result ^= zobEp[ep_square()]; result ^= zobEp[file_of(ep_square())];
if (sideToMove == BLACK) if (sideToMove == BLACK)
result ^= zobSideToMove; result ^= zobSideToMove;
@ -1542,8 +1542,8 @@ void Position::init() {
for (Square s = SQ_A1; s <= SQ_H8; s++) for (Square s = SQ_A1; s <= SQ_H8; s++)
zobrist[c][pt][s] = rk.rand<Key>(); zobrist[c][pt][s] = rk.rand<Key>();
for (Square s = SQ_A1; s <= SQ_H8; s++) for (File f = FILE_A; f <= FILE_H; f++)
zobEp[s] = rk.rand<Key>(); zobEp[f] = rk.rand<Key>();
for (int cr = CASTLES_NONE; cr <= ALL_CASTLES; cr++) for (int cr = CASTLES_NONE; cr <= ALL_CASTLES; cr++)
{ {

View file

@ -257,7 +257,7 @@ private:
// Static variables // Static variables
static Score pieceSquareTable[16][64]; // [piece][square] static Score pieceSquareTable[16][64]; // [piece][square]
static Key zobrist[2][8][64]; // [color][pieceType][square]/[piece count] 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 zobCastle[16]; // [castleRight]
static Key zobSideToMove; static Key zobSideToMove;
static Key zobExclusion; static Key zobExclusion;