From d528a20684570fb70f0e6b13a78bc6504a1edd89 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 29 Jul 2026 20:11:40 +0200 Subject: adding testing new folder structer --- src/board.cpp | 4 +-- src/bot.cpp | 2 +- src/main.cpp | 2 +- src/zobrist.cpp | 72 ------------------------------------------------- src/zobrist.hpp | 11 -------- src/zobrist/zobrist.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ src/zobrist/zobrist.hpp | 11 ++++++++ 7 files changed, 87 insertions(+), 87 deletions(-) delete mode 100644 src/zobrist.cpp delete mode 100644 src/zobrist.hpp create mode 100644 src/zobrist/zobrist.cpp create mode 100644 src/zobrist/zobrist.hpp diff --git a/src/board.cpp b/src/board.cpp index 0f33f17..43d30c0 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -1,6 +1,6 @@ #include "board.hpp" #include "moves.hpp" -#include "zobrist.hpp" +#include "zobrist/zobrist.hpp" #include Piece createPiece(PieceType type, bool color) { @@ -188,7 +188,7 @@ UndoMove MakeMove(Move move, Game *g) { if (g->halfMoveClock >= 50) { g->state = DRAW; - } + } return undo; }; diff --git a/src/bot.cpp b/src/bot.cpp index 916a311..c5e7a3b 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -1,7 +1,7 @@ #include "bot.hpp" #include "board.hpp" #include "moves.hpp" -#include "zobrist.hpp" +#include "zobrist/zobrist.hpp" #include #include #include diff --git a/src/main.cpp b/src/main.cpp index 6a71d3e..36014b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ #include "uci.hpp" -#include "zobrist.hpp" +#include "zobrist/zobrist.hpp" int main() { InitZobrist(); diff --git a/src/zobrist.cpp b/src/zobrist.cpp deleted file mode 100644 index cfc7769..0000000 --- a/src/zobrist.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include "zobrist.hpp" -#include "board.hpp" - -#include - -uint64_t PieceKeys[2][7][64]; -uint64_t SideKey; -uint64_t CastleKeys[16]; -uint64_t EnPassantKeys[8]; - -void InitZobrist() { - std::mt19937_64 rng(1234567); // fixed seed - - for (int color = 0; color < 2; color++) { - for (int piece = 0; piece < 7; piece++) { - for (int square = 0; square < 64; square++) { - PieceKeys[color][piece][square] = rng(); - } - } - } - - SideKey = rng(); - - for (int i = 0; i < 16; i++) { - CastleKeys[i] = rng(); - } - - for (int i = 0; i < 8; i++) { - EnPassantKeys[i] = rng(); - } -} - -uint64_t GenerateZobristKey(Game *b) { - uint64_t key = 0; - - for (int square = 0; square < 64; square++) { - Piece p = b->pieces[square]; - - if (p.type == NONEPIECE) - continue; - - key ^= PieceKeys[p.color][p.type][square]; - } - - // side to move - if (b->turn) - key ^= SideKey; - - // castling - int castle = 0; - - if (b->whiteCastleKing) - castle |= 1; - - if (b->whiteCastleQueen) - castle |= 2; - - if (b->blackCastleKing) - castle |= 4; - - if (b->blackCastleQueen) - castle |= 8; - - key ^= CastleKeys[castle]; - - // en passant - if (b->canEnpassant) { - key ^= EnPassantKeys[b->enPassant.file]; - } - - return key; -} diff --git a/src/zobrist.hpp b/src/zobrist.hpp deleted file mode 100644 index 8de9d42..0000000 --- a/src/zobrist.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include "board.hpp" -#include - -extern uint64_t PieceKeys[2][7][64]; -extern uint64_t SideKey; -extern uint64_t CastleKeys[16]; -extern uint64_t EnPassantKeys[8]; - -void InitZobrist(); -uint64_t GenerateZobristKey(Game *b); diff --git a/src/zobrist/zobrist.cpp b/src/zobrist/zobrist.cpp new file mode 100644 index 0000000..cfc7769 --- /dev/null +++ b/src/zobrist/zobrist.cpp @@ -0,0 +1,72 @@ +#include "zobrist.hpp" +#include "board.hpp" + +#include + +uint64_t PieceKeys[2][7][64]; +uint64_t SideKey; +uint64_t CastleKeys[16]; +uint64_t EnPassantKeys[8]; + +void InitZobrist() { + std::mt19937_64 rng(1234567); // fixed seed + + for (int color = 0; color < 2; color++) { + for (int piece = 0; piece < 7; piece++) { + for (int square = 0; square < 64; square++) { + PieceKeys[color][piece][square] = rng(); + } + } + } + + SideKey = rng(); + + for (int i = 0; i < 16; i++) { + CastleKeys[i] = rng(); + } + + for (int i = 0; i < 8; i++) { + EnPassantKeys[i] = rng(); + } +} + +uint64_t GenerateZobristKey(Game *b) { + uint64_t key = 0; + + for (int square = 0; square < 64; square++) { + Piece p = b->pieces[square]; + + if (p.type == NONEPIECE) + continue; + + key ^= PieceKeys[p.color][p.type][square]; + } + + // side to move + if (b->turn) + key ^= SideKey; + + // castling + int castle = 0; + + if (b->whiteCastleKing) + castle |= 1; + + if (b->whiteCastleQueen) + castle |= 2; + + if (b->blackCastleKing) + castle |= 4; + + if (b->blackCastleQueen) + castle |= 8; + + key ^= CastleKeys[castle]; + + // en passant + if (b->canEnpassant) { + key ^= EnPassantKeys[b->enPassant.file]; + } + + return key; +} diff --git a/src/zobrist/zobrist.hpp b/src/zobrist/zobrist.hpp new file mode 100644 index 0000000..8de9d42 --- /dev/null +++ b/src/zobrist/zobrist.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "board.hpp" +#include + +extern uint64_t PieceKeys[2][7][64]; +extern uint64_t SideKey; +extern uint64_t CastleKeys[16]; +extern uint64_t EnPassantKeys[8]; + +void InitZobrist(); +uint64_t GenerateZobristKey(Game *b); -- cgit v1.2.3