Skip to content

Commit 72760c0

Browse files
committed
Try only recaptures in qsearch if depth is very low
This avoids search explosion in qsearch for some patological cases like: r1n1n1b1/1P1P1P1P/1N1N1N2/2RnQrRq/2pKp3/3BNQbQ/k7/4Bq2 w - - 0 1 After 9078 games 20"+0.1 QUAD: Mod vs Orig 1413 - 1319 - 6346 ELO +3 (+- 4) Signed-off-by: Marco Costalba <mcostalba@gmail.com>
1 parent 1568303 commit 72760c0

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

src/movepick.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace {
3737
PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < captureThreshold (captureThreshold <= 0)
3838
PH_EVASIONS, // Check evasions
3939
PH_QCAPTURES, // Captures in quiescence search
40+
PH_QRECAPTURES, // Recaptures in quiescence search
4041
PH_QCHECKS, // Non-capture checks in quiescence search
4142
PH_STOP
4243
};
@@ -46,6 +47,7 @@ namespace {
4647
const uint8_t EvasionTable[] = { PH_TT_MOVE, PH_EVASIONS, PH_STOP };
4748
const uint8_t QsearchWithChecksTable[] = { PH_TT_MOVE, PH_QCAPTURES, PH_QCHECKS, PH_STOP };
4849
const uint8_t QsearchWithoutChecksTable[] = { PH_TT_MOVE, PH_QCAPTURES, PH_STOP };
50+
const uint8_t QsearchRecapturesTable[] = { PH_TT_MOVE, PH_QRECAPTURES, PH_STOP };
4951
const uint8_t ProbCutTable[] = { PH_TT_MOVE, PH_GOOD_PROBCUT, PH_STOP };
5052
}
5153

@@ -85,7 +87,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
8587
go_next_phase();
8688
}
8789

88-
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h)
90+
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, Square recaptureSq)
8991
: pos(p), H(h) {
9092

9193
assert(d <= DEPTH_ZERO);
@@ -94,7 +96,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h)
9496
phasePtr = EvasionTable;
9597
else if (d >= DEPTH_QS_CHECKS)
9698
phasePtr = QsearchWithChecksTable;
97-
else
99+
else if (d >= DEPTH_QS_RECAPTURES)
98100
{
99101
phasePtr = QsearchWithoutChecksTable;
100102

@@ -104,6 +106,12 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h)
104106
if (ttm != MOVE_NONE && !pos.move_is_capture(ttm) && !move_is_promotion(ttm))
105107
ttm = MOVE_NONE;
106108
}
109+
else
110+
{
111+
phasePtr = QsearchRecapturesTable;
112+
recaptureSquare = recaptureSq;
113+
ttm = MOVE_NONE;
114+
}
107115

108116
ttMove = (ttm && pos.move_is_pl(ttm) ? ttm : MOVE_NONE);
109117
phasePtr += int(ttMove == MOVE_NONE) - 1;
@@ -184,6 +192,10 @@ void MovePicker::go_next_phase() {
184192
score_captures();
185193
return;
186194

195+
case PH_QRECAPTURES:
196+
lastMove = generate<MV_CAPTURE>(pos, moves);
197+
return;
198+
187199
case PH_QCHECKS:
188200
lastMove = generate<MV_NON_CAPTURE_CHECK>(pos, moves);
189201
return;
@@ -347,6 +359,12 @@ Move MovePicker::get_next_move() {
347359
return move;
348360
break;
349361

362+
case PH_QRECAPTURES:
363+
move = (curMove++)->move;
364+
if (move_to(move) == recaptureSquare)
365+
return move;
366+
break;
367+
350368
case PH_QCHECKS:
351369
move = (curMove++)->move;
352370
if (move != ttMove)

src/movepick.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MovePicker {
4141

4242
public:
4343
MovePicker(const Position&, Move, Depth, const History&, SearchStack*, Value);
44-
MovePicker(const Position&, Move, Depth, const History&);
44+
MovePicker(const Position&, Move, Depth, const History&, Square recaptureSq);
4545
MovePicker(const Position&, Move, const History&, int parentCapture);
4646
Move get_next_move();
4747

@@ -56,6 +56,7 @@ class MovePicker {
5656
Depth depth;
5757
Move ttMove;
5858
MoveStack killers[2];
59+
Square recaptureSquare;
5960
int captureThreshold, phase;
6061
const uint8_t* phasePtr;
6162
MoveStack *curMove, *lastMove, *lastNonCapture, *badCaptures;

src/search.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ namespace {
13931393
// to search the moves. Because the depth is <= 0 here, only captures,
13941394
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
13951395
// be generated.
1396-
MovePicker mp(pos, ttMove, depth, H);
1396+
MovePicker mp(pos, ttMove, depth, H, move_to((ss-1)->currentMove));
13971397
CheckInfo ci(pos);
13981398
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
13991399

src/types.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,10 @@ enum Depth {
201201

202202
ONE_PLY = 2,
203203

204-
DEPTH_ZERO = 0 * ONE_PLY,
205-
DEPTH_QS_CHECKS = -1 * ONE_PLY,
206-
DEPTH_QS_NO_CHECKS = -2 * ONE_PLY,
204+
DEPTH_ZERO = 0 * ONE_PLY,
205+
DEPTH_QS_CHECKS = -1 * ONE_PLY,
206+
DEPTH_QS_NO_CHECKS = -2 * ONE_PLY,
207+
DEPTH_QS_RECAPTURES = -4 * ONE_PLY,
207208

208209
DEPTH_NONE = -127 * ONE_PLY
209210
};

0 commit comments

Comments
 (0)