aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/board/fen.cpp56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/board/fen.cpp b/src/board/fen.cpp
index f44719a..4ac997a 100644
--- a/src/board/fen.cpp
+++ b/src/board/fen.cpp
@@ -13,26 +13,6 @@
bool WHITE = true;
bool BLACK = false;
-static void updateBitboards(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;
- }
- g->PieceBitboards[piece.color][piece.type] |= (1ULL << i);
-
- if (piece.color) {
- g->WhitePieceBitboard |= (1ULL << i);
- } else {
- g->BlackPieceBitboard |= (1ULL << i);
- }
- }
- g->PieceBitboard = g->WhitePieceBitboard | g->BlackPieceBitboard;
-}
static void SetPiece(int i, PieceType type, bool color, Game *g) {
if (i < 0 || i >= 64) {
std::println("Fatal: piece outside board");
@@ -154,32 +134,44 @@ void setBoardFen(const std::string &fen, Game *g) {
continue;
};
if (toupper(c) == 'N') {
- SetPiece((rank * 8) + file, KNIGHT, isupper(c) != 0, g);
+ bool color = isupper(c) != 0;
+ g->PieceBitboards[color][KNIGHT] |= (1ULL << ((rank * 8) + file));
+ SetPiece((rank * 8) + file, KNIGHT, color, g);
file++;
continue;
};
if (toupper(c) == 'R') {
- SetPiece((rank * 8) + file, ROOK, isupper(c) != 0, g);
+ bool color = isupper(c) != 0;
+ g->PieceBitboards[color][ROOK] |= (1ULL << ((rank * 8) + file));
+ SetPiece((rank * 8) + file, ROOK, color, g);
file++;
continue;
}
if (toupper(c) == 'Q') {
- SetPiece((rank * 8) + file, QUEEN, isupper(c) != 0, g);
+ bool color = isupper(c) != 0;
+ g->PieceBitboards[color][QUEEN] |= (1ULL << ((rank * 8) + file));
+ SetPiece((rank * 8) + file, QUEEN, color, g);
file++;
continue;
}
if (toupper(c) == 'B') {
- SetPiece((rank * 8) + file, BISHOP, isupper(c) != 0, g);
+ bool color = isupper(c) != 0;
+ g->PieceBitboards[color][BISHOP] |= (1ULL << ((rank * 8) + file));
+ SetPiece((rank * 8) + file, BISHOP, color, g);
file++;
continue;
}
if (toupper(c) == 'P') {
- SetPiece((rank * 8) + file, PAWN, isupper(c) != 0, g);
+ bool color = isupper(c) != 0;
+ g->PieceBitboards[color][PAWN] |= (1ULL << ((rank * 8) + file));
+ SetPiece((rank * 8) + file, PAWN, color, g);
file++;
continue;
}
if (toupper(c) == 'K') {
- SetPiece((rank * 8) + file, KING, isupper(c) != 0, g);
+ bool color = isupper(c) != 0;
+ g->PieceBitboards[color][KING] |= (1ULL << ((rank * 8) + file));
+ SetPiece((rank * 8) + file, KING, color, g);
file++;
continue;
}
@@ -188,7 +180,17 @@ void setBoardFen(const std::string &fen, Game *g) {
}
g->enPassant = enpassant;
- updateBitboards(g);
+ g->WhitePieceBitboard =
+ g->PieceBitboards[1][PAWN] | g->PieceBitboards[1][KNIGHT] |
+ g->PieceBitboards[1][BISHOP] | g->PieceBitboards[1][ROOK] |
+ g->PieceBitboards[1][QUEEN] | g->PieceBitboards[1][KING];
+
+ g->BlackPieceBitboard =
+ g->PieceBitboards[0][PAWN] | g->PieceBitboards[0][KNIGHT] |
+ g->PieceBitboards[0][BISHOP] | g->PieceBitboards[0][ROOK] |
+ g->PieceBitboards[0][QUEEN] | g->PieceBitboards[0][KING];
+
+ g->PieceBitboard = g->WhitePieceBitboard | g->BlackPieceBitboard;
int whiteKingCount = __builtin_popcountll(g->PieceBitboards[true][KING]);
int blackKingCount = __builtin_popcountll(g->PieceBitboards[false][KING]);