From d7a383ccaa3d07a91116ca2791c2e787e45262e0 Mon Sep 17 00:00:00 2001 From: Terje Date: Sat, 2 Dec 2023 13:16:33 +0100 Subject: [PATCH] Bench: 21825554 --- src/board.c | 4 +-- src/board.h | 2 +- src/endgame.c | 4 +-- src/endgame.h | 2 +- src/evaluate.c | 2 +- src/makemove.c | 2 +- src/move.c | 4 +-- src/move.h | 2 +- src/noobprobe/noobprobe.c | 10 ++++---- src/noobprobe/noobprobe.h | 4 +-- src/onlinesyzygy/onlinesyzygy.c | 2 +- src/onlinesyzygy/onlinesyzygy.h | 2 +- src/search.c | 4 +-- src/syzygy.h | 4 +-- src/tests.c | 14 +++++------ src/threads.c | 44 ++++++++++++++++----------------- src/threads.h | 2 +- src/uci.c | 8 +++--- 18 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/board.c b/src/board.c index c2d6cda3..22f06952 100644 --- a/src/board.c +++ b/src/board.c @@ -27,7 +27,7 @@ #include "psqt.h" -bool chess960 = false; +bool Chess960 = false; uint8_t SqDistance[64][64]; @@ -170,7 +170,7 @@ static void AddPiece(Position *pos, const Square sq, const Piece piece) { static void InitCastlingRight(Position *pos, Color color, int file) { if ( FileOf(kingSq(color)) != FILE_E - || (file != FILE_A && file != FILE_H)) chess960 = true; + || (file != FILE_A && file != FILE_H)) Chess960 = true; Square kFrom = kingSq(color); Square rFrom = MakeSquare(RelativeRank(color, RANK_1), file); diff --git a/src/board.h b/src/board.h index f196ec94..064a6e8a 100644 --- a/src/board.h +++ b/src/board.h @@ -61,7 +61,7 @@ typedef struct Position { } Position; -extern bool chess960; +extern bool Chess960; extern const int NonPawn[PIECE_NB]; diff --git a/src/endgame.c b/src/endgame.c index 61f95938..293ec51f 100644 --- a/src/endgame.c +++ b/src/endgame.c @@ -24,7 +24,7 @@ #include "endgame.h" -Endgame endgameTable[ENDGAME_TABLE_SIZE] = { 0 }; +Endgame EndgameTable[ENDGAME_TABLE_SIZE] = { 0 }; // Generates a material key from a string like "KRPkr" @@ -50,7 +50,7 @@ static void AddEndgame(const char *white, const char *black, SpecializedEval ef) Key key = GenMaterialKey(white, black); - Endgame *eg = &endgameTable[EndgameIndex(key)]; + Endgame *eg = &EndgameTable[EndgameIndex(key)]; if (eg->evalFunc != NULL) { puts("Collision in endgame table."); diff --git a/src/endgame.h b/src/endgame.h index aea67c45..c5cd48a4 100644 --- a/src/endgame.h +++ b/src/endgame.h @@ -33,7 +33,7 @@ typedef struct Endgame { } Endgame; -extern Endgame endgameTable[ENDGAME_TABLE_SIZE]; +extern Endgame EndgameTable[ENDGAME_TABLE_SIZE]; INLINE int EndgameIndex(Key materialKey) { diff --git a/src/evaluate.c b/src/evaluate.c index eec9adca..f02475a9 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -524,7 +524,7 @@ static int ScaleFactor(const Position *pos, const int eval) { // Calculate a static evaluation of a position int EvalPosition(const Position *pos, PawnCache pc) { - Endgame *eg = &endgameTable[EndgameIndex(pos->materialKey)]; + Endgame *eg = &EndgameTable[EndgameIndex(pos->materialKey)]; if (eg->key == pos->materialKey && eg->evalFunc != NULL) return eg->evalFunc(pos, sideToMove); diff --git a/src/makemove.c b/src/makemove.c index fe4dc393..389b748f 100644 --- a/src/makemove.c +++ b/src/makemove.c @@ -110,7 +110,7 @@ static void MovePiece(Position *pos, const Square from, const Square to, const b const PieceType pt = PieceTypeOf(piece); assert(ValidPiece(piece)); - assert(pieceOn(to) == EMPTY || (chess960 && pt == ROOK)); + assert(pieceOn(to) == EMPTY || (Chess960 && pt == ROOK)); // Hash out piece on old square, in on new square if (hash) diff --git a/src/move.c b/src/move.c index 8bc0e3c8..9014f832 100644 --- a/src/move.c +++ b/src/move.c @@ -81,7 +81,7 @@ char *MoveToStr(const Move move) { moveStr[4] = "\0.nbrq"[PieceTypeOf(promotion(move))]; // Encode castling as KxR for chess 960 - if (chess960 && moveIsCastle(move)) { + if (Chess960 && moveIsCastle(move)) { int color = ColorOf(piece(move)) == WHITE ? WHITE_CASTLE : BLACK_CASTLE; int side = FileOf(toSq(move)) == FILE_G ? OO : OOO; SqToStr(RookSquare[color & side], moveStr + 2); @@ -109,7 +109,7 @@ Move ParseMove(const char *str, const Position *pos) { : pt == PAWN && str[0] != str[2] && !pieceOn(to) ? FLAG_ENPAS : 0; - if (chess960 && pt == KING && pieceOn(to) == MakePiece(sideToMove, ROOK)) { + if (Chess960 && pt == KING && pieceOn(to) == MakePiece(sideToMove, ROOK)) { to = RelativeSquare(sideToMove, to > from ? G1 : C1); flag = FLAG_CASTLE; } diff --git a/src/move.h b/src/move.h index d8cb2eef..f78e322d 100644 --- a/src/move.h +++ b/src/move.h @@ -88,7 +88,7 @@ INLINE bool CastleLegal(const Position *pos, Square to) { if (SqAttacked(pos, PopLsb(&kingPath), !color)) return false; - return !chess960 || !(Attackers(pos, to, pieceBB(ALL) ^ BB(RookSquare[castle])) & colorBB(!color)); + return !Chess960 || !(Attackers(pos, to, pieceBB(ALL) ^ BB(RookSquare[castle])) & colorBB(!color)); } bool MoveIsPseudoLegal(const Position *pos, Move move); diff --git a/src/noobprobe/noobprobe.c b/src/noobprobe/noobprobe.c index bfd36918..e1ac30ea 100644 --- a/src/noobprobe/noobprobe.c +++ b/src/noobprobe/noobprobe.c @@ -25,19 +25,19 @@ #include "../query/query.h" -bool noobbook; +bool NoobBook; int failedQueries; -int noobLimit; +int NoobLimit; // Probes noobpwnftw's Chess Cloud Database bool ProbeNoob(Position *pos) { // Stop querying after 3 failures or at the specified depth - if ( !noobbook + if ( !NoobBook || failedQueries >= 3 || (Limits.timelimit && Limits.maxUsage < 2000) - || (noobLimit && pos->gameMoves > noobLimit)) + || (NoobLimit && pos->gameMoves > NoobLimit)) return false; puts("info string NoobBook: Querying chessdb.cn for a move..."); @@ -51,7 +51,7 @@ bool ProbeNoob(Position *pos) { if (strstr(response, "move") != response) return failedQueries++, false; - threads->rootMoves[0].move = ParseMove(&response[5], pos); + Threads->rootMoves[0].move = ParseMove(&response[5], pos); puts("info string NoobBook: Move received"); diff --git a/src/noobprobe/noobprobe.h b/src/noobprobe/noobprobe.h index 3307990d..2329398e 100644 --- a/src/noobprobe/noobprobe.h +++ b/src/noobprobe/noobprobe.h @@ -22,9 +22,9 @@ #include "../types.h" -extern bool noobbook; +extern bool NoobBook; +extern int NoobLimit; extern int failedQueries; -extern int noobLimit; bool ProbeNoob(Position *pos); diff --git a/src/onlinesyzygy/onlinesyzygy.c b/src/onlinesyzygy/onlinesyzygy.c index 0b91769f..5b0c9ceb 100644 --- a/src/onlinesyzygy/onlinesyzygy.c +++ b/src/onlinesyzygy/onlinesyzygy.c @@ -26,7 +26,7 @@ #include "onlinesyzygy.h" -bool onlineSyzygy = false; +bool OnlineSyzygy = false; // Probes lichess syzygy diff --git a/src/onlinesyzygy/onlinesyzygy.h b/src/onlinesyzygy/onlinesyzygy.h index 66ca153a..26d799c8 100644 --- a/src/onlinesyzygy/onlinesyzygy.h +++ b/src/onlinesyzygy/onlinesyzygy.h @@ -22,7 +22,7 @@ #include "../types.h" -extern bool onlineSyzygy; +extern bool OnlineSyzygy; bool QueryRoot(const Position *pos, unsigned *wdl, unsigned *dtz, Move *move); diff --git a/src/search.c b/src/search.c index 174b0409..5987bbad 100644 --- a/src/search.c +++ b/src/search.c @@ -698,7 +698,7 @@ void *SearchPosition(void *pos) { // Start helper threads and begin searching StartHelpers(IterativeDeepening); - IterativeDeepening(&threads[0]); + IterativeDeepening(&Threads[0]); conclusion: @@ -710,7 +710,7 @@ void *SearchPosition(void *pos) { WaitForHelpers(); // Print conclusion - PrintConclusion(threads); + PrintConclusion(Threads); SEARCH_STOPPED = true; Wake(); diff --git a/src/syzygy.h b/src/syzygy.h index 558feeb6..374d2941 100644 --- a/src/syzygy.h +++ b/src/syzygy.h @@ -106,7 +106,7 @@ static bool SyzygyMove(const Position *pos) { bool success = pos->castlingRights ? false : pieces <= TB_LARGEST ? ProbeRoot(pos, &move, &wdl, &dtz) - : onlineSyzygy && pieces <= 7 ? QueryRoot(pos, &move, &wdl, &dtz) + : OnlineSyzygy && pieces <= 7 ? QueryRoot(pos, &move, &wdl, &dtz) : false; if (!success) return false; @@ -117,7 +117,7 @@ static bool SyzygyMove(const Position *pos) { fflush(stdout); // Set move to be printed as conclusion - threads->rootMoves[0].move = move; + Threads->rootMoves[0].move = move; return true; } diff --git a/src/tests.c b/src/tests.c index 27274c58..47c8fcee 100644 --- a/src/tests.c +++ b/src/tests.c @@ -122,14 +122,14 @@ void Benchmark(int argc, char **argv) { // Collect results BenchResult *r = &results[i]; r->elapsed = TimeSince(Limits.start); - r->nodes = TotalNodes(threads); - r->score = threads->rootMoves[0].score; - r->best = threads->rootMoves[0].move; + r->nodes = TotalNodes(Threads); + r->score = Threads->rootMoves[0].score; + r->best = Threads->rootMoves[0].move; totalElapsed += r->elapsed; totalNodes += r->nodes; - ClearTT(threads); + ClearTT(Threads); } puts("======================================================"); @@ -179,13 +179,13 @@ void Perft(char *str) { char *fen = strtok(NULL, "\0") ?: default_fen; Depth depth = d ? atoi(d) : 5; - ParseFen(fen, &threads->pos); + ParseFen(fen, &Threads->pos); printf("\nPerft starting:\nDepth : %d\nFEN : %s\n", depth, fen); fflush(stdout); const TimePoint start = Now(); - uint64_t leafNodes = RecursivePerft(&threads->pos, depth); + uint64_t leafNodes = RecursivePerft(&Threads->pos, depth); const TimePoint elapsed = TimeSince(start) + 1; printf("\nPerft complete:" @@ -197,7 +197,7 @@ void Perft(char *str) { } void PrintEval(Position *pos) { - printf("%d\n", EvalPositionWhitePov(pos, threads->pawnCache)); + printf("%d\n", EvalPositionWhitePov(pos, Threads->pawnCache)); fflush(stdout); } #endif diff --git a/src/threads.c b/src/threads.c index 335e13dd..944b2e57 100644 --- a/src/threads.c +++ b/src/threads.c @@ -27,7 +27,7 @@ #include "threads.h" -Thread *threads; +Thread *Threads; static pthread_t *pthreads; // Used for letting the main thread sleep without using cpu @@ -38,16 +38,16 @@ static pthread_cond_t sleepCondition = PTHREAD_COND_INITIALIZER; // Allocates memory for thread structs void InitThreads(int count) { - if (threads) free(threads); + if (Threads) free(Threads); if (pthreads) free(pthreads); - threads = calloc(count, sizeof(Thread)); + Threads = calloc(count, sizeof(Thread)); pthreads = calloc(count, sizeof(pthread_t)); // Each thread knows its own index and total thread count for (int i = 0; i < count; ++i) - threads[i].index = i, - threads[i].count = count; + Threads[i].index = i, + Threads[i].count = count; } // Sorts all rootmoves searched by multiPV @@ -70,16 +70,16 @@ void SortRootMoves(Thread *thread, int multiPV) { // Tallies the nodes searched by all threads uint64_t TotalNodes() { uint64_t total = 0; - for (int i = 0; i < threads->count; ++i) - total += threads[i].pos.nodes; + for (int i = 0; i < Threads->count; ++i) + total += Threads[i].pos.nodes; return total; } // Tallies the tbhits of all threads uint64_t TotalTBHits() { uint64_t total = 0; - for (int i = 0; i < threads->count; ++i) - total += threads[i].tbhits; + for (int i = 0; i < Threads->count; ++i) + total += Threads[i].tbhits; return total; } @@ -87,7 +87,7 @@ uint64_t TotalTBHits() { void PrepareSearch(Position *pos, Move searchmoves[]) { int rootMoveCount = LegalMoveCount(pos, searchmoves); - for (Thread *t = threads; t < threads + threads->count; ++t) { + for (Thread *t = Threads; t < Threads + Threads->count; ++t) { memset(t, 0, offsetof(Thread, pos)); memcpy(&t->pos, pos, sizeof(Position)); t->rootMoveCount = rootMoveCount; @@ -109,33 +109,33 @@ static bool helpersActive = false; // Start helper threads running the provided function void StartHelpers(void *(*func)(void *)) { helpersActive = true; - for (int i = 1; i < threads->count; ++i) - pthread_create(&pthreads[i], NULL, func, &threads[i]); + for (int i = 1; i < Threads->count; ++i) + pthread_create(&pthreads[i], NULL, func, &Threads[i]); } // Wait for helper threads to finish void WaitForHelpers() { if (!helpersActive) return; - for (int i = 1; i < threads->count; ++i) + for (int i = 1; i < Threads->count; ++i) pthread_join(pthreads[i], NULL); helpersActive = false; } // Reset all data that isn't reset each turn void ResetThreads() { - for (int i = 0; i < threads->count; ++i) - memset(threads[i].pawnCache, 0, sizeof(PawnCache)), - memset(threads[i].history, 0, sizeof(threads[i].history)), - memset(threads[i].pawnHistory, 0, sizeof(threads[i].pawnHistory)), - memset(threads[i].captureHistory, 0, sizeof(threads[i].captureHistory)), - memset(threads[i].continuation, 0, sizeof(threads[i].continuation)); + for (int i = 0; i < Threads->count; ++i) + memset(Threads[i].pawnCache, 0, sizeof(PawnCache)), + memset(Threads[i].history, 0, sizeof(Threads[i].history)), + memset(Threads[i].pawnHistory, 0, sizeof(Threads[i].pawnHistory)), + memset(Threads[i].captureHistory, 0, sizeof(Threads[i].captureHistory)), + memset(Threads[i].continuation, 0, sizeof(Threads[i].continuation)); } // Run the given function once in each thread void RunWithAllThreads(void *(*func)(void *)) { - for (int i = 0; i < threads->count; ++i) - pthread_create(&pthreads[i], NULL, func, &threads[i]); - for (int i = 0; i < threads->count; ++i) + for (int i = 0; i < Threads->count; ++i) + pthread_create(&pthreads[i], NULL, func, &Threads[i]); + for (int i = 0; i < Threads->count; ++i) pthread_join(pthreads[i], NULL); } diff --git a/src/threads.h b/src/threads.h index bab7ff35..1eebed8d 100644 --- a/src/threads.h +++ b/src/threads.h @@ -83,7 +83,7 @@ typedef struct Thread { } Thread; -extern Thread *threads; +extern Thread *Threads; void InitThreads(int threadCount); diff --git a/src/uci.c b/src/uci.c index b6002ccf..27b6769e 100644 --- a/src/uci.c +++ b/src/uci.c @@ -113,10 +113,10 @@ static void SetOption(char *str) { else if (OptionNameIs("Threads" )) InitThreads(IntValue); else if (OptionNameIs("SyzygyPath" )) tb_init(optionValue); else if (OptionNameIs("MultiPV" )) Limits.multiPV = IntValue; - else if (OptionNameIs("NoobBookLimit")) noobLimit = IntValue; - else if (OptionNameIs("NoobBook" )) noobbook = BooleanValue; - else if (OptionNameIs("UCI_Chess960" )) chess960 = BooleanValue; - else if (OptionNameIs("OnlineSyzygy" )) onlineSyzygy = BooleanValue; + else if (OptionNameIs("NoobBookLimit")) NoobLimit = IntValue; + else if (OptionNameIs("NoobBook" )) NoobBook = BooleanValue; + else if (OptionNameIs("UCI_Chess960" )) Chess960 = BooleanValue; + else if (OptionNameIs("OnlineSyzygy" )) OnlineSyzygy = BooleanValue; else puts("info string No such option."); fflush(stdout);