]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Retire to_char() helpers
[stockfish] / src / position.cpp
index b2d46b83a6a3b3d19494f2f0c424cd0df8188905..ba399b128c45ea7ab30c4440d71682fe1817ba25 100644 (file)
@@ -409,16 +409,16 @@ const string Position::fen() const {
   ss << (sideToMove == WHITE ? " w " : " b ");
 
   if (can_castle(WHITE_OO))
-      ss << (chess960 ? to_char(file_of(castling_rook_square(WHITE |  KING_SIDE)), false) : 'K');
+      ss << (chess960 ? 'A' + file_of(castling_rook_square(WHITE |  KING_SIDE)) : 'K');
 
   if (can_castle(WHITE_OOO))
-      ss << (chess960 ? to_char(file_of(castling_rook_square(WHITE | QUEEN_SIDE)), false) : 'Q');
+      ss << (chess960 ? 'A' + file_of(castling_rook_square(WHITE | QUEEN_SIDE)) : 'Q');
 
   if (can_castle(BLACK_OO))
-      ss << (chess960 ? to_char(file_of(castling_rook_square(BLACK |  KING_SIDE)),  true) : 'k');
+      ss << (chess960 ? 'a' + file_of(castling_rook_square(BLACK |  KING_SIDE)) : 'k');
 
   if (can_castle(BLACK_OOO))
-      ss << (chess960 ? to_char(file_of(castling_rook_square(BLACK | QUEEN_SIDE)),  true) : 'q');
+      ss << (chess960 ? 'a' + file_of(castling_rook_square(BLACK | QUEEN_SIDE)) : 'q');
 
   if (!can_castle(WHITE) && !can_castle(BLACK))
       ss << '-';
@@ -807,9 +807,6 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
       st->castlingRights &= ~cr;
   }
 
-  // Prefetch TT access as soon as we know the new hash key
-  prefetch((char*)TT.first_entry(k));
-
   // Move the piece. The tricky Chess960 castling is handled earlier
   if (type_of(m) != CASTLING)
       move_piece(from, to, us, pt);
@@ -1015,22 +1012,27 @@ void Position::undo_null_move() {
   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.