]> git.sesse.net Git - stockfish/blobdiff - src/search.cpp
Retire MovePicker::discovered_check_candidates()
[stockfish] / src / search.cpp
index d073b7da31a2e14056bee54e2c4d45dbfd8b0ba7..978041e8ff5bad79f9483ac5fabc551165f802be 100644 (file)
@@ -326,6 +326,37 @@ namespace {
 //// Functions
 ////
 
+
+/// perft() is our utility to verify move generation is bug free. All the
+/// legal moves up to given depth are generated and counted and the sum returned.
+
+int perft(Position& pos, Depth depth)
+{
+    Move move;
+    MovePicker mp = MovePicker(pos, MOVE_NONE, depth, H);
+    Bitboard dcCandidates = pos.discovered_check_candidates(pos.side_to_move());
+    int sum = 0;
+
+    // If we are at the last ply we don't need to do and undo
+    // the moves, just to count them.
+    if (depth <= OnePly) // Replace with '<' to test also qsearch
+    {
+        while ((move = mp.get_next_move()) != MOVE_NONE) sum++;
+        return sum;
+    }
+
+    // Loop through all legal moves
+    while ((move = mp.get_next_move()) != MOVE_NONE)
+    {
+      StateInfo st;
+      pos.do_move(move, st, dcCandidates);
+      sum += perft(pos, depth - OnePly);
+      pos.undo_move(move);
+    }
+    return sum;
+}
+
+
 /// think() is the external interface to Stockfish's search, and is called when
 /// the program receives the UCI 'go' command. It initializes various
 /// search-related global variables, and calls root_search(). It returns false
@@ -447,7 +478,7 @@ bool think(const Position& pos, bool infinite, bool ponder, int side_to_move,
       if (movesToGo == 1)
       {
           MaxSearchTime = myTime / 2;
-          AbsoluteMaxSearchTime = 
+          AbsoluteMaxSearchTime =
              (myTime > 3000)? (myTime - 500) : ((myTime * 3) / 4);
       } else {
           MaxSearchTime = myTime / Min(movesToGo, 20);
@@ -976,7 +1007,7 @@ namespace {
                 std::cout << std::endl;
 
                 if (UseLogFile)
-                    LogFile << pretty_pv(pos, current_search_time(), Iteration, nodes_searched(), value, 
+                    LogFile << pretty_pv(pos, current_search_time(), Iteration, nodes_searched(), value,
                                          ((value >= beta)? VALUE_TYPE_LOWER
                                           : ((value <= alpha)? VALUE_TYPE_UPPER : VALUE_TYPE_EXACT)),
                                          ss[0].pv)
@@ -1079,7 +1110,7 @@ namespace {
     bool mateThreat = pos.has_mate_threat(opposite_color(us));
 
     MovePicker mp = MovePicker(pos, ttMove, depth, H, &ss[ply]);
-    Bitboard dcCandidates = mp.discovered_check_candidates();
+    Bitboard dcCandidates = pos.discovered_check_candidates(us);
 
     // Loop through all legal moves until no moves remain or a beta cutoff
     // occurs.
@@ -1332,7 +1363,8 @@ namespace {
     Move move, movesSearched[256];
     int moveCount = 0;
     Value value, bestValue = -VALUE_INFINITE;
-    Bitboard dcCandidates = mp.discovered_check_candidates();
+    Color us = pos.side_to_move();
+    Bitboard dcCandidates = pos.discovered_check_candidates(us);
     Value futilityValue = VALUE_NONE;
     bool useFutilityPruning =   depth < SelectiveDepth
                              && !isCheck;
@@ -1552,8 +1584,8 @@ namespace {
     MovePicker mp = MovePicker(pos, ttMove, depth, H);
     Move move;
     int moveCount = 0;
-    Bitboard dcCandidates = mp.discovered_check_candidates();
     Color us = pos.side_to_move();
+    Bitboard dcCandidates = pos.discovered_check_candidates(us);
     bool enoughMaterial = pos.non_pawn_material(us) > RookValueMidgame;
 
     // Loop through the moves until no moves remain or a beta cutoff