Skip to content
This repository
Browse code

Rewrok the extendeable patch

Cleanup and document.

The real functional change is that not mate threat
moves are never pruned, as could happen before.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
  • Loading branch information...
commit c3ba5fb9d382f378541fc4c92d19f94071885c0f 1 parent eba8925
Marco Costalba authored

Showing 1 changed file with 35 additions and 46 deletions. Show diff stats Hide diff stats

  1. 81  src/search.cpp
81  src/search.cpp
@@ -245,7 +245,7 @@ namespace {
245 245
   void sp_update_pv(SearchStack *pss, SearchStack ss[], int ply);
246 246
   bool connected_moves(const Position &pos, Move m1, Move m2);
247 247
   bool move_is_killer(Move m, const SearchStack& ss);
248  
-  Depth extension(const Position &pos, Move m, bool pvNode, bool check, bool singleReply, bool mateThreat, bool* extendable);
  248
+  Depth extension(const Position &pos, Move m, bool pvNode, bool check, bool singleReply, bool mateThreat, bool* dangerous);
249 249
   bool ok_to_do_nullmove(const Position &pos);
250 250
   bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d);
251 251
   bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply);
@@ -778,8 +778,8 @@ namespace {
778 778
                       << " currmovenumber " << i + 1 << std::endl;
779 779
 
780 780
         // Decide search depth for this move
781  
-        bool dummy;
782  
-        ext = extension(pos, move, true, pos.move_is_check(move), false, false, &dummy);
  781
+        bool dangerous;
  782
+        ext = extension(pos, move, true, pos.move_is_check(move), false, false, &dangerous);
783 783
         newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
784 784
 
785 785
         // Make the move, and search it
@@ -953,8 +953,7 @@ namespace {
953 953
     Value value, bestValue = -VALUE_INFINITE;
954 954
     Bitboard dcCandidates = mp.discovered_check_candidates();
955 955
     bool isCheck = pos.is_check();
956  
-    bool mateThreat =   MateThreatExtension[1] > Depth(0)
957  
-                     && pos.has_mate_threat(opposite_color(pos.side_to_move()));
  956
+    bool mateThreat = pos.has_mate_threat(opposite_color(pos.side_to_move()));
958 957
 
959 958
     // Loop through all legal moves until no moves remain or a beta cutoff
960 959
     // occurs.
@@ -967,7 +966,6 @@ namespace {
967 966
       bool singleReply = (isCheck && mp.number_of_moves() == 1);
968 967
       bool moveIsCheck = pos.move_is_check(move, dcCandidates);
969 968
       bool moveIsCapture = pos.move_is_capture(move);
970  
-      bool moveIsPassedPawnPush = pos.move_is_passed_pawn_push(move);
971 969
 
972 970
       movesSearched[moveCount++] = ss[ply].currentMove = move;
973 971
 
@@ -979,8 +977,8 @@ namespace {
979 977
           ss[ply].currentMoveCaptureValue = Value(0);
980 978
 
981 979
       // Decide the new search depth
982  
-      bool extendable;
983  
-      Depth ext = extension(pos, move, true, moveIsCheck, singleReply, mateThreat, &extendable);
  980
+      bool dangerous;
  981
+      Depth ext = extension(pos, move, true, moveIsCheck, singleReply, mateThreat, &dangerous);
984 982
       Depth newDepth = depth - OnePly + ext;
985 983
 
986 984
       // Make and search the move
@@ -994,11 +992,10 @@ namespace {
994 992
         // Try to reduce non-pv search depth by one ply if move seems not problematic,
995 993
         // if the move fails high will be re-searched at full depth.
996 994
         if (    depth >= 2*OnePly
997  
-            && !extendable
998 995
             &&  moveCount >= LMRPVMoves
  996
+            && !dangerous
999 997
             && !moveIsCapture
1000 998
             && !move_promotion(move)
1001  
-            && !moveIsPassedPawnPush
1002 999
             && !move_is_castle(move)
1003 1000
             && !move_is_killer(move, ss[ply]))
1004 1001
         {
@@ -1222,20 +1219,18 @@ namespace {
1222 1219
       bool singleReply = (isCheck && mp.number_of_moves() == 1);
1223 1220
       bool moveIsCheck = pos.move_is_check(move, dcCandidates);
1224 1221
       bool moveIsCapture = pos.move_is_capture(move);
1225  
-      bool moveIsPassedPawnPush = pos.move_is_passed_pawn_push(move);
1226 1222
 
1227 1223
       movesSearched[moveCount++] = ss[ply].currentMove = move;
1228 1224
 
1229 1225
       // Decide the new search depth
1230  
-      bool extendable;
1231  
-      Depth ext = extension(pos, move, false, moveIsCheck, singleReply, mateThreat, &extendable);
  1226
+      bool dangerous;
  1227
+      Depth ext = extension(pos, move, false, moveIsCheck, singleReply, mateThreat, &dangerous);
1232 1228
       Depth newDepth = depth - OnePly + ext;
1233 1229
 
1234 1230
       // Futility pruning
1235 1231
       if (    useFutilityPruning
1236  
-          && !extendable
  1232
+          && !dangerous
1237 1233
           && !moveIsCapture
1238  
-          && !moveIsPassedPawnPush
1239 1234
           && !move_promotion(move))
1240 1235
       {
1241 1236
           if (   moveCount >= 2 + int(depth)
@@ -1263,12 +1258,11 @@ namespace {
1263 1258
 
1264 1259
       // Try to reduce non-pv search depth by one ply if move seems not problematic,
1265 1260
       // if the move fails high will be re-searched at full depth.
1266  
-      if (   depth >= 2*OnePly
1267  
-          && !extendable
1268  
-          && moveCount >= LMRNonPVMoves
  1261
+      if (    depth >= 2*OnePly
  1262
+          &&  moveCount >= LMRNonPVMoves
  1263
+          && !dangerous
1269 1264
           && !moveIsCapture
1270 1265
           && !move_promotion(move)
1271  
-          && !moveIsPassedPawnPush
1272 1266
           && !move_is_castle(move)
1273 1267
           && !move_is_killer(move, ss[ply]))
1274 1268
       {
@@ -1401,20 +1395,17 @@ namespace {
1401 1395
     {
1402 1396
       assert(move_is_ok(move));
1403 1397
 
1404  
-      bool moveIsCheck = pos.move_is_check(move, dcCandidates);
1405  
-      bool moveIsPassedPawnPush = pos.move_is_passed_pawn_push(move);
1406  
-
1407 1398
       moveCount++;
1408 1399
       ss[ply].currentMove = move;
1409 1400
 
1410 1401
       // Futility pruning
1411 1402
       if (    UseQSearchFutilityPruning
  1403
+          &&  enoughMaterial
1412 1404
           && !isCheck
1413  
-          && !moveIsCheck
1414  
-          && !move_promotion(move)
1415  
-          && !moveIsPassedPawnPush
1416 1405
           && !pvNode
1417  
-          &&  enoughMaterial)
  1406
+          && !move_promotion(move)
  1407
+          && !pos.move_is_check(move, dcCandidates)
  1408
+          && !pos.move_is_passed_pawn_push(move))
1418 1409
       {
1419 1410
           Value futilityValue = staticValue
1420 1411
                               + Max(pos.midgame_value_of_piece_on(move_to(move)),
@@ -1509,7 +1500,6 @@ namespace {
1509 1500
 
1510 1501
       bool moveIsCheck = pos.move_is_check(move, sp->dcCandidates);
1511 1502
       bool moveIsCapture = pos.move_is_capture(move);
1512  
-      bool moveIsPassedPawnPush = pos.move_is_passed_pawn_push(move);
1513 1503
 
1514 1504
       lock_grab(&(sp->lock));
1515 1505
       int moveCount = ++sp->moves;
@@ -1518,15 +1508,14 @@ namespace {
1518 1508
       ss[sp->ply].currentMove = move;
1519 1509
 
1520 1510
       // Decide the new search depth.
1521  
-      bool extendable;
1522  
-      Depth ext = extension(pos, move, false, moveIsCheck, false, false, &extendable);
  1511
+      bool dangerous;
  1512
+      Depth ext = extension(pos, move, false, moveIsCheck, false, false, &dangerous);
1523 1513
       Depth newDepth = sp->depth - OnePly + ext;
1524 1514
 
1525 1515
       // Prune?
1526 1516
       if (    useFutilityPruning
1527  
-          && !extendable
  1517
+          && !dangerous
1528 1518
           && !moveIsCapture
1529  
-          && !moveIsPassedPawnPush
1530 1519
           && !move_promotion(move)
1531 1520
           &&  moveCount >= 2 + int(sp->depth)
1532 1521
           &&  ok_to_prune(pos, move, ss[sp->ply].threatMove, sp->depth))
@@ -1538,10 +1527,9 @@ namespace {
1538 1527
 
1539 1528
       // Try to reduce non-pv search depth by one ply if move seems not problematic,
1540 1529
       // if the move fails high will be re-searched at full depth.
1541  
-      if (   !extendable
  1530
+      if (   !dangerous
1542 1531
           &&  moveCount >= LMRNonPVMoves
1543 1532
           && !moveIsCapture
1544  
-          && !moveIsPassedPawnPush
1545 1533
           && !move_promotion(move)
1546 1534
           && !move_is_castle(move)
1547 1535
           && !move_is_killer(move, ss[sp->ply]))
@@ -1622,7 +1610,6 @@ namespace {
1622 1610
     {
1623 1611
       bool moveIsCheck = pos.move_is_check(move, sp->dcCandidates);
1624 1612
       bool moveIsCapture = pos.move_is_capture(move);
1625  
-      bool moveIsPassedPawnPush = pos.move_is_passed_pawn_push(move);
1626 1613
 
1627 1614
       assert(move_is_ok(move));
1628 1615
 
@@ -1636,8 +1623,8 @@ namespace {
1636 1623
       ss[sp->ply].currentMove = move;
1637 1624
 
1638 1625
       // Decide the new search depth.
1639  
-      bool extendable;
1640  
-      Depth ext = extension(pos, move, true, moveIsCheck, false, false, &extendable);
  1626
+      bool dangerous;
  1627
+      Depth ext = extension(pos, move, true, moveIsCheck, false, false, &dangerous);
1641 1628
       Depth newDepth = sp->depth - OnePly + ext;
1642 1629
 
1643 1630
       // Make and search the move.
@@ -1646,10 +1633,9 @@ namespace {
1646 1633
 
1647 1634
       // Try to reduce non-pv search depth by one ply if move seems not problematic,
1648 1635
       // if the move fails high will be re-searched at full depth.
1649  
-      if (   !extendable
  1636
+      if (   !dangerous
1650 1637
           &&  moveCount >= LMRPVMoves
1651 1638
           && !moveIsCapture
1652  
-          && !moveIsPassedPawnPush
1653 1639
           && !move_promotion(move)
1654 1640
           && !move_is_castle(move)
1655 1641
           && !move_is_killer(move, ss[sp->ply]))
@@ -2053,13 +2039,16 @@ namespace {
2053 2039
 
2054 2040
   // extension() decides whether a move should be searched with normal depth,
2055 2041
   // or with extended depth.  Certain classes of moves (checking moves, in
2056  
-  // particular) are searched with bigger depth than ordinary moves.
  2042
+  // particular) are searched with bigger depth than ordinary moves and in
  2043
+  // any case are marked as 'dangerous'. Note that also if a move is not
  2044
+  // extended, as example because the corresponding UCI option is set to zero,
  2045
+  // the move is marked as 'dangerous' so, at least, we avoid to prune it.
2057 2046
 
2058  
-  Depth extension(const Position &pos, Move m, bool pvNode,
2059  
-                  bool check, bool singleReply, bool mateThreat, bool* extendable) {
  2047
+  Depth extension(const Position &pos, Move m, bool pvNode, bool check,
  2048
+                  bool singleReply, bool mateThreat, bool* dangerous) {
2060 2049
 
2061 2050
     Depth result = Depth(0);
2062  
-    *extendable = check || singleReply || mateThreat;
  2051
+    *dangerous = check || singleReply || mateThreat;
2063 2052
 
2064 2053
     if (check)
2065 2054
         result += CheckExtension[pvNode];
@@ -2073,12 +2062,12 @@ namespace {
2073 2062
     if (pos.move_is_pawn_push_to_7th(m))
2074 2063
     {
2075 2064
         result += PawnPushTo7thExtension[pvNode];
2076  
-        *extendable = true;
  2065
+        *dangerous = true;
2077 2066
     }
2078 2067
     if (pos.move_is_passed_pawn_push(m))
2079 2068
     {
2080 2069
         result += PassedPawnExtension[pvNode];
2081  
-        *extendable = true;
  2070
+        *dangerous = true;
2082 2071
     }
2083 2072
 
2084 2073
     if (   pos.midgame_value_of_piece_on(move_to(m)) >= RookValueMidgame
@@ -2087,7 +2076,7 @@ namespace {
2087 2076
         && !move_promotion(m))
2088 2077
     {
2089 2078
         result += PawnEndgameExtension[pvNode];
2090  
-        *extendable = true;
  2079
+        *dangerous = true;
2091 2080
     }
2092 2081
 
2093 2082
     if (   pvNode
@@ -2096,7 +2085,7 @@ namespace {
2096 2085
         && pos.see(m) >= 0)
2097 2086
     {
2098 2087
         result += OnePly/2;
2099  
-        *extendable = true;
  2088
+        *dangerous = true;
2100 2089
     }
2101 2090
 
2102 2091
     return Min(result, OnePly);

0 notes on commit c3ba5fb

Please sign in to comment.
Something went wrong with that request. Please try again.