From 66a4008b0faf0742c41d8ae334b82dc93b141a88 Mon Sep 17 00:00:00 2001 From: dhb <1084714805@qq.com> Date: Mon, 14 Oct 2024 18:00:02 +0800 Subject: [PATCH] fix movegen and multi-threading bug Passed non-regressive tests: Book: f15-500M-12k TC: 60+0.6 Total/Win/Draw/Lose: 26146 / 4611 / 17013 / 4522 PTNML: 223 / 2205 / 8130 / 2290 / 225 WinRate: 50.17% ELO: 0.80[-1.85, 3.37] LOS: 72.63 LLR: 2.20[-2.20, 2.20] Book: s15-500M-16k TC: 60+0.6 Total/Win/Draw/Lose: 17288 / 2701 / 11935 / 2652 PTNML: 113 / 1390 / 5620 / 1377 / 144 WinRate: 50.14% ELO: 0.31[-3.25, 3.62] LOS: 57.12 LLR: 1.28[-1.10, 1.10] Book: r15-500M-16k TC: 60+0.6 Total/Win/Draw/Lose: 20572 / 5827 / 8940 / 5805 PTNML: 502 / 2068 / 5140 / 2058 / 518 WinRate: 50.05% ELO: -0.59[-5.24, 3.62] LOS: 39.25 LLR: 1.17[-1.10, 1.10] bench 454a4d48 bench (msvc clang) 37ddaa3a --- Rapfi/core/iohelper.cpp | 12 ++++++++++++ Rapfi/core/iohelper.h | 2 ++ Rapfi/game/movegen.cpp | 6 ++---- Rapfi/search/searchthread.cpp | 18 +++++++----------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Rapfi/core/iohelper.cpp b/Rapfi/core/iohelper.cpp index d51d67b..e477681 100644 --- a/Rapfi/core/iohelper.cpp +++ b/Rapfi/core/iohelper.cpp @@ -81,6 +81,18 @@ int outputCoordYConvert(Pos pos, int boardsize) return pos.y(); } +Pos parseCoord(std::string coordStr) +{ + if (coordStr == "Pass" || coordStr == "pass") + return Pos::PASS; + if (coordStr == "None" || coordStr == "none") + return Pos::NONE; + + int x = std::toupper(coordStr[0]) - 'A'; + int y = std::atoi(coordStr.data() + 1) - '1'; + return Pos(x, y); +} + // ------------------------------------------------- std::ostream &operator<<(std::ostream &out, Pos pos) diff --git a/Rapfi/core/iohelper.h b/Rapfi/core/iohelper.h index f57d958..f191379 100644 --- a/Rapfi/core/iohelper.h +++ b/Rapfi/core/iohelper.h @@ -47,6 +47,8 @@ Pos inputCoordConvert(int x, int y, int boardsize); int outputCoordXConvert(Pos pos, int boardsize); int outputCoordYConvert(Pos pos, int boardsize); +Pos parseCoord(std::string coordStr); + // ------------------------------------------------- // Formatters diff --git a/Rapfi/game/movegen.cpp b/Rapfi/game/movegen.cpp index 062fce2..1412cae 100644 --- a/Rapfi/game/movegen.cpp +++ b/Rapfi/game/movegen.cpp @@ -550,10 +550,8 @@ ScoredMove *findB4F3Defence(const Board &board, ScoredMove *const moveList) *last++ = b4Pos; - for (int d = 0; d < 4; d++) { - if (d != dir) - last = findAllB3CounterDefence(b4Pos, d, last); - } + for (int d = 0; d < 4; d++) + last = findAllB3CounterDefence(b4Pos, d, last); } } diff --git a/Rapfi/search/searchthread.cpp b/Rapfi/search/searchthread.cpp index fcdd904..f277910 100644 --- a/Rapfi/search/searchthread.cpp +++ b/Rapfi/search/searchthread.cpp @@ -314,10 +314,6 @@ void ThreadPool::startThinking(const Board &board, const SearchOptions &options, assert(size() > 0); assert(searcher()); - // Clear and init all threads state - for (size_t i = 1; i < size(); i++) - (*this)[i]->runTask([this](SearchThread &th) { th.clear(); }); - main()->clear(); main()->inPonder = inPonder; main()->searchOptions = options; @@ -386,14 +382,14 @@ void ThreadPool::startThinking(const Board &board, const SearchOptions &options, } } - // Copy board and root moves from main thread to other threads + // Clear threads state and copy board and root moves to other threads sequentially for (size_t i = 1; i < size(); i++) { - (*this)[i]->runTask([this](SearchThread &th) { - th.setBoardAndEvaluator(*main()->board); - th.rootMoves = main()->rootMoves; - if (main()->searchOptions.balanceMode == Search::SearchOptions::BALANCE_TWO) - th.balance2Moves = main()->balance2Moves; - }); + SearchThread &th = *(*this)[i]; + th.clear(); + th.setBoardAndEvaluator(*main()->board); + th.rootMoves = main()->rootMoves; + if (main()->searchOptions.balanceMode == Search::SearchOptions::BALANCE_TWO) + th.balance2Moves = main()->balance2Moves; } main()->runTask([searcher = searcher()](SearchThread &th) {