Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
peregrineshahin committed Feb 2, 2024
1 parent fcbb02f commit 32a655e
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct Skill {

Value value_to_tt(Value v, int ply);
Value value_from_tt(Value v, int ply, int r50c);
bool possibleFortress(Stack* ss);
void update_pv(Move* pv, Move move, const Move* childPv);
void update_continuation_histories(Stack* ss, Piece pc, Square to, int bonus);
void update_quiet_stats(
Expand Down Expand Up @@ -1184,7 +1185,14 @@ Value Search::Worker::search(
newDepth += doDeeperSearch - doShallowerSearch;

if (newDepth > d)
{
if (possibleFortress(ss))
{
newDepth = 2 * newDepth / 3;
assert(newDepth >= 1);
}
value = -search<NonPV>(pos, ss + 1, -(alpha + 1), -alpha, newDepth, !cutNode);
}

// Post LMR continuation history updates (~1 Elo)
int bonus = value <= alpha ? -stat_malus(newDepth)
Expand All @@ -1202,8 +1210,12 @@ Value Search::Worker::search(
if (!ttMove)
r += 2;

if (newDepth > 1 && possibleFortress(ss))
newDepth = 2 * newDepth / 3;

// Note that if expected reduction is high, we reduce search depth by 1 here (~9 Elo)
value = -search<NonPV>(pos, ss + 1, -(alpha + 1), -alpha, newDepth - (r > 3), !cutNode);
value = -search<NonPV>(pos, ss + 1, -(alpha + 1), -alpha,
newDepth - (r > 3 && !possibleFortress(ss)), !cutNode);
}

// For PV nodes only, do a full PV search on the first move or after a fail high,
Expand Down Expand Up @@ -1373,7 +1385,6 @@ Value Search::Worker::search(
return bestValue;
}


// Quiescence search function, which is called by the main search
// function with zero depth, or recursively with further decreasing depth per call.
// (~155 Elo)
Expand Down Expand Up @@ -1812,6 +1823,24 @@ void update_quiet_stats(
}
}

// Detects a possible fortress by checking weither any player can keep repeating moves
// this fixes a fortress search explosion in case staticEval of the fortress is way off
bool possibleFortress(Stack* ss) {
const bool fortressUs =
(ss - 4)->currentMove.is_ok()
&& (ss - 6)->currentMove
== Move((ss - 4)->currentMove.to_sq(), (ss - 4)->currentMove.from_sq())
&& (ss - 6)->currentMove == (ss - 2)->currentMove;

const bool fortressThem =
(ss - 5)->currentMove.is_ok()
&& (ss - 7)->currentMove
== Move((ss - 5)->currentMove.to_sq(), (ss - 5)->currentMove.from_sq())
&& (ss - 7)->currentMove == (ss - 3)->currentMove;

return fortressUs || fortressThem;
}

// When playing with strength handicap, choose the best move among a set of RootMoves
// using a statistical rule dependent on 'level'. Idea by Heinz van Saanen.
Move Skill::pick_best(const RootMoves& rootMoves, size_t multiPV) {
Expand Down

0 comments on commit 32a655e

Please sign in to comment.