From c5891a499f180da91aa14ad7273f00092a7b3e45 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 17 Aug 2026 20:01:05 +0200 Subject: adding zobrist hashing --- src/uci.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/uci.cpp') diff --git a/src/uci.cpp b/src/uci.cpp index 6c035d5..23e8419 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -14,6 +14,7 @@ #include "board/board.hpp" #include "board/fen.hpp" #include "bot.hpp" +#include "book.hpp" #include "misc.hpp" #include "moves.hpp" #include "uci.hpp" @@ -222,13 +223,25 @@ static void GoCommand(Game *game, std::string &cmd) { std::cout << "Fatal: Depth must be positive integer"; exit(1); } - move_options options = { - .wtime = wtime, - .btime = btime, - .wncr = wncr, - .bncr = bncr, - }; - uint16_t best = GetBestMove(game, depth, options); + + // Try opening book first + uint16_t bookMove = 0; + if (game->MoveClock < GetBookDepth()) { + bookMove = ProbeBook(GenerateZobristKey(game)); + } + + uint16_t best; + if (bookMove != 0) { + best = bookMove; + } else { + move_options options = { + .wtime = wtime, + .btime = btime, + .wncr = wncr, + .bncr = bncr, + }; + best = GetBestMove(game, depth, options); + } Piece piece = game->pieces[getFromValueFromMove(best)]; @@ -309,6 +322,8 @@ void Uci() { Game game = initBoard(starting_fen, &transpositions); std::string cmd; + InitBook("book.bin"); + while (getline(std::cin, cmd)) { if (cmd == "quit") { return; @@ -342,5 +357,9 @@ void Uci() { if (cmd == "moves") { movesCommnad(&game); } + if (cmd == "hash") { + uint64_t hash = GenerateZobristKey(&game); + std::cout << hash << "\n"; + } } } -- cgit v1.2.3