bool UseQSearchFutilityPruning = true;
bool UseFutilityPruning = true;
- // Margins for futility pruning in the quiescence search, at frontier
- // nodes, and at pre-frontier nodes
- Value FutilityMargin0 = Value(0x80);
- Value FutilityMargin1 = Value(0x100);
- Value FutilityMargin2 = Value(0x200);
+ // Margins for futility pruning in the quiescence search, and at frontier
+ // and near frontier nodes
+ Value FutilityMarginQS = Value(0x80);
+ Value FutilityMargins[6] = { Value(0x100), Value(0x200), Value(0x250),
+ Value(0x2A0), Value(0x340), Value(0x3A0) };
// Razoring
+ const bool RazorAtDepthOne = false;
Depth RazorDepth = 4*OnePly;
Value RazorMargin = Value(0x300);
bool connected_moves(const Position &pos, Move m1, Move m2);
bool value_is_mate(Value value);
bool move_is_killer(Move m, const SearchStack& ss);
- Depth extension(const Position &pos, Move m, bool pvNode, bool check, bool singleReply, bool mateThreat, bool* dangerous);
+ Depth extension(const Position &pos, Move m, bool pvNode, bool capture, bool check, bool singleReply, bool mateThreat, bool* dangerous);
bool ok_to_do_nullmove(const Position &pos);
bool ok_to_prune(const Position &pos, Move m, Move threat, Depth d);
bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply);
UseQSearchFutilityPruning = get_option_value_bool("Futility Pruning (Quiescence Search)");
UseFutilityPruning = get_option_value_bool("Futility Pruning (Main Search)");
- FutilityMargin0 = value_from_centipawns(get_option_value_int("Futility Margin 0"));
- FutilityMargin1 = value_from_centipawns(get_option_value_int("Futility Margin 1"));
- FutilityMargin2 = value_from_centipawns(get_option_value_int("Futility Margin 2"));
+ FutilityMarginQS = value_from_centipawns(get_option_value_int("Futility Margin (Quiescence Search)"));
+ int fmScale = get_option_value_int("Futility Margin Scale Factor (Main Search)");
+ for (int i = 0; i < 6; i++)
+ FutilityMargins[i] = (FutilityMargins[i] * fmScale) / 100;
RazorDepth = (get_option_value_int("Maximum Razoring Depth") + 1) * OnePly;
RazorMargin = value_from_centipawns(get_option_value_int("Razoring Margin"));
// Set thinking time:
int myTime = time[side_to_move];
int myIncrement = increment[side_to_move];
- int oppTime = time[1 - side_to_move];
if (!movesToGo) // Sudden death time control
{
// Decide search depth for this move
bool dangerous;
- ext = extension(pos, move, true, pos.move_is_check(move), false, false, &dangerous);
+ ext = extension(pos, move, true, pos.move_is_capture(move), pos.move_is_check(move), false, false, &dangerous);
newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
// Make the move, and search it
assert(move_is_ok(move));
bool singleReply = (isCheck && mp.number_of_moves() == 1);
- bool moveIsCheck = pos.move_is_check(move, dcCandidates);
+ bool moveIsCheck = pos.move_is_check(move);
bool moveIsCapture = pos.move_is_capture(move);
movesSearched[moveCount++] = ss[ply].currentMove = move;
// Decide the new search depth
bool dangerous;
- Depth ext = extension(pos, move, true, moveIsCheck, singleReply, mateThreat, &dangerous);
+ Depth ext = extension(pos, move, true, moveIsCapture, moveIsCheck, singleReply, mateThreat, &dangerous);
Depth newDepth = depth - OnePly + ext;
// Make and search the move
else
value = alpha + 1; // Just to trigger next condition
- if (value > alpha) // Go with full depth pv search
+ if (value > alpha) // Go with full depth non-pv search
{
ss[ply].reduction = Depth(0);
value = -search(pos, ss, -alpha, newDepth, ply+1, true, threadID);
// Null move search not allowed, try razoring
else if ( !value_is_mate(beta)
&& approximateEval < beta - RazorMargin
- && depth < RazorDepth)
+ && depth < RazorDepth
+ && (RazorAtDepthOne || depth > OnePly)
+ && ttMove == MOVE_NONE
+ && !pos.has_pawn_on_7th(pos.side_to_move()))
{
Value v = qsearch(pos, ss, beta-1, beta, Depth(0), ply, threadID);
- if (v < beta - RazorMargin / 2)
+ if ( (v < beta - RazorMargin - RazorMargin / 4)
+ || (depth < 3*OnePly && v < beta - RazorMargin)
+ || (depth < 2*OnePly && v < beta - RazorMargin / 2))
return v;
}
assert(move_is_ok(move));
bool singleReply = (isCheck && mp.number_of_moves() == 1);
- bool moveIsCheck = pos.move_is_check(move, dcCandidates);
+ bool moveIsCheck = pos.move_is_check(move);
bool moveIsCapture = pos.move_is_capture(move);
movesSearched[moveCount++] = ss[ply].currentMove = move;
// Decide the new search depth
bool dangerous;
- Depth ext = extension(pos, move, false, moveIsCheck, singleReply, mateThreat, &dangerous);
+ Depth ext = extension(pos, move, false, moveIsCapture, moveIsCheck, singleReply, mateThreat, &dangerous);
Depth newDepth = depth - OnePly + ext;
// Futility pruning
continue;
// Value based pruning
- if (depth < 6 * OnePly && approximateEval < beta)
+ if (depth < 7 * OnePly && approximateEval < beta)
{
if (futilityValue == VALUE_NONE)
futilityValue = evaluate(pos, ei, threadID)
- + (depth < 2 * OnePly ? FutilityMargin1
- : FutilityMargin2 + (depth - 2*OnePly) * 32);
+ + FutilityMargins[int(depth)/2 - 1]
+ + 32 * (depth & 1);
+
if (futilityValue < beta)
{
if (futilityValue > bestValue)
&& !isCheck
&& !pvNode
&& !move_promotion(move)
- && !pos.move_is_check(move, dcCandidates)
+ && !pos.move_is_check(move)
&& !pos.move_is_passed_pawn_push(move))
{
Value futilityValue = staticValue
+ Max(pos.midgame_value_of_piece_on(move_to(move)),
pos.endgame_value_of_piece_on(move_to(move)))
+ (move_is_ep(move) ? PawnValueEndgame : Value(0))
- + FutilityMargin0
+ + FutilityMarginQS
+ ei.futilityMargin;
if (futilityValue < alpha)
&& (move = sp->mp->get_next_move(sp->lock)) != MOVE_NONE)
{
assert(move_is_ok(move));
+ assert(pos.discovered_check_candidates(pos.side_to_move()) == sp->dcCandidates);
- bool moveIsCheck = pos.move_is_check(move, sp->dcCandidates);
+ bool moveIsCheck = pos.move_is_check(move);
bool moveIsCapture = pos.move_is_capture(move);
lock_grab(&(sp->lock));
// Decide the new search depth.
bool dangerous;
- Depth ext = extension(pos, move, false, moveIsCheck, false, false, &dangerous);
+ Depth ext = extension(pos, move, false, moveIsCapture, moveIsCheck, false, false, &dangerous);
Depth newDepth = sp->depth - OnePly + ext;
// Prune?
&& !thread_should_stop(threadID)
&& (move = sp->mp->get_next_move(sp->lock)) != MOVE_NONE)
{
- bool moveIsCheck = pos.move_is_check(move, sp->dcCandidates);
+ assert(pos.discovered_check_candidates(pos.side_to_move()) == sp->dcCandidates);
+
+ bool moveIsCheck = pos.move_is_check(move);
bool moveIsCapture = pos.move_is_capture(move);
assert(move_is_ok(move));
// Decide the new search depth.
bool dangerous;
- Depth ext = extension(pos, move, true, moveIsCheck, false, false, &dangerous);
+ Depth ext = extension(pos, move, true, moveIsCapture, moveIsCheck, false, false, &dangerous);
Depth newDepth = sp->depth - OnePly + ext;
// Make and search the move.
// Case 4: The destination square for m2 is attacked by the moving piece
// in m1:
- if(pos.piece_attacks_square(t1, t2))
+ if(pos.piece_attacks_square(pos.piece_on(t1), t1, t2))
return true;
// Case 5: Discovered check, checking piece is the piece moved in m1:
// extended, as example because the corresponding UCI option is set to zero,
// the move is marked as 'dangerous' so, at least, we avoid to prune it.
- Depth extension(const Position &pos, Move m, bool pvNode, bool check,
+ Depth extension(const Position& pos, Move m, bool pvNode, bool capture, bool check,
bool singleReply, bool mateThreat, bool* dangerous) {
assert(m != MOVE_NONE);
if (mateThreat)
result += MateThreatExtension[pvNode];
- if (pos.move_is_pawn_push_to_7th(m))
- {
- result += PawnPushTo7thExtension[pvNode];
- *dangerous = true;
- }
- if (pos.move_is_passed_pawn_push(m))
+ if (pos.type_of_piece_on(move_from(m)) == PAWN)
{
- result += PassedPawnExtension[pvNode];
- *dangerous = true;
+ if (pos.move_is_pawn_push_to_7th(m))
+ {
+ result += PawnPushTo7thExtension[pvNode];
+ *dangerous = true;
+ }
+ if (pos.move_is_passed_pawn_push(m))
+ {
+ result += PassedPawnExtension[pvNode];
+ *dangerous = true;
+ }
}
- if ( pos.move_is_capture(m)
+ if ( capture
&& pos.type_of_piece_on(move_to(m)) != PAWN
&& ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
- pos.midgame_value_of_piece_on(move_to(m)) == Value(0))
}
if ( pvNode
- && pos.move_is_capture(m)
+ && capture
&& pos.type_of_piece_on(move_to(m)) != PAWN
&& pos.see(m) >= 0)
{