From aa56d07ce2ca5947ddf0e2d3dd6532a294aeab4b Mon Sep 17 00:00:00 2001 From: Jonathan Rosenthal Date: Sat, 29 Jun 2024 10:24:54 -0400 Subject: [PATCH] Final output (#152) * Search end time is now computed before threads start. Furthermore, start time is computed by reversing the end time computation and will thus be identical between threads. The main thread will update the score estimate and PV one final time before returning if time has run out. * Version number update This quality of life patch ends the era of Winter v3.x and begins the era of Winter v4.x Elo | 1.55 +- 3.59 (95%) SPRT | 8.0+0.08s Threads=1 Hash=8MB LLR | 2.95 (-2.94, 2.94) [-5.00, 0.00] Games | N: 14358 W: 3418 L: 3354 D: 7586 Penta | [284, 1684, 3188, 1730, 293] http://chess.grantnet.us/test/37419/ Bench 478500 --- src/general/settings.h | 2 +- src/search.cc | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/general/settings.h b/src/general/settings.h index cd10d3c..fd32b5d 100644 --- a/src/general/settings.h +++ b/src/general/settings.h @@ -33,7 +33,7 @@ namespace settings { const std::string engine_name = "Winter"; -const std::string engine_version = "3.21"; +const std::string engine_version = "4.0"; const std::string engine_author = "Jonathan Rosenthal"; diff --git a/src/search.cc b/src/search.cc index d2efb68..1d3132e 100644 --- a/src/search.cc +++ b/src/search.cc @@ -770,7 +770,11 @@ Score AlphaBeta(Thread &t, Score alpha, const Score beta, Depth depth, Move excl inline Score PVS(Thread &t, Depth current_depth, const std::vector &previous_scores) { if (current_depth <= 4) { - return AlphaBeta(t, kMinScore, kMaxScore, current_depth); + Score score = AlphaBeta(t, kMinScore, kMaxScore, current_depth); + if (t.id == 0 && !finished(t)) { + last_search_score = score; + } + return score; } else { Score score = previous_scores.back(); @@ -778,6 +782,9 @@ inline Score PVS(Thread &t, Depth current_depth, const std::vector &previ Score alpha = (score-delta).get_valid_score(); Score beta = (score+delta).get_valid_score(); score = AlphaBeta(t, alpha, beta, current_depth); + if (t.id == 0 && !finished(t)) { + last_search_score = score; + } while (!finished(t) && (score <= alpha || score >= beta)) { assert(delta.win > 0 && delta.win_draw > 0); if (score <= alpha) { @@ -803,6 +810,9 @@ inline Score PVS(Thread &t, Depth current_depth, const std::vector &previ assert(score > alpha && score < beta); score = AlphaBeta(t, alpha, beta, current_depth); delta *= 2; + if (t.id == 0 && !finished(t)) { + last_search_score = score; + } } return score; } @@ -853,13 +863,10 @@ void PrintUCIInfoString(Thread &t, const Depth depth, const Time &begin, } void Thread::search() { - const Time begin = now(); + const Time begin = end_time-rsearch_duration; double time_factor = 1.0; current_depth = 1; root_height = board.get_num_made_moves(); - if (id == 0) { - end_time = begin+rsearch_duration; - } Score score = net_evaluation::ScoreBoard(board); set_static_score(score); @@ -893,16 +900,16 @@ void Thread::search() { current_depth = depth; score = PVS(*this, current_depth, previous_scores); - - if(!finished(*this)) { - last_search_score = score; - previous_scores.emplace_back(score); - if (id != 0) { - continue; + + previous_scores.emplace_back(score); + + if (id == 0) { + if (finished(*this)) { + current_depth--; } Time end = now(); - PrintUCIInfoString(*this, current_depth, begin, end, score, best_root_move); + PrintUCIInfoString(*this, current_depth, begin, end, last_search_score, best_root_move); auto time_used = std::chrono::duration_cast(end-begin); if (!fixed_search_time) { @@ -924,6 +931,9 @@ void Thread::search() { Move RootSearch(Board &board, Depth depth, Milliseconds duration = Milliseconds(24 * 60 * 60 * 1000)) { Threads.is_searching = true; + rsearch_depth = std::min(depth, settings::kMaxDepth); + rsearch_duration = duration; + end_time = now()+rsearch_duration; table::UpdateGeneration(); if (armageddon) { net_evaluation::SetContempt(kWhite, 60); @@ -936,8 +946,6 @@ Move RootSearch(Board &board, Depth depth, Milliseconds duration = Milliseconds( min_ply = board.get_num_made_moves(); Threads.reset_node_count(); Threads.reset_depths(); - rsearch_depth = std::min(depth, settings::kMaxDepth); - rsearch_duration = duration; std::vector moves = board.GetMoves(); assert(moves.size() != 0); if (moves.size() == 1 && !fixed_search_time) {