]> git.sesse.net Git - stockfish/commitdiff
Index en-passant zobrist keys by file
authorMarco Costalba <mcostalba@gmail.com>
Sun, 19 Feb 2012 10:28:42 +0000 (11:28 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 19 Feb 2012 10:31:36 +0000 (11:31 +0100)
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>
src/position.cpp
src/position.h

index ef510766afcd592e8e29b19f0e88a464447b51b9..f4b051ed762a31ac1b1ff48aa72bc82867d6e798 100644 (file)
@@ -36,7 +36,7 @@ using std::cout;
 using std::endl;
 
 Key Position::zobrist[2][8][64];
 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;
 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)
   {
   // 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;
   }
 
@@ -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)))
       {
           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)];
       }
 
       if (is_promotion(m))
       }
 
       if (is_promotion(m))
@@ -1146,7 +1146,7 @@ void Position::do_castle_move(Move m) {
       // 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;
       }
 
@@ -1195,7 +1195,7 @@ void Position::do_null_move(StateInfo& backupSt) {
   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));
@@ -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 ^= 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;
@@ -1542,8 +1542,8 @@ void Position::init() {
           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++)
   {
index e471baea099029c5b7d72dbb9d472a9d780b462a..7db5fa453ff9e644b1a9806e26b917a9861c5e63 100644 (file)
@@ -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 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;