aboutsummaryrefslogtreecommitdiff
path: root/src/board/fen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/board/fen.cpp')
-rw-r--r--src/board/fen.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/board/fen.cpp b/src/board/fen.cpp
index c4c5e7a..5f27e68 100644
--- a/src/board/fen.cpp
+++ b/src/board/fen.cpp
@@ -3,6 +3,7 @@
#include <cassert>
#include <cctype>
#include <cstdlib>
+#include <cstring>
#include <print>
#include <string>
#include <sys/types.h>
@@ -10,7 +11,39 @@
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) {
+ g->pieces[i] = {.color = color, .type = type};
+}
+
void setBoardFen(const std::string fen, Game *g) {
+ for (int i = 0; i < 64; ++i) {
+ g->pieces[i] = {.color = false, .type = NONEPIECE};
+ }
+ g->blackCastleKing = false;
+ g->blackCastleQueen = false;
+ g->whiteCastleKing = false;
+ g->whiteCastleQueen = false;
+
// example fen rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
int file = 0;
int rank = 7;
@@ -145,5 +178,5 @@ void setBoardFen(const std::string fen, Game *g) {
break;
}
g->enPassant = enpassant;
- UpdateHelpers(g);
+ updateBitboards(g);
}