From 729ba94123c69894d7231782b3c3895f23269acd Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 20 Mar 2025 21:14:07 +0100 Subject: [PATCH] final refactor | bench 900613 --- source/benchmark.cpp | 2 ++ source/board.cpp | 24 ++++++++++++------------ source/search.cpp | 3 +++ source/search.h | 3 +++ source/tt.cpp | 2 +- source/tt.h | 2 +- source/uci.cpp | 8 ++++---- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/source/benchmark.cpp b/source/benchmark.cpp index db3e04d..02528e5 100644 --- a/source/benchmark.cpp +++ b/source/benchmark.cpp @@ -6,6 +6,8 @@ #include "stopwatch.h" #include "tt.h" +using namespace SEARCH; + constexpr std::array fenPositions = { "rnbq1k1r/ppp1bppp/4pn2/8/2B5/2NP1N2/PPP2PPP/R1BQR1K1 b - - 2 8", "rnbq1k1r/pp2bppp/4pn2/2p5/2B2B2/2NP1N2/PPP2PPP/R2QR1K1 b - - 1 9", diff --git a/source/board.cpp b/source/board.cpp index 21540d4..2625a5f 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -217,28 +217,28 @@ void Board::Promote(int square, int pieceType, int color, bool isCapture) { } void Board::MakeMove(Move move) { - nodes++; - - // Null Move + SEARCH::nodes++; + + // Null Move if (!move) { - int newEpTarget = noEPTarget; - + int newEpTarget = noEPTarget; + sideToMove = !sideToMove; hashKey ^= UTILS::zSide; - + if (enPassantTarget != noEPTarget) { - hashKey ^= UTILS::zEnPassant[enPassantTarget % 8]; + hashKey ^= UTILS::zEnPassant[enPassantTarget % 8]; } - + if (newEpTarget != noEPTarget) { - hashKey ^= UTILS::zEnPassant[newEpTarget % 8]; + hashKey ^= UTILS::zEnPassant[newEpTarget % 8]; } - + enPassantTarget = newEpTarget; - + return; } - + int newEpTarget = noEPTarget; int attackerPiece = GetPieceType(move.MoveFrom()); diff --git a/source/search.cpp b/source/search.cpp index d4e5994..6874efe 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -6,6 +6,8 @@ #include "tt.h" #include "stopwatch.h" +namespace SEARCH { + U64 nodes = 0; bool benchStarted = false; @@ -361,3 +363,4 @@ void SearchPosition(Board &board, SearchParams params) { void StopSearch() { searchStopped = true; } +} \ No newline at end of file diff --git a/source/search.h b/source/search.h index 55cb9bb..1458400 100644 --- a/source/search.h +++ b/source/search.h @@ -5,6 +5,8 @@ #include "move.h" #include +namespace SEARCH { + constexpr int maxDepth = 64; constexpr int maxHistory = 16384; @@ -108,3 +110,4 @@ constexpr int moveScoreTable[6][6] = { }; void ListScores(Board &board); +} \ No newline at end of file diff --git a/source/tt.cpp b/source/tt.cpp index e65b2b7..3df1649 100644 --- a/source/tt.cpp +++ b/source/tt.cpp @@ -1,6 +1,6 @@ #include "tt.h" -SearchResults TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int beta) { +SEARCH::SearchResults TTable::ReadEntry(U64 &hashKey, int depth, int alpha, int beta) { TTEntry *current = &table[hashKey % hashSize]; if (current->hashKey == hashKey) { diff --git a/source/tt.h b/source/tt.h index 1b973ab..e8607c4 100644 --- a/source/tt.h +++ b/source/tt.h @@ -56,7 +56,7 @@ public: return count; } - SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta); + SEARCH::SearchResults ReadEntry(U64 &hashKey, int depth, int alpha, int beta); void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove); }; diff --git a/source/uci.cpp b/source/uci.cpp index 723f139..d9f72b4 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -72,7 +72,7 @@ static void ParseGo(Board &board, std::string &command) { params.btime = ReadParam("movetime", command); } - auto worker = std::thread(SearchPosition, std::ref(board), params); + auto worker = std::thread(SEARCH::SearchPosition, std::ref(board), params); worker.detach(); } @@ -118,9 +118,9 @@ void UCILoop(Board &board) { // Clearing TT.Clear(); - std::memset(killerMoves, 0, sizeof(killerMoves)); + std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves)); - history.Clear(); + SEARCH::history.Clear(); positionIndex = 0; continue; @@ -141,7 +141,7 @@ void UCILoop(Board &board) { // parse UCI "stop" command if (input.find("stop") != std::string::npos) { // stop the loop - StopSearch(); + SEARCH::StopSearch(); continue; }