diff options
Diffstat (limited to 'src/board/board.cpp')
| -rw-r--r-- | src/board/board.cpp | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/src/board/board.cpp b/src/board/board.cpp index b4c058a..e68bf80 100644 --- a/src/board/board.cpp +++ b/src/board/board.cpp @@ -1,6 +1,7 @@ #include <cassert> #include <cstdint> #include <cstdlib> +#include <cstring> #include "board.hpp" #include "moves.hpp" @@ -9,26 +10,8 @@ int PositionToIndex(Position i) { return i.rank * 8 + i.file; } Position FindKing(Game *b, bool color) { - if (b->WhiteKingPosition >= 64) { - assert(false && "weird position"); - exit(1); - } - if (b->BlackKingPosition >= 64) { - assert(false && "weird position"); - exit(1); - } - if (b->pieces[b->WhiteKingPosition].color != true || - b->pieces[b->WhiteKingPosition].type != KING) { - assert(false && "Expected king at king position"); - exit(1); - } - if (b->pieces[b->BlackKingPosition].color != false || - b->pieces[b->BlackKingPosition].type != KING) { - assert(false && "Expected king at king position"); - exit(1); - } - return color ? IndexToPosition(b->WhiteKingPosition) - : IndexToPosition(b->BlackKingPosition); + + return IndexToPosition(__builtin_ctzll(b->PieceBitboards[color][KING])); } UndoMove MakeMove(Move move, Game *g) { UndoMove undo = {}; @@ -262,18 +245,14 @@ void UpdateHelpers(Game *g) { g->PieceBitboard = 0; g->WhitePieceBitboard = 0; g->BlackPieceBitboard = 0; + std::memset(g->PieceBitboards, 0, sizeof(g->PieceBitboards)); for (uint8_t i = 0; i < 64; i++) { Piece piece = g->pieces[i]; if (piece.type == NONEPIECE) { continue; } - if (piece.type == KING) { - if (piece.color) { - g->WhiteKingPosition = i; - } else { - g->BlackKingPosition = i; - } - } + g->PieceBitboards[piece.color][piece.type] |= (1ULL << i); + if (piece.color) { g->WhitePieceBitboard |= (1ULL << i); } else { |
