]> git.sesse.net Git - stockfish/blobdiff - src/position.cpp
Prefetch also material tables
[stockfish] / src / position.cpp
index d7e0516c88114007d0ee26473a8ed4b16630668e..abe7fde3226692ad6fc1f0d376f0518c2d9cfb4a 100644 (file)
@@ -160,7 +160,7 @@ void Position::detach() {
 /// string. This function is not very robust - make sure that input FENs are
 /// correct (this is assumed to be the responsibility of the GUI).
 
-void Position::from_fen(const string& fen, bool c960) {
+void Position::from_fen(const string& fen, bool isChess960) {
 /*
    A FEN string defines a particular position using only the ASCII character set.
 
@@ -255,7 +255,7 @@ void Position::from_fen(const string& fen, bool c960) {
   castleRightsMask[make_square(initialQRFile, RANK_1)] ^= WHITE_OOO;
   castleRightsMask[make_square(initialQRFile, RANK_8)] ^= BLACK_OOO;
 
-  isChess960 = c960;
+  chess960 = isChess960;
   find_checkers();
 
   st->key = compute_key();
@@ -368,16 +368,16 @@ const string Position::to_fen() const {
   if (st->castleRights != CASTLES_NONE)
   {
       if (can_castle_kingside(WHITE))
-          fen += isChess960 ? char(toupper(file_to_char(initialKRFile))) : 'K';
+          fen += chess960 ? char(toupper(file_to_char(initialKRFile))) : 'K';
 
       if (can_castle_queenside(WHITE))
-          fen += isChess960 ? char(toupper(file_to_char(initialQRFile))) : 'Q';
+          fen += chess960 ? char(toupper(file_to_char(initialQRFile))) : 'Q';
 
       if (can_castle_kingside(BLACK))
-          fen += isChess960 ? file_to_char(initialKRFile) : 'k';
+          fen += chess960 ? file_to_char(initialKRFile) : 'k';
 
       if (can_castle_queenside(BLACK))
-          fen += isChess960 ? file_to_char(initialQRFile) : 'q';
+          fen += chess960 ? file_to_char(initialQRFile) : 'q';
   } else
       fen += '-';
 
@@ -501,7 +501,7 @@ Bitboard Position::attacks_from(Piece p, Square s) const {
   case WB: case BB: return attacks_from<BISHOP>(s);
   case WR: case BR: return attacks_from<ROOK>(s);
   case WQ: case BQ: return attacks_from<QUEEN>(s);
-  default: return NonSlidingAttacksBB[p][s];
+  default: return StepAttacksBB[p][s];
   }
 }
 
@@ -514,7 +514,7 @@ Bitboard Position::attacks_from(Piece p, Square s, Bitboard occ) {
   case WB: case BB: return bishop_attacks_bb(s, occ);
   case WR: case BR: return rook_attacks_bb(s, occ);
   case WQ: case BQ: return bishop_attacks_bb(s, occ) | rook_attacks_bb(s, occ);
-  default: return NonSlidingAttacksBB[p][s];
+  default: return StepAttacksBB[p][s];
   }
 }
 
@@ -885,7 +885,6 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
 
       // Update pawn hash key and prefetch in L1/L2 cache
       st->pawnKey ^= zobrist[us][PAWN][from] ^ zobrist[us][PAWN][to];
-      prefetchPawn(st->pawnKey, threadID);
 
       // Set en passant square, only if moved pawn can be captured
       if ((to ^ from) == 16)
@@ -938,6 +937,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
       }
   }
 
+  // Prefetch pawn and material hash tables
+  prefetchTables(st->pawnKey, st->materialKey, threadID);
+
   // Update incremental scores
   st->value += pst_delta(piece, from, to);
 
@@ -1689,49 +1691,6 @@ bool Position::is_mate() const {
 }
 
 
-/// Position::has_mate_threat() tests whether the side to move is under
-/// a threat of being mated in one from the current position.
-
-bool Position::has_mate_threat() {
-
-  MoveStack mlist[MOVES_MAX], *last, *cur;
-  StateInfo st1, st2;
-  bool mateFound = false;
-
-  // If we are under check it's up to evasions to do the job
-  if (is_check())
-      return false;
-
-  // First pass the move to our opponent doing a null move
-  do_null_move(st1);
-
-  // Then generate pseudo-legal moves that could give check
-  last = generate<MV_NON_CAPTURE_CHECK>(*this, mlist);
-  last = generate<MV_CAPTURE>(*this, last);
-
-  // Loop through the moves, and see if one of them gives mate
-  Bitboard pinned = pinned_pieces(sideToMove);
-  CheckInfo ci(*this);
-  for (cur = mlist; cur != last && !mateFound; cur++)
-  {
-      Move move = cur->move;
-      if (   !pl_move_is_legal(move, pinned)
-          || !move_is_check(move, ci))
-          continue;
-
-      do_move(move, st2, ci, true);
-
-      if (is_mate())
-          mateFound = true;
-
-      undo_move(move);
-  }
-
-  undo_null_move();
-  return mateFound;
-}
-
-
 /// Position::init_zobrist() is a static member function which initializes at
 /// startup the various arrays used to compute hash keys.
 
@@ -1975,7 +1934,6 @@ bool Position::is_ok(int* failedStep) const {
 
   if (failedStep) (*failedStep)++;
   if (debugPieceList)
-  {
       for (Color c = WHITE; c <= BLACK; c++)
           for (PieceType pt = PAWN; pt <= KING; pt++)
               for (int i = 0; i < pieceCount[c][pt]; i++)
@@ -1986,13 +1944,15 @@ bool Position::is_ok(int* failedStep) const {
                   if (index[piece_list(c, pt, i)] != i)
                       return false;
               }
-  }
 
   if (failedStep) (*failedStep)++;
-  if (debugCastleSquares) {
-      for (Color c = WHITE; c <= BLACK; c++) {
+  if (debugCastleSquares)
+  {
+      for (Color c = WHITE; c <= BLACK; c++)
+      {
           if (can_castle_kingside(c) && piece_on(initial_kr_square(c)) != make_piece(c, ROOK))
               return false;
+
           if (can_castle_queenside(c) && piece_on(initial_qr_square(c)) != make_piece(c, ROOK))
               return false;
       }