From cdfb752bfa0b46c81a88b07d43256e8149fb09e2 Mon Sep 17 00:00:00 2001 From: rektdie Date: Tue, 5 Aug 2025 01:13:57 +0200 Subject: [PATCH] removed unused functions & variables | bench 24146828 --- Makefile | 2 +- source/benchmark.cpp | 1 - source/datagen.cpp | 3 -- source/movegen.cpp | 114 ------------------------------------------- source/nnue.cpp | 5 -- source/search.cpp | 2 +- source/search.h | 9 ---- source/tt.h | 2 +- source/uci.cpp | 2 +- 9 files changed, 4 insertions(+), 136 deletions(-) diff --git a/Makefile b/Makefile index 4f1b6e5..38d8bf7 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ else endif endif -CXXFLAGS := -std=c++20 -O3 -flto +CXXFLAGS := -std=c++20 -O3 -flto -Wall LDFLAGS := -O3 -flto ifeq ($(PLATFORM),mac) diff --git a/source/benchmark.cpp b/source/benchmark.cpp index 0eab98c..2e0b73e 100644 --- a/source/benchmark.cpp +++ b/source/benchmark.cpp @@ -63,7 +63,6 @@ constexpr std::array fenPositions = { void RunBenchmark() { Board board; - int depth = BENCH_DEPTH; auto ctx = std::make_unique(); diff --git a/source/datagen.cpp b/source/datagen.cpp index d6800fb..ab8f7cb 100644 --- a/source/datagen.cpp +++ b/source/datagen.cpp @@ -263,9 +263,6 @@ void PrintProgress(int positions, int targetPositions, Stopwatch &stopwatch, int lastElapsed = elapsed; } - int positionsInThousands = static_cast(round(positions / 1000.0)); - int targetInThousands = static_cast(round(targetPositions / 1000.0)); - std::cout << "\033[H"; int width = 60; diff --git a/source/movegen.cpp b/source/movegen.cpp index 5634103..c18553f 100644 --- a/source/movegen.cpp +++ b/source/movegen.cpp @@ -299,120 +299,6 @@ Bitboard getPawnPushes(int square, bool color, Bitboard &occupancy) { return pushes; } -// Returns the direction to target from square -static int GetDirection(int square, int target) { - int rankDiff = (target / 8) - (square / 8); - int fileDiff = (target % 8) - (square % 8); - - // Main directions - if (rankDiff == 0 && fileDiff < 0) { - return west; - } else if (rankDiff == 0 && fileDiff > 0) { - return east; - } else if (rankDiff < 0 && fileDiff == 0) { - return south; - } else if (rankDiff > 0 && fileDiff == 0) { - return north; - } - - // Diagonals - if (abs(rankDiff) == abs(fileDiff)) { - if (rankDiff < 0 && fileDiff < 0) { - return soWe; - } else if (rankDiff < 0 && fileDiff > 0) { - return soEa; - } else if (rankDiff > 0 && fileDiff < 0) { - return noWe; - } else if (rankDiff > 0 && fileDiff > 0) { - return noEa; - } - } - - return 0; -} - -// Returns a bitboard of the squares from attacker to target -static Bitboard SliderRayToSquare(int attacker, int target) { - Bitboard ray; - int direction = GetDirection(attacker, target); - - if (direction) { - while (attacker != target) { - ray.SetBit(attacker); - attacker += direction; - } - ray.SetBit(target); - } - - return ray; -} - -static Bitboard GetPinningRay(Board &board, int square, int direction) { - Bitboard ray; - int currentSquare = (board.pieces[King] & board.colors[board.sideToMove]).getLS1BIndex(); - int previousRank = currentSquare / 8; - - currentSquare += direction; - while (currentSquare < 64 && currentSquare >= 0) { - int currentRank = currentSquare / 8; - - int difference = abs(currentRank - previousRank); - - if ((abs(direction) == 7 || abs(direction) == 9) - && difference != 1) { - break; - } else if (abs(direction) == 1 && difference) { - break; - } - previousRank = currentRank; - - ray.SetBit(currentSquare); - if (board.occupied.IsSet(currentSquare)) { - if (currentSquare == square) { - currentSquare += direction; - continue; - } - int attackerType = board.GetPieceType(currentSquare); - int attackerColor = board.GetPieceColor(currentSquare); - - if (attackerColor != board.sideToMove) { - // Pinned by rook or queen - if (abs(direction) == 1 || abs(direction) == 8) { - if (attackerType == Rook || attackerType == Queen) { - return ray; - } - // Pinned by bishop or queen - } else if (direction % 2 != 0) { - if (attackerType == Bishop || attackerType == Queen) { - return ray; - } - } - } - break; - } - currentSquare += direction; - } - - return 0ULL; -} - -static bool IsPinned(Board &board, int square) { - int kingSquare = (board.colors[board.sideToMove] & board.pieces[King]).getLS1BIndex(); - int directionToKing = GetDirection(square, kingSquare); - - if (directionToKing) { - // Checking if there are any pieces between square and kingSquare - if ((SliderRayToSquare(square, kingSquare) - & board.occupied).PopCount() != 2) { - return false; - } - - return GetPinningRay(board, square, -directionToKing).PopCount(); - } - - return false; -} - void GenThreatMaps(Board &board) { for (int color = White; color <= Black; color++) { board.colorThreats[color] = 0ULL; diff --git a/source/nnue.cpp b/source/nnue.cpp index f12bf32..240d52a 100644 --- a/source/nnue.cpp +++ b/source/nnue.cpp @@ -170,14 +170,9 @@ static int32_t VectorizedSCReLU(const Board& board, const Network& net, size_t o } int Forward(const Board& board, const Network& net) { - bool stm = board.sideToMove; - const size_t divisor = 32 / OUTPUT_BUCKETS; const size_t outputBucket = (board.occupied.PopCount() - 2) / divisor; - const ACC::Accumulator& stmACC = stm ? board.accPair.white : board.accPair.black; - const ACC::Accumulator& nstmACC = !stm ? board.accPair.white : board.accPair.black; - int64_t eval = 0; eval = VectorizedSCReLU(board, net, outputBucket); diff --git a/source/search.cpp b/source/search.cpp index 92f436c..cc45fd7 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -36,7 +36,7 @@ static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) { targetType = Pawn; } - return 50000 * ((SEE(board, move, -100))) + moveScoreTable[attackerType][targetType]; + return 50000 * ((SEE(board, move, -100))) + (100 * targetType - attackerType + 105); } else { if (ctx->killerMoves[0][ply] == move) { return 41000; diff --git a/source/search.h b/source/search.h index cbe0896..3ba9fea 100644 --- a/source/search.h +++ b/source/search.h @@ -163,15 +163,6 @@ SearchResults SearchPosition(Board &board, SearchParams params, SearchContext* c bool IsDraw(Board &board, SearchContext* ctx); -constexpr int moveScoreTable[6][6] = { - 105, 205, 305, 405, 505, 605, - 104, 204, 304, 404, 504, 604, - 103, 203, 303, 403, 503, 603, - 102, 202, 302, 402, 502, 602, - 101, 201, 301, 401, 501, 601, - 100, 200, 300, 400, 500, 600 -}; - void ListScores(Board &board, SearchContext* ctx); int MoveEstimatedValue(Board& board, Move& move); diff --git a/source/tt.h b/source/tt.h index d471e07..9b5db2d 100644 --- a/source/tt.h +++ b/source/tt.h @@ -43,7 +43,7 @@ constexpr U64 maxHash = (1024 * 1000000) / sizeof(TTEntry); // 8 MB constexpr U64 defaultHash = (8 * 1000000) / sizeof(TTEntry); -constexpr int16_t invalidEntry = 111111; +constexpr int16_t invalidEntry = 11111; class TTable { private: diff --git a/source/uci.cpp b/source/uci.cpp index 40c68cc..2c74f17 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -32,7 +32,7 @@ static void ParsePosition(Board &board, std::string_view command, SEARCH::Search std::vector moves = UTILS::split(command.substr(movesIndex + 6, command.length() - (movesIndex + 5)), ' '); for (std::string_view move : moves) { - bool isLegal = board.MakeMove(UTILS::parseMove(board, move)); + board.MakeMove(UTILS::parseMove(board, move)); ctx->positionHistory[board.positionIndex] = board.hashKey; } }