aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-08-10 15:04:37 +0200
committerAdam <adammegarules1@gmail.com>2026-08-10 15:04:37 +0200
commitfa99aa2d53eb1f784b6e7bb4971cf36092488957 (patch)
tree3f532bce9a114859cef834b6f3989399737940df /src
parent6a39e28205d44e96da72728c0a3d4d6468962539 (diff)
making fen parser be self contained
Diffstat (limited to 'src')
-rw-r--r--src/board/board.cpp3
-rw-r--r--src/board/board.hpp1
-rw-r--r--src/board/fen.cpp35
3 files changed, 34 insertions, 5 deletions
diff --git a/src/board/board.cpp b/src/board/board.cpp
index 676a7de..c02aac5 100644
--- a/src/board/board.cpp
+++ b/src/board/board.cpp
@@ -324,6 +324,3 @@ void UpdateHelpers(Game *g) {
}
g->PieceBitboard = g->WhitePieceBitboard | g->BlackPieceBitboard;
}
-void SetPiece(int i, PieceType type, bool color, Game *g) {
- g->pieces[i] = {.color = color, .type = type};
-}
diff --git a/src/board/board.hpp b/src/board/board.hpp
index 50d38ed..d93f6ae 100644
--- a/src/board/board.hpp
+++ b/src/board/board.hpp
@@ -106,5 +106,4 @@ void UnMakeMove(UndoMove undo, Game *g);
Position FindKing(Game *g, bool white);
void UpdateHelpers(Game *g);
-void SetPiece(int i, PieceType type, bool color, Game *g);
#endif /* SRC_BOARD_H_ */
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);
}