aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/board/board.cpp9
-rw-r--r--src/board/board.hpp2
-rw-r--r--src/moves.cpp15
-rw-r--r--src/uci.cpp32
4 files changed, 38 insertions, 20 deletions
diff --git a/src/board/board.cpp b/src/board/board.cpp
index 572a3f0..2257010 100644
--- a/src/board/board.cpp
+++ b/src/board/board.cpp
@@ -259,6 +259,8 @@ void UnMakeMove(UndoMove undo, Game *g) {
};
void UpdateHelpers(Game *g) {
g->PieceBitboard = 0;
+ g->WhitePieceBitboard = 0;
+ g->BlackPieceBitboard = 0;
for (uint8_t i = 0; i < 64; i++) {
Piece piece = g->pieces[i];
if (piece.type == NONEPIECE) {
@@ -271,8 +273,13 @@ void UpdateHelpers(Game *g) {
g->BlackKingPosition = i;
}
}
- g->PieceBitboard |= (1ULL << i);
+ if (piece.color) {
+ g->WhitePieceBitboard |= (1ULL << i);
+ } else {
+ g->BlackPieceBitboard |= (1ULL << i);
+ }
}
+ 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 869e223..e754991 100644
--- a/src/board/board.hpp
+++ b/src/board/board.hpp
@@ -53,6 +53,8 @@ struct TranspositionsEntry {
struct Game {
Piece pieces[64];
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;
bool turn = true; // 1 white; 0 black
diff --git a/src/moves.cpp b/src/moves.cpp
index 803538b..17d6814 100644
--- a/src/moves.cpp
+++ b/src/moves.cpp
@@ -28,13 +28,14 @@ void GenerateKnightMoves(Game *b, int from, std::vector<Move> &moves,
if (fileDelta != 1 && fileDelta != 2) {
continue;
};
- if (b->pieces[next].type != NONEPIECE) {
- if (b->pieces[next].color == b->turn) {
- continue;
- };
+ bool hasFriendlyPiece = b->turn
+ ? (b->WhitePieceBitboard & (1ULL << (next)))
+ : (b->BlackPieceBitboard & (1ULL << (next)));
+ bool isCaptuare = b->PieceBitboard & (1ULL << next);
+ if (hasFriendlyPiece) {
+ continue;
}
-
- if (!GenerateQuietMoves && b->pieces[next].type == NONEPIECE) {
+ if (!GenerateQuietMoves && isCaptuare) {
continue;
}
moves.push_back({IndexToPosition(from), IndexToPosition(next)});
@@ -92,7 +93,7 @@ void GeneratePawnMoves(Game *b, int from, std::vector<Move> &moves,
int target = targetRank * 8 + targetFile;
if (IndexToPosition(target) == b->enPassant && b->canEnpassant) {
- moves.push_back({position, IndexToPosition(target)});
+ moves.push_back({positiopn, IndexToPosition(target)});
}
if (b->pieces[target].type != NONEPIECE &&
diff --git a/src/uci.cpp b/src/uci.cpp
index f099b78..94e5693 100644
--- a/src/uci.cpp
+++ b/src/uci.cpp
@@ -1,26 +1,25 @@
-#include "uci.hpp"
-#include "board/board.hpp"
-#include "board/fen.hpp"
-#include "bot.hpp"
-#include "misc.hpp"
-#include "moves.hpp"
-#include "zobrist.hpp"
-
#include <algorithm>
#include <cassert>
#include <cctype>
+#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
+#include <fstream>
+#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
-
-#include <chrono>
-#include <fstream>
-#include <iomanip>
#include <unordered_map>
+#include "board/board.hpp"
+#include "board/fen.hpp"
+#include "bot.hpp"
+#include "misc.hpp"
+#include "moves.hpp"
+#include "uci.hpp"
+#include "zobrist.hpp"
+
std::ofstream uciLog("cache/uci_log.txt", std::ios::app);
void LogUci(const std::string &message) {
@@ -210,9 +209,18 @@ void Uci() {
cout.flush();
continue;
}
+
+ auto start = std::chrono::steady_clock::now();
+
uint64_t count = MoveGenTest(depth, &game);
+ auto end = std::chrono::steady_clock::now();
+ auto ms =
+ std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
+ .count();
+ std::cout << ms << " ms\n";
cout << count << "\n";
+
cout.flush();
}
}