From f83bb43c6a3435e18ddca55c17f69174a64a7cf0 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 11 Aug 2026 10:33:29 +0200 Subject: modernizing the code --- src/moves.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/moves.cpp b/src/moves.cpp index c1c6a0a..a130055 100644 --- a/src/moves.cpp +++ b/src/moves.cpp @@ -9,7 +9,7 @@ #include "board/board.hpp" #include "moves.hpp" -constexpr uint64_t KNIGHT_ATTACKS[64] = { +constexpr std::array KNIGHT_ATTACKS = { 0x0000000000020400ULL, 0x0000000000050800ULL, 0x00000000000A1100ULL, 0x0000000000142200ULL, 0x0000000000284400ULL, 0x0000000000508800ULL, 0x0000000000A01000ULL, 0x0000000000402000ULL, 0x0000000002040004ULL, @@ -39,7 +39,7 @@ static void GenerateKnightMoves(Game *b, std::vector &moves, while (knights != 0) { int from = __builtin_ctzll(knights); knights &= knights - 1; - uint64_t knight_attacks = KNIGHT_ATTACKS[from]; + uint64_t knight_attacks = KNIGHT_ATTACKS[static_cast(from)]; while (knight_attacks != 0) { int next = __builtin_ctzll(knight_attacks); knight_attacks &= knight_attacks - 1; @@ -51,17 +51,19 @@ static void GenerateKnightMoves(Game *b, std::vector &moves, if (fileDelta != 1 && fileDelta != 2) { continue; }; - bool hasFriendlyPiece = b->turn - ? (b->WhitePieceBitboard & (1ULL << (next))) - : (b->BlackPieceBitboard & (1ULL << (next))); - bool isCaptuared = b->PieceBitboard & (1ULL << next); + bool hasFriendlyPiece = + b->turn ? (b->WhitePieceBitboard & (1ULL << next)) > 0 + : (b->BlackPieceBitboard & (1ULL << next)) > 0; + + bool isCaptuare = (b->PieceBitboard & (1ULL << next)) > 0; if (hasFriendlyPiece) { continue; } - if (!GenerateQuietMoves && !isCaptuared) { + if (!GenerateQuietMoves && !isCaptuare) { continue; } - moves.push_back({IndexToPosition(from), IndexToPosition(next)}); + moves.push_back( + {.From = IndexToPosition(from), .To = IndexToPosition(next)}); } } }; -- cgit v1.2.3