From f17275972ffde9000bb28a10b9c2e61990a44a3d Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 16 Aug 2026 18:11:43 +0200 Subject: refactor(board): making generate knight moves use const reference --- src/moves.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/moves.cpp b/src/moves.cpp index 1a23b26..9130761 100644 --- a/src/moves.cpp +++ b/src/moves.cpp @@ -64,10 +64,9 @@ constexpr std::array KNIGHT_ATTACKS = computeKnightAttacks(); constexpr std::array, 2> PAWN_ATTACKS = computePawnAttacks(); -static void GenerateKnightMoves(Game *b, std::vector &moves, +static void GenerateKnightMoves(const Game &g, std::vector &moves, bool GenerateQuietMoves) { - - uint64_t knights = b->PieceBitboards[b->turn][KNIGHT]; + uint64_t knights = g.PieceBitboards[g.turn][KNIGHT]; while (knights != 0) { uint8_t from = static_cast(__builtin_ctzll(knights)); knights &= knights - 1; @@ -76,11 +75,11 @@ static void GenerateKnightMoves(Game *b, std::vector &moves, uint8_t next = static_cast(__builtin_ctzll(knight_attacks)); knight_attacks &= knight_attacks - 1; - bool hasFriendlyPiece = - b->turn ? (b->WhitePieceBitboard & (1ULL << next)) > 0 - : (b->BlackPieceBitboard & (1ULL << next)) > 0; + bool hasFriendlyPiece = g.turn + ? (g.WhitePieceBitboard & (1ULL << next)) > 0 + : (g.BlackPieceBitboard & (1ULL << next)) > 0; - bool isCaptuare = (b->PieceBitboard & (1ULL << next)) > 0; + bool isCaptuare = (g.PieceBitboard & (1ULL << next)) > 0; if (hasFriendlyPiece) { continue; } @@ -194,7 +193,7 @@ std::vector GetPseudoLegalMoves(Game *g, bool GenerateQuietMoves) { std::vector moves; moves.reserve(40); - GenerateKnightMoves(g, moves, GenerateQuietMoves); + GenerateKnightMoves(*g, moves, GenerateQuietMoves); constexpr std::array rook_Moves{-1, 1, 8, -8}; constexpr std::array bishop_Moves{-9, 9, -7, 7}; -- cgit v1.2.3