aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-08-16 18:11:43 +0200
committerAdam <adammegarules1@gmail.com>2026-08-16 18:11:43 +0200
commitf17275972ffde9000bb28a10b9c2e61990a44a3d (patch)
tree09839e0c03c663a32b347932c04c0c94e9072730
parent2f401ec6422a5d44fa1eb64b5b7d1d05c8075b19 (diff)
refactor(board): making generate knight moves use const reference
-rw-r--r--src/moves.cpp15
1 files 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<std::uint64_t, 64> KNIGHT_ATTACKS = computeKnightAttacks();
constexpr std::array<std::array<std::uint64_t, 64>, 2> PAWN_ATTACKS =
computePawnAttacks();
-static void GenerateKnightMoves(Game *b, std::vector<uint16_t> &moves,
+static void GenerateKnightMoves(const Game &g, std::vector<uint16_t> &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<uint8_t>(__builtin_ctzll(knights));
knights &= knights - 1;
@@ -76,11 +75,11 @@ static void GenerateKnightMoves(Game *b, std::vector<uint16_t> &moves,
uint8_t next = static_cast<uint8_t>(__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<uint16_t> GetPseudoLegalMoves(Game *g, bool GenerateQuietMoves) {
std::vector<uint16_t> moves;
moves.reserve(40);
- GenerateKnightMoves(g, moves, GenerateQuietMoves);
+ GenerateKnightMoves(*g, moves, GenerateQuietMoves);
constexpr std::array<int, 4> rook_Moves{-1, 1, 8, -8};
constexpr std::array<int, 4> bishop_Moves{-9, 9, -7, 7};