From: Marco Costalba Date: Sun, 19 Feb 2012 10:28:42 +0000 (+0100) Subject: Index en-passant zobrist keys by file X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=ec5b9994b55a32e0f8d8c6d9684c0f5fc0e4992a 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 --- diff --git a/src/position.cpp b/src/position.cpp index ef510766..f4b051ed 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -36,7 +36,7 @@ using std::cout; using std::endl; Key Position::zobrist[2][8][64]; -Key Position::zobEp[64]; +Key Position::zobEp[8]; Key Position::zobCastle[16]; Key Position::zobSideToMove; Key Position::zobExclusion; @@ -835,7 +835,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI // Reset en passant square if (st->epSquare != SQ_NONE) { - k ^= zobEp[st->epSquare]; + k ^= zobEp[file_of(st->epSquare)]; st->epSquare = SQ_NONE; } @@ -873,7 +873,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI && (attacks_from(from + pawn_push(us), us) & pieces(PAWN, them))) { st->epSquare = Square((from + to) / 2); - k ^= zobEp[st->epSquare]; + k ^= zobEp[file_of(st->epSquare)]; } if (is_promotion(m)) @@ -1146,7 +1146,7 @@ void Position::do_castle_move(Move m) { // 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; } @@ -1195,7 +1195,7 @@ void Position::do_null_move(StateInfo& backupSt) { 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)); @@ -1396,7 +1396,7 @@ Key Position::compute_key() const { 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; @@ -1542,8 +1542,8 @@ void Position::init() { for (Square s = SQ_A1; s <= SQ_H8; s++) zobrist[c][pt][s] = rk.rand(); - for (Square s = SQ_A1; s <= SQ_H8; s++) - zobEp[s] = rk.rand(); + for (File f = FILE_A; f <= FILE_H; f++) + zobEp[f] = rk.rand(); for (int cr = CASTLES_NONE; cr <= ALL_CASTLES; cr++) { diff --git a/src/position.h b/src/position.h index e471baea..7db5fa45 100644 --- a/src/position.h +++ b/src/position.h @@ -257,7 +257,7 @@ private: // 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;