aboutsummaryrefslogtreecommitdiff
path: root/src/board
diff options
context:
space:
mode:
Diffstat (limited to 'src/board')
-rw-r--r--src/board/board.cpp33
-rw-r--r--src/board/board.hpp3
2 files changed, 7 insertions, 29 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 {
diff --git a/src/board/board.hpp b/src/board/board.hpp
index e754991..50d38ed 100644
--- a/src/board/board.hpp
+++ b/src/board/board.hpp
@@ -55,8 +55,7 @@ struct Game {
uint64_t PieceBitboard = 0; // used for quicly iterating over all squares
uint64_t WhitePieceBitboard = 0;
uint64_t BlackPieceBitboard = 0;
- uint8_t WhiteKingPosition = 0;
- uint8_t BlackKingPosition = 0;
+ uint64_t PieceBitboards[2][7] = {};
bool turn = true; // 1 white; 0 black
bool whiteCastleKing = false;
bool whiteCastleQueen = false;