diff options
| author | Adam <adammegarules1@gmail.com> | 2026-08-11 10:33:29 +0200 |
|---|---|---|
| committer | Adam <adammegarules1@gmail.com> | 2026-08-11 10:33:29 +0200 |
| commit | f83bb43c6a3435e18ddca55c17f69174a64a7cf0 (patch) | |
| tree | 33278c58d57417d1834fa1e7d62e1aa134bcddfb /src/moves.cpp | |
| parent | b806cc058bd001dbfbc28412d29eae7f4d8005df (diff) | |
modernizing the code
Diffstat (limited to 'src/moves.cpp')
| -rw-r--r-- | src/moves.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
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<uint64_t, 64> KNIGHT_ATTACKS = { 0x0000000000020400ULL, 0x0000000000050800ULL, 0x00000000000A1100ULL, 0x0000000000142200ULL, 0x0000000000284400ULL, 0x0000000000508800ULL, 0x0000000000A01000ULL, 0x0000000000402000ULL, 0x0000000002040004ULL, @@ -39,7 +39,7 @@ static void GenerateKnightMoves(Game *b, std::vector<Move> &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<size_t>(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<Move> &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)}); } } }; |
