DroidFish: Improve mate finding in endgames.

Include the early_mate code from
https://github.com/syzygy1/Stockfish/tree/early_mate
This commit is contained in:
Peter Osterlund 2017-09-11 23:03:59 +02:00
parent 4b6418cb02
commit 2570cd2871

View File

@ -541,7 +541,7 @@ namespace {
Key posKey;
Move ttMove, move, excludedMove, bestMove;
Depth extension, newDepth;
Value bestValue, value, ttValue, eval;
Value bestValue, value, ttValue, eval, maxValue;
bool ttHit, inCheck, givesCheck, singularExtensionNode, improving;
bool captureOrPromotion, doFullDepthSearch, moveCountPruning, skipQuiets, ttCapture;
Piece movedPiece;
@ -553,6 +553,7 @@ namespace {
moveCount = quietCount = ss->moveCount = 0;
ss->statScore = 0;
bestValue = -VALUE_INFINITE;
maxValue = VALUE_INFINITE;
ss->ply = (ss-1)->ply + 1;
// Check for the available remaining time
@ -641,7 +642,7 @@ namespace {
&& !pos.can_castle(ANY_CASTLING))
{
TB::ProbeState err;
TB::WDLScore v = Tablebases::probe_wdl(pos, &err);
TB::WDLScore wdl = Tablebases::probe_wdl(pos, &err);
if (err != TB::ProbeState::FAIL)
{
@ -649,16 +650,31 @@ namespace {
int drawScore = TB::UseRule50 ? 1 : 0;
value = v < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply
: v > drawScore ? VALUE_MATE - MAX_PLY - ss->ply
: VALUE_DRAW + 2 * v * drawScore;
value = wdl < -drawScore ? -VALUE_MATE + MAX_PLY + ss->ply
: wdl > drawScore ? VALUE_MATE - MAX_PLY - ss->ply
: VALUE_DRAW + 2 * wdl * drawScore;
tte->save(posKey, value_to_tt(value, ss->ply), BOUND_EXACT,
Bound b = wdl < -drawScore ? BOUND_UPPER
: wdl > drawScore ? BOUND_LOWER : BOUND_EXACT;
if ( b == BOUND_EXACT
|| (b == BOUND_LOWER ? value >= beta : value <= alpha))
{
tte->save(posKey, value_to_tt(value, ss->ply), b,
std::min(DEPTH_MAX - ONE_PLY, depth + 6 * ONE_PLY),
MOVE_NONE, VALUE_NONE, TT.generation());
return value;
}
if (PvNode)
{
if (b == BOUND_LOWER)
bestValue = value, alpha = std::max(alpha, bestValue);
else
maxValue = value;
}
}
}
}
@ -1120,6 +1136,9 @@ moves_loop: // When in check search starts from here
&& is_ok((ss-1)->currentMove))
update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, stat_bonus(depth));
if (PvNode)
bestValue = std::min(bestValue, maxValue);
if (!excludedMove)
tte->save(posKey, value_to_tt(bestValue, ss->ply),
bestValue >= beta ? BOUND_LOWER :
@ -1616,4 +1635,9 @@ void Tablebases::filter_root_moves(Position& pos, Search::RootMoves& rootMoves)
TB::Score = TB::Score > VALUE_DRAW ? VALUE_MATE - MAX_PLY - 1
: TB::Score < VALUE_DRAW ? -VALUE_MATE + MAX_PLY + 1
: VALUE_DRAW;
// Since root_probe() and root_probe_wdl() dirty the root move scores,
// we reset them to -VALUE_INFINITE
for (RootMove& rm : rootMoves)
rm.score = -VALUE_INFINITE;
}