]> git.sesse.net Git - stockfish/commitdiff
Reformat and rename hash_after_move()
authorMarco Costalba <mcostalba@gmail.com>
Sat, 4 Oct 2014 04:07:55 +0000 (06:07 +0200)
committerJoona Kiiski <joona.kiiski@gmail.com>
Sat, 4 Oct 2014 09:36:29 +0000 (10:36 +0100)
Align to standard coding style and properly use
enum types. Rename while there.

No functional change.

src/position.cpp
src/position.h
src/search.cpp

index b2d46b83a6a3b3d19494f2f0c424cd0df8188905..b7baeb6b77d248128893fae25a411638d2805382 100644 (file)
@@ -1015,22 +1015,27 @@ void Position::undo_null_move() {
   sideToMove = ~sideToMove;
 }
 
   sideToMove = ~sideToMove;
 }
 
-// Position::hash_after_move() updates the hash key needed for the speculative prefetch.
-// It doesn't recognize special moves like castling, en-passant and promotions.
-Key Position::hash_after_move(Move m) const {
-
-  int from = from_sq(m);
-  int to = to_sq(m);
-  Piece p = board[from];
-  Piece capP = board[to];
-  Key ret = st->key ^ Zobrist::side;
-  if (capP != NO_PIECE)
-      ret ^= Zobrist::psq[color_of(capP)][type_of(capP)][to];
-  ret ^= Zobrist::psq[color_of(p)][type_of(p)][to];
-  ret ^= Zobrist::psq[color_of(p)][type_of(p)][from];
-  return ret;
+
+/// Position::key_after() computes the new hash key after the given moven. Needed
+/// for speculative prefetch. It doesn't recognize special moves like castling,
+/// en-passant and promotions.
+
+Key Position::key_after(Move m) const {
+
+  Color us = sideToMove;
+  Square from = from_sq(m);
+  Square to = to_sq(m);
+  PieceType pt = type_of(piece_on(from));
+  PieceType captured = type_of(piece_on(to));
+  Key k = st->key ^ Zobrist::side;
+
+  if (captured)
+      k ^= Zobrist::psq[~us][captured][to];
+
+  return k ^ Zobrist::psq[us][pt][to] ^ Zobrist::psq[us][pt][from];
 }
 
 }
 
+
 /// Position::see() is a static exchange evaluator: It tries to estimate the
 /// material gain or loss resulting from a move.
 
 /// Position::see() is a static exchange evaluator: It tries to estimate the
 /// material gain or loss resulting from a move.
 
index 7565abb92cf90dbadebaf59cea290e3e05a7876b..72932f778e9c07af6bcb9ce89e2822a8b78ddc61 100644 (file)
@@ -139,7 +139,6 @@ public:
   void undo_move(Move m);
   void do_null_move(StateInfo& st);
   void undo_null_move();
   void undo_move(Move m);
   void do_null_move(StateInfo& st);
   void undo_null_move();
-  Key hash_after_move(Move m) const;
 
   // Static exchange evaluation
   Value see(Move m) const;
 
   // Static exchange evaluation
   Value see(Move m) const;
@@ -147,6 +146,7 @@ public:
 
   // Accessing hash keys
   Key key() const;
 
   // Accessing hash keys
   Key key() const;
+  Key key_after(Move m) const;
   Key exclusion_key() const;
   Key pawn_key() const;
   Key material_key() const;
   Key exclusion_key() const;
   Key pawn_key() const;
   Key material_key() const;
index 32f42cf07e879777c8b7241fe8a517d65e33f8b2..5b56af58051de0e8eff643260468c099f917f650 100644 (file)
@@ -788,8 +788,8 @@ moves_loop: // When in check and at SpNode search starts from here
           }
       }
 
           }
       }
 
-      // Speculative prefetch
-      prefetch((char*)TT.first_entry(pos.hash_after_move(move)));
+      // Speculative prefetch as early as possible
+      prefetch((char*)TT.first_entry(pos.key_after(move)));
 
       // Check for legality just before making the move
       if (!RootNode && !SpNode && !pos.legal(move, ci.pinned))
 
       // Check for legality just before making the move
       if (!RootNode && !SpNode && !pos.legal(move, ci.pinned))
@@ -1140,8 +1140,8 @@ moves_loop: // When in check and at SpNode search starts from here
           &&  pos.see_sign(move) < VALUE_ZERO)
           continue;
 
           &&  pos.see_sign(move) < VALUE_ZERO)
           continue;
 
-      // Speculative prefetch
-      prefetch((char*)TT.first_entry(pos.hash_after_move(move)));
+      // Speculative prefetch as early as possible
+      prefetch((char*)TT.first_entry(pos.key_after(move)));
 
       // Check for legality just before making the move
       if (!pos.legal(move, ci.pinned))
 
       // Check for legality just before making the move
       if (!pos.legal(move, ci.pinned))