Skip to content

Commit

Permalink
Remove skipQuiets variable in search()
Browse files Browse the repository at this point in the history
This is a functional simplification. The moveCountPruning variable and the
skipQuiets variable are similar enough in function that they can be combined.
This removes the skipQuiets variable in search.

STC
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 23278 W: 5210 L: 5091 D: 12977
http://tests.stockfishchess.org/tests/view/5c65dc490ebc5925cffc12e9

LTC
LLR: 2.95 (-2.94,2.94) [-3.00,1.00]
Total: 77107 W: 12792 L: 12761 D: 51554
http://tests.stockfishchess.org/tests/view/5c65e4360ebc5925cffc1490

Closes #2011

bench 3640330
  • Loading branch information
protonspring authored and snicolet committed Feb 21, 2019
1 parent 3c92f84 commit 76d2f5b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/search.cpp
Expand Up @@ -570,7 +570,7 @@ namespace {
Depth extension, newDepth;
Value bestValue, value, ttValue, eval, maxValue, pureStaticEval;
bool ttHit, ttPv, inCheck, givesCheck, improving;
bool captureOrPromotion, doFullDepthSearch, moveCountPruning, skipQuiets, ttCapture;
bool captureOrPromotion, doFullDepthSearch, moveCountPruning, ttCapture;
Piece movedPiece;
int moveCount, captureCount, quietCount;

Expand Down Expand Up @@ -880,12 +880,12 @@ namespace {
ss->killers);
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc

skipQuiets = false;
moveCountPruning = false;
ttCapture = ttMove && pos.capture_or_promotion(ttMove);

// Step 12. Loop through all pseudo-legal moves until no moves remain
// or a beta cutoff occurs.
while ((move = mp.next_move(skipQuiets)) != MOVE_NONE)
while ((move = mp.next_move(moveCountPruning)) != MOVE_NONE)
{
assert(is_ok(move));

Expand Down Expand Up @@ -914,8 +914,9 @@ namespace {
movedPiece = pos.moved_piece(move);
givesCheck = gives_check(pos, move);

moveCountPruning = depth < 16 * ONE_PLY
&& moveCount >= FutilityMoveCounts[improving][depth / ONE_PLY];
// Skip quiet moves if movecount exceeds our FutilityMoveCount threshold
moveCountPruning = depth < 16 * ONE_PLY
&& moveCount >= FutilityMoveCounts[improving][depth / ONE_PLY];

// Step 13. Extensions (~70 Elo)

Expand Down Expand Up @@ -973,10 +974,7 @@ namespace {
{
// Move count based pruning (~30 Elo)
if (moveCountPruning)
{
skipQuiets = true;
continue;
}

// Reduced depth of the next LMR search
int lmrDepth = std::max(newDepth - reduction<PvNode>(improving, depth, moveCount), DEPTH_ZERO) / ONE_PLY;
Expand Down

3 comments on commit 76d2f5b

@joergoster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snicolet @mcostalba @protonspring There is a really nasty side effect of this patch.
Take a look at bench position 38 (default bench):

Position: 38/42
info depth 1 seldepth 1 multipv 1 score cp -343 nodes 11 nps 11000 tbhits 0 time 1 pv a5b4 a3b4
info depth 2 seldepth 2 multipv 1 score cp 964 nodes 44 nps 44000 tbhits 0 time 1 pv h4f4 f1g1 f4e3 g1f1 e3a3
info depth 3 seldepth 4 multipv 1 score cp 883 nodes 87 nps 87000 tbhits 0 time 1 pv h4f4 e2f3 f4e3
info depth 4 seldepth 4 multipv 1 score mate 3 nodes 302 nps 302000 tbhits 0 time 1 pv h4f4 e2f3 f4e3 b4c5 h7h1
info depth 5 seldepth 6 multipv 1 score mate 3 nodes 425 nps 425000 tbhits 0 time 1 pv h4f4 e2f3 f4e3 b4c5 h7h1
info depth 6 seldepth 8 multipv 1 score mate 4 nodes 669 nps 669000 tbhits 0 time 1 pv h4f4 d4f3 f4e3 e2d3 h7h1 f3g1 h1g1
info depth 7 seldepth 8 multipv 1 score mate 4 nodes 1040 nps 520000 tbhits 0 time 2 pv h4f4 e2f3 f4e3 f3h5 h7h5 b4c5
info depth 8 seldepth 8 multipv 1 score mate 4 nodes 1250 nps 625000 tbhits 0 time 2 pv h4f4 e2f3 f4e3 f3h5 h7h5 b4c5 h5h1
info depth 9 seldepth 8 multipv 1 score mate 4 nodes 1479 nps 739500 tbhits 0 time 2 pv h4f4 e2f3 f4e3 f3h5 h7h5 b4c5 h5h1
info depth 10 seldepth 12 multipv 1 score mate 5 nodes 2108 nps 1054000 tbhits 0 time 2 pv h4f4 e2f3 f4e3 f3h5 h7h5 d4f3 h5h1 f3g1 h1g1
info depth 11 seldepth 10 multipv 1 score mate 5 nodes 2724 nps 908000 tbhits 0 time 3 pv h4f4 e2f3 f4e3 f3h5 h7h5 d4f3 h5h1 f3g1 h1g1
info depth 12 seldepth 10 multipv 1 score mate 5 nodes 3654 nps 1218000 tbhits 0 time 3 pv h4f4 e2f3 f4e3 f3h5 h7h5 d4f3 h5h1 f3g1 h1g1
info depth 13 seldepth 10 multipv 1 score mate 5 nodes 4638 nps 1159500 tbhits 0 time 4 pv h4f4 e2f3 f4e3 f3h5 h7h5 d4f3 h5h1 f3g1 h1g1
bestmove h4f4 ponder e2f3

It starts with a mate in 3 at depth 4, then mate in 4, and finally with the correct mate in 5. This is really weird!

Finding a longer mate and then subsequently settle down to the shortest mate, makes sense. But the other way round like this? Do we really want this?

@MichaelB7
Copy link
Contributor

@MichaelB7 MichaelB7 commented on 76d2f5b Feb 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clearly a new bug which was introduced with this "simplification". Engines should not report an incorrect "shorter" mate that is shorter than the actual shortest mate line. There was no Elo gain with this patch, it was possibly regressive and it introduces a very undesirable artifact which should not be tolerated. (Just my $.02, other may feel differently) .

Seems to be more prevalent with shorter mates I found two more quite easily ( out of 20 or so mates).

This mate-in-4 is reported as mate-in-3 initially.

3q1rk1/4bp1p/1n2P2Q/3p1p2/6r1/Pp2R2N/1B4PP/7K w - -; wac 283

info depth 1 seldepth 2 multipv 1 score cp -575 nodes 23 nps 11500 tbhits 0 time 2 pv e3b3
info depth 2 seldepth 2 multipv 1 score cp -302 nodes 61 nps 30500 tbhits 0 time 2 pv e3b3 d8d6 e6f7 f8f7 b3b6 d6h6 b6h6
info depth 3 seldepth 4 multipv 1 score cp -429 nodes 101 nps 50500 tbhits 0 time 2 pv e3b3 f7f6 h3f4
info depth 4 seldepth 4 multipv 1 score cp -416 nodes 137 nps 68500 tbhits 0 time 2 pv e3b3 f7f6 h3f4 d8c7
info depth 5 seldepth 6 multipv 1 score cp -766 nodes 1531 nps 510333 tbhits 0 time 3 pv h3f4 e7g5 e6e7 g5h6 e7d8q f8d8
info depth 6 seldepth 7 multipv 1 score cp -596 nodes 1782 nps 594000 tbhits 0 time 3 pv e3b3 g4g6
info depth 7 seldepth 8 multipv 1 score cp -751 nodes 3317 nps 829250 tbhits 0 time 4 pv e3b3 b6c4 h3f4 c4b2 b3b2 e7g5 e6f7 f8f7
info depth 8 seldepth 9 multipv 1 score cp -675 nodes 5235 nps 1047000 tbhits 0 time 5 pv h3f4 d8c7 e6f7 f8f7 f4e6
info depth 9 seldepth 10 multipv 1 score cp -584 nodes 7932 nps 1133142 tbhits 0 time 7 pv h3f4 d8c7 e6f7 f8f7 f4e6 c7a7
info depth 10 seldepth 15 multipv 1 score cp -647 nodes 21272 nps 1519428 tbhits 0 time 14 pv h3f4 d5d4 e3b3 b6c4 b3h3 g4g7 e6f7 f8f7 f4e6 d8d5 e6f4 d5b5 b2d4
info depth 11 seldepth 18 multipv 1 score cp -750 nodes 90587 nps 1811740 tbhits 0 time 50 pv e6f7 f8f7 e3b3 b6c4 h6c1 e7d6 h3f2 g4g6 c1c2 c4b2 c2b2 d8f6 b2f6
info depth 12 seldepth 19 multipv 1 score cp -742 nodes 128977 nps 1816577 tbhits 0 time 71 pv h3g1 g4g6 e6f7 f8f7 h6h3 f5f4 e3b3 b6c4 b2c1 e7f8 g1f3 d5d4 h3h4
info depth 13 seldepth 19 multipv 1 score cp -747 nodes 241259 nps 1827719 tbhits 0 time 132 pv e3b3 b6c4 h3g1 g4g6 e6f7 f8f7 h6c1 e7c5 a3a4 f7e7 c1c3 e7g7 g2g3 c4b2 c3c5
info depth 14 seldepth 23 multipv 1 score cp -740 nodes 290952 nps 1865076 tbhits 0 time 156 pv e3b3 b6c4 h3g1 c4b2 b3b2 d8a8 e6f7 f8f7 h6h3 a8a3 b2b8 g8g7 h3a3 e7a3 b8b5 a3b4 b5d5
info depth 15 seldepth 24 multipv 1 score cp -589 nodes 450442 nps 1908652 tbhits 0 time 236 pv e3b3 g4g6 e6f7 f8f7 h6e3 b6c4 e3f2 e7d6 h3f4 d6f4 f2f4
info depth 16 seldepth 24 multipv 1 score cp -658 nodes 718325 nps 1880431 tbhits 0 time 382 pv e3b3 g4g6 e6f7 f8f7 h6f4 e7f6 b2f6 d8f6 f4f1 g6g4 g2g3 b6c4 h3f4 f6e5 b3b5 c4e3 f1d3 e5e4 d3e4 f5e4 b5b3
info depth 17 seldepth 29 multipv 1 score cp -648 nodes 794747 nps 1883286 tbhits 0 time 422 pv e3b3 g4g6 e6f7 f8f7 h6f4 e7f6 b2f6 d8f6 f4f1 g6g4 g2g3 g4e4 f1f2 b6c4 h3f4 f7f8 b3b1 c4a3 b1f1 f6e5
info depth 18 seldepth 30 multipv 1 score cp -585 nodes 1326515 nps 1889622 tbhits 0 time 702 pv e3b3 g4g6 h6f4 g6e6 b3g3 e6g6 f4e5 f7f6 e5f5 g6g3 h2g3 d8d7 f5d7 b6d7 h3f4 d5d4 b2d4 e7a3 f4d5
info depth 19 seldepth 25 multipv 1 score mate 3 nodes 1356948 nps 1895178 tbhits 0 time 716 pv h3g5 g4g5 e3h3 f7e6 h6h7
info depth 20 seldepth 8 multipv 1 score mate 4 nodes 1359976 nps 1896758 tbhits 0 time 717 pv h3g5 g4g5 e3h3 f8e8 h6h7 g8f8 h7f7

This mate-in-5 is reported as a mate in 4 initially:
r4rk1/4Rppp/p1P5/1p6/3P1n2/1BP2b2/PP3PpP/RN4K1 w - -

info depth 1 seldepth 1 multipv 1 score cp -406 nodes 25 nps 25000 tbhits 0 time 1 pv b3f7 f8f7
info depth 2 seldepth 2 multipv 1 score cp -406 nodes 37 nps 37000 tbhits 0 time 1 pv b3f7 f8f7
info depth 3 seldepth 3 multipv 1 score cp -925 nodes 74 nps 74000 tbhits 0 time 1 pv b3f7 f8f7 e7e8 a8e8
info depth 4 seldepth 4 multipv 1 score cp -925 nodes 107 nps 107000 tbhits 0 time 1 pv b3f7 f8f7 e7e8 a8e8
info depth 5 seldepth 8 multipv 1 score mate -4 nodes 629 nps 314500 tbhits 0 time 2 pv h2h3 f4h3 g1h2 g2g1q h2h3 g1g2 h3h4 g7g5
info depth 6 seldepth 9 multipv 1 score mate -4 nodes 706 nps 353000 tbhits 0 time 2 pv h2h3 f4h3 g1h2 g2g1q h2h3 g1g2 h3h4 g7g5
info depth 7 seldepth 9 multipv 1 score mate -4 nodes 790 nps 395000 tbhits 0 time 2 pv h2h3 f4h3 g1h2 g2g1q h2h3 g1g2 h3h4 g7g5
info depth 8 seldepth 9 multipv 1 score cp -1774 nodes 1293 nps 646500 tbhits 0 time 2 pv b3f7 f8f7 h2h3 f4h3 g1h2 g2g1q h2h3 f7e7
info depth 9 seldepth 15 multipv 1 score mate -5 nodes 2780 nps 926666 tbhits 0 time 3 pv b3f7 f8f7 h2h3 f4h3 g1h2 g2g1q h2h3 g1g2 h3h4 g2g4
info depth 10 seldepth 11 multipv 1 score mate -5 nodes 2991 nps 997000 tbhits 0 time 3 pv b3f7 f8f7 h2h3 f4h3 g1h2 g2g1q h2h3 g1g2 h3h4 g2g4

@mcostalba
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have opened an issue #2019, please follow on there.

Please sign in to comment.