From 793d47e64e3c0c706f785f6f32c396f952e5bb36 Mon Sep 17 00:00:00 2001 From: Jay Honnold Date: Sun, 18 Jul 2021 16:43:35 -0500 Subject: [PATCH 1/3] Bench: 7435016 --- src/search.c | 26 +++++++++++++++++++++----- src/search.h | 2 ++ src/types.h | 2 ++ src/uci.c | 8 ++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/search.c b/src/search.c index 4c8c0e42..0d3b3206 100644 --- a/src/search.c +++ b/src/search.c @@ -80,8 +80,14 @@ void* UCISearch(void* arg) { void BestMove(Board* board, SearchParams* params, ThreadData* threads, SearchResults* results) { Move bestMove; if ((bestMove = TBRootProbe(board))) { + while (params->pondering) + asm(""); + printf("bestmove %s\n", MoveToStr(bestMove)); } else if ((bestMove = ProbeNoob(board))) { + while (params->pondering) + asm(""); + printf("bestmove %s\n", MoveToStr(bestMove)); } else { pthread_t pthreads[threads->count]; @@ -100,7 +106,14 @@ void BestMove(Board* board, SearchParams* params, ThreadData* threads, SearchRes for (int i = 1; i < threads->count; i++) pthread_join(pthreads[i], NULL); - printf("bestmove %s\n", MoveToStr(results->bestMoves[results->depth])); + while (params->pondering) + asm(""); + + printf("bestmove %s", MoveToStr(results->bestMoves[results->depth])); + if (results->ponderMoves[results->depth]) + printf(" ponder %s", MoveToStr(results->ponderMoves[results->depth])); + + printf("\n"); } } @@ -204,6 +217,7 @@ void* Search(void* arg) { results->depth = depth; results->scores[depth] = thread->scores[0]; results->bestMoves[depth] = thread->bestMoves[0]; + results->ponderMoves[depth] = thread->pvs[0].count ? thread->pvs[0].moves[0] : NULL_MOVE; if (!mainThread || depth < 5 || !params->timeset) continue; @@ -257,8 +271,7 @@ int Negamax(int alpha, int beta, int depth, ThreadData* thread, PV* pv) { // Either mainthread has ended us OR we've run out of time // this second check is more expensive and done only every 1024 nodes // 1Mnps ~1ms - if (params->stopped || - (!(data->nodes & 1023) && params->timeset && GetTimeMS() - params->start > min(params->alloc, params->max))) + if (params->stopped || (!(data->nodes & 1023) && StopSearch(params))) longjmp(thread->exit, 1); if (!isRoot) { @@ -610,8 +623,7 @@ int Quiesce(int alpha, int beta, ThreadData* thread, PV* pv) { // Either mainthread has ended us OR we've run out of time // this second check is more expensive and done only every 1024 nodes // 1Mnps ~1ms - if (params->stopped || - (!(data->nodes & 1023) && params->timeset && GetTimeMS() - params->start > min(params->alloc, params->max))) + if (params->stopped || (!(data->nodes & 1023) && StopSearch(params))) longjmp(thread->exit, 1); // draw check @@ -735,6 +747,10 @@ void PrintPV(PV* pv) { printf("\n"); } +inline int StopSearch(SearchParams* params) { + return params->timeset && !params->pondering && GetTimeMS() - params->start > min(params->alloc, params->max); +} + int MoveSearchedByMultiPV(ThreadData* thread, Move move) { for (int i = 0; i < thread->multiPV; i++) if (thread->bestMoves[i] == move) diff --git a/src/search.h b/src/search.h index a2a7b84e..766483e0 100644 --- a/src/search.h +++ b/src/search.h @@ -48,6 +48,8 @@ int Quiesce(int alpha, int beta, ThreadData* thread, PV* pv); void PrintInfo(PV* pv, int score, ThreadData* thread, int alpha, int beta, int multiPV); void PrintPV(PV* pv); +int StopSearch(SearchParams* params); + int MoveSearchedByMultiPV(ThreadData* thread, Move move); int MoveSearchable(SearchParams* params, Move move); diff --git a/src/types.h b/src/types.h index 2632a568..58c7e918 100644 --- a/src/types.h +++ b/src/types.h @@ -202,6 +202,7 @@ typedef struct { int movesToGo; int stopped; int quit; + int pondering; int multiPV; int searchMoves; SimpleMoveList searchable; @@ -211,6 +212,7 @@ typedef struct { int depth; Score scores[MAX_SEARCH_PLY]; Move bestMoves[MAX_SEARCH_PLY]; + Move ponderMoves[MAX_SEARCH_PLY]; } SearchResults; typedef struct { diff --git a/src/uci.c b/src/uci.c index 0c6f035e..42fd761f 100644 --- a/src/uci.c +++ b/src/uci.c @@ -64,6 +64,7 @@ void ParseGo(char* in, SearchParams* params, Board* board, ThreadData* threads) params->stopped = 0; params->quit = 0; params->multiPV = MULTI_PV; + params->pondering = 0; params->searchMoves = 0; params->searchable.count = 0; @@ -97,6 +98,9 @@ void ParseGo(char* in, SearchParams* params, Board* board, ThreadData* threads) if ((ptrChar = strstr(in, "depth"))) depth = min(MAX_SEARCH_PLY - 1, atoi(ptrChar + 6)); + if ((ptrChar = strstr(in, "ponder"))) + params->pondering = 1; + if ((ptrChar = strstr(in, "searchmoves"))) { params->searchMoves = 1; @@ -243,12 +247,16 @@ void UCILoop() { } else if (!strncmp(in, "go", 2)) { ParseGo(in, &searchParameters, &board, threads); } else if (!strncmp(in, "stop", 4)) { + searchParameters.pondering = 0; searchParameters.stopped = 1; } else if (!strncmp(in, "quit", 4)) { + searchParameters.pondering = 0; searchParameters.quit = 1; break; } else if (!strncmp(in, "uci", 3)) { PrintUCIOptions(); + } else if (!strncmp(in, "ponderhit", 9)) { + searchParameters.pondering = 0; } else if (!strncmp(in, "board", 5)) { PrintBoard(&board); } else if (!strncmp(in, "eval", 4)) { From 957526256d4e8532424766526a0a63ad7c1466f3 Mon Sep 17 00:00:00 2001 From: Jay Honnold Date: Sun, 18 Jul 2021 17:04:43 -0500 Subject: [PATCH 2/3] Bench: 7435016 --- src/search.c | 8 ++++---- src/search.h | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/search.c b/src/search.c index 0d3b3206..d0db1bf8 100644 --- a/src/search.c +++ b/src/search.c @@ -63,6 +63,10 @@ void InitPruningAndReductionTables() { } } +INLINE int StopSearch(SearchParams* params) { + return params->timeset && GetTimeMS() - params->start > min(params->alloc, params->max) && !params->pondering; +} + void* UCISearch(void* arg) { SearchArgs* args = (SearchArgs*)arg; @@ -747,10 +751,6 @@ void PrintPV(PV* pv) { printf("\n"); } -inline int StopSearch(SearchParams* params) { - return params->timeset && !params->pondering && GetTimeMS() - params->start > min(params->alloc, params->max); -} - int MoveSearchedByMultiPV(ThreadData* thread, Move move) { for (int i = 0; i < thread->multiPV; i++) if (thread->bestMoves[i] == move) diff --git a/src/search.h b/src/search.h index 766483e0..cb487d10 100644 --- a/src/search.h +++ b/src/search.h @@ -47,9 +47,7 @@ int Quiesce(int alpha, int beta, ThreadData* thread, PV* pv); void PrintInfo(PV* pv, int score, ThreadData* thread, int alpha, int beta, int multiPV); void PrintPV(PV* pv); - -int StopSearch(SearchParams* params); - + int MoveSearchedByMultiPV(ThreadData* thread, Move move); int MoveSearchable(SearchParams* params, Move move); From c10da1f474710b5fa508d5e1873b774d43f3bf99 Mon Sep 17 00:00:00 2001 From: Jay Honnold Date: Sun, 18 Jul 2021 17:07:51 -0500 Subject: [PATCH 3/3] Fix ponder move Bench: 7435016 --- src/search.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.c b/src/search.c index d0db1bf8..8c1a9194 100644 --- a/src/search.c +++ b/src/search.c @@ -221,7 +221,7 @@ void* Search(void* arg) { results->depth = depth; results->scores[depth] = thread->scores[0]; results->bestMoves[depth] = thread->bestMoves[0]; - results->ponderMoves[depth] = thread->pvs[0].count ? thread->pvs[0].moves[0] : NULL_MOVE; + results->ponderMoves[depth] = thread->pvs[0].count > 1 ? thread->pvs[0].moves[1] : NULL_MOVE; if (!mainThread || depth < 5 || !params->timeset) continue;