1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 00:33:09 +00:00

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>
This commit is contained in:
Marco Costalba 2011-06-12 07:25:51 +01:00
parent 15683034a7
commit 72760c05c6
4 changed files with 27 additions and 7 deletions

View file

@ -37,6 +37,7 @@ namespace {
PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < captureThreshold (captureThreshold <= 0) PH_BAD_CAPTURES, // Queen promotions and captures with SEE values < captureThreshold (captureThreshold <= 0)
PH_EVASIONS, // Check evasions PH_EVASIONS, // Check evasions
PH_QCAPTURES, // Captures in quiescence search PH_QCAPTURES, // Captures in quiescence search
PH_QRECAPTURES, // Recaptures in quiescence search
PH_QCHECKS, // Non-capture checks in quiescence search PH_QCHECKS, // Non-capture checks in quiescence search
PH_STOP PH_STOP
}; };
@ -46,6 +47,7 @@ namespace {
const uint8_t EvasionTable[] = { PH_TT_MOVE, PH_EVASIONS, PH_STOP }; const uint8_t EvasionTable[] = { PH_TT_MOVE, PH_EVASIONS, PH_STOP };
const uint8_t QsearchWithChecksTable[] = { PH_TT_MOVE, PH_QCAPTURES, PH_QCHECKS, PH_STOP }; const uint8_t QsearchWithChecksTable[] = { PH_TT_MOVE, PH_QCAPTURES, PH_QCHECKS, PH_STOP };
const uint8_t QsearchWithoutChecksTable[] = { PH_TT_MOVE, PH_QCAPTURES, PH_STOP }; const uint8_t QsearchWithoutChecksTable[] = { PH_TT_MOVE, PH_QCAPTURES, PH_STOP };
const uint8_t QsearchRecapturesTable[] = { PH_TT_MOVE, PH_QRECAPTURES, PH_STOP };
const uint8_t ProbCutTable[] = { PH_TT_MOVE, PH_GOOD_PROBCUT, PH_STOP }; const uint8_t ProbCutTable[] = { PH_TT_MOVE, PH_GOOD_PROBCUT, PH_STOP };
} }
@ -85,7 +87,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h,
go_next_phase(); go_next_phase();
} }
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h) MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, Square recaptureSq)
: pos(p), H(h) { : pos(p), H(h) {
assert(d <= DEPTH_ZERO); assert(d <= DEPTH_ZERO);
@ -94,7 +96,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h)
phasePtr = EvasionTable; phasePtr = EvasionTable;
else if (d >= DEPTH_QS_CHECKS) else if (d >= DEPTH_QS_CHECKS)
phasePtr = QsearchWithChecksTable; phasePtr = QsearchWithChecksTable;
else else if (d >= DEPTH_QS_RECAPTURES)
{ {
phasePtr = QsearchWithoutChecksTable; phasePtr = QsearchWithoutChecksTable;
@ -104,6 +106,12 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h)
if (ttm != MOVE_NONE && !pos.move_is_capture(ttm) && !move_is_promotion(ttm)) if (ttm != MOVE_NONE && !pos.move_is_capture(ttm) && !move_is_promotion(ttm))
ttm = MOVE_NONE; ttm = MOVE_NONE;
} }
else
{
phasePtr = QsearchRecapturesTable;
recaptureSquare = recaptureSq;
ttm = MOVE_NONE;
}
ttMove = (ttm && pos.move_is_pl(ttm) ? ttm : MOVE_NONE); ttMove = (ttm && pos.move_is_pl(ttm) ? ttm : MOVE_NONE);
phasePtr += int(ttMove == MOVE_NONE) - 1; phasePtr += int(ttMove == MOVE_NONE) - 1;
@ -184,6 +192,10 @@ void MovePicker::go_next_phase() {
score_captures(); score_captures();
return; return;
case PH_QRECAPTURES:
lastMove = generate<MV_CAPTURE>(pos, moves);
return;
case PH_QCHECKS: case PH_QCHECKS:
lastMove = generate<MV_NON_CAPTURE_CHECK>(pos, moves); lastMove = generate<MV_NON_CAPTURE_CHECK>(pos, moves);
return; return;
@ -347,6 +359,12 @@ Move MovePicker::get_next_move() {
return move; return move;
break; break;
case PH_QRECAPTURES:
move = (curMove++)->move;
if (move_to(move) == recaptureSquare)
return move;
break;
case PH_QCHECKS: case PH_QCHECKS:
move = (curMove++)->move; move = (curMove++)->move;
if (move != ttMove) if (move != ttMove)

View file

@ -41,7 +41,7 @@ class MovePicker {
public: public:
MovePicker(const Position&, Move, Depth, const History&, SearchStack*, Value); MovePicker(const Position&, Move, Depth, const History&, SearchStack*, Value);
MovePicker(const Position&, Move, Depth, const History&); MovePicker(const Position&, Move, Depth, const History&, Square recaptureSq);
MovePicker(const Position&, Move, const History&, int parentCapture); MovePicker(const Position&, Move, const History&, int parentCapture);
Move get_next_move(); Move get_next_move();
@ -56,6 +56,7 @@ private:
Depth depth; Depth depth;
Move ttMove; Move ttMove;
MoveStack killers[2]; MoveStack killers[2];
Square recaptureSquare;
int captureThreshold, phase; int captureThreshold, phase;
const uint8_t* phasePtr; const uint8_t* phasePtr;
MoveStack *curMove, *lastMove, *lastNonCapture, *badCaptures; MoveStack *curMove, *lastMove, *lastNonCapture, *badCaptures;

View file

@ -1393,7 +1393,7 @@ split_point_start: // At split points actual search starts from here
// to search the moves. Because the depth is <= 0 here, only captures, // to search the moves. Because the depth is <= 0 here, only captures,
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will // queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
// be generated. // be generated.
MovePicker mp(pos, ttMove, depth, H); MovePicker mp(pos, ttMove, depth, H, move_to((ss-1)->currentMove));
CheckInfo ci(pos); CheckInfo ci(pos);
Bitboard pinned = pos.pinned_pieces(pos.side_to_move()); Bitboard pinned = pos.pinned_pieces(pos.side_to_move());

View file

@ -204,6 +204,7 @@ enum Depth {
DEPTH_ZERO = 0 * ONE_PLY, DEPTH_ZERO = 0 * ONE_PLY,
DEPTH_QS_CHECKS = -1 * ONE_PLY, DEPTH_QS_CHECKS = -1 * ONE_PLY,
DEPTH_QS_NO_CHECKS = -2 * ONE_PLY, DEPTH_QS_NO_CHECKS = -2 * ONE_PLY,
DEPTH_QS_RECAPTURES = -4 * ONE_PLY,
DEPTH_NONE = -127 * ONE_PLY DEPTH_NONE = -127 * ONE_PLY
}; };