stellar

Stellar - UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

commit 8bab42ac758595bc29cfc1ae86398a57e72cd963
parent 362cc43b8bc8a4e5519238dc587ddd0b8eb30ee2
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Wed, 30 Aug 2023 20:07:52 +0200

General Search Improvement

Diffstat:
MCMakeLists.txt | 2+-
Msrc/engine/CMakeLists.txt | 7-------
Msrc/engine/engine.cpp | 29++++++++++++-----------------
Msrc/move/move.hpp | 2+-
Msrc/move/movelist.cpp | 8--------
Msrc/move/movelist.hpp | 1-
6 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -3,7 +3,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) project( Stellar - VERSION 0.0.25 + VERSION 0.0.26 DESCRIPTION "Chess engine written in C" HOMEPAGE_URL https://git.dimitrijedobrota.com/stellar.git LANGUAGES C CXX diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt @@ -11,13 +11,6 @@ target_link_libraries(engine PRIVATE utils ) -stellar_target_precompile_headers(board - PRIVATE "board.hpp" - PRIVATE "move.hpp" - PRIVATE "movelist.hpp" - PRIVATE "piece.hpp" -) - set_target_properties(engine PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp @@ -98,22 +98,19 @@ U32 inline move_list_score(Move move) { return history[piece::get_index(type, board.get_side())][to_underlying(move.target())]; } -Move move_list_best_move; -void move_list_sort(MoveList &list, std::vector<int> &index, bool bestCheck = true) { +std::vector<int> move_list_sort(MoveList &list, const Move best) { static std::vector<int> score(256); - bool best = false; + bool best_found = false; for (int i = 0; i < list.size(); i++) { score[i] = move_list_score(list[i]); - index[i] = i; - if (bestCheck && list[i] == move_list_best_move) { + if (list[i] == best) { score[i] = 30000; - bestCheck = false; - best = true; + best_found = true; } } - if (!best && ply && follow_pv) { + if (!best_found && ply && follow_pv) { follow_pv = false; for (int i = 0; i < list.size(); i++) { if (list[i] == pv_table[0][ply]) { @@ -124,7 +121,10 @@ void move_list_sort(MoveList &list, std::vector<int> &index, bool bestCheck = tr } } - sort(index.begin(), index.begin() + list.size(), [&](int a, int b) { return score[a] > score[b]; }); + std::vector<int> index(list.size()); + std::iota(begin(index), end(index), 0); + sort(begin(index), end(index), [&](int a, int b) { return score[a] > score[b]; }); + return index; } int evaluate(const Board &board) { @@ -200,9 +200,7 @@ int quiescence(int16_t alpha, int16_t beta) { Board copy; MoveList list(board); - std::vector<int> index(list.size()); - move_list_sort(list, index, false); - for (int idx : index) { + for (int idx : move_list_sort(list, Move())) { if (!stats_move_make(copy, list[idx], 1)) continue; score = -quiescence(-beta, -alpha); stats_move_unmake(copy); @@ -300,11 +298,8 @@ int negamax(int16_t alpha, int16_t beta, uint8_t depth, bool null) { int legal_moves = 0; int searched = 0; - move_list_best_move = bestMove; MoveList list(board); - std::vector<int> index(list.size()); - move_list_sort(list, index); - for (int idx : index) { + for (int idx : move_list_sort(list, bestMove)) { const Move move = list[idx]; if (!stats_move_make(copy, move, 0)) continue; legal_moves++; @@ -380,7 +375,7 @@ void search_position(const uci::Settings &settingsr) { settings = &settingsr; if (settings->newgame) { - ttable = TTable(C64(0x400000)); + ttable = TTable(C64(0x1000000)); } ply = 0; diff --git a/src/move/move.hpp b/src/move/move.hpp @@ -26,7 +26,7 @@ struct Move { PCQUEEN, }; - Move() = default; + Move() : source_i(0), target_i(0), flags_i(0) {} Move(Square source, Square target, Flag flags) : source_i(to_underlying(source)), target_i(to_underlying(target)), flags_i(flags) {} diff --git a/src/move/movelist.cpp b/src/move/movelist.cpp @@ -10,17 +10,9 @@ ((color == Color::BLACK && source >= Square::a7 && source <= Square::h7) || \ (color == Color::WHITE && source >= Square::a2 && source <= Square::h2)) -using piece::Type::BISHOP; -using piece::Type::KING; -using piece::Type::KNIGHT; -using piece::Type::NONE; using piece::Type::PAWN; -using piece::Type::QUEEN; -using piece::Type::ROOK; void MoveList::generate(const Board &board) { - this->clear(); - uint8_t src_i, tgt_i; Color color = board.get_side(); diff --git a/src/move/movelist.hpp b/src/move/movelist.hpp @@ -29,7 +29,6 @@ class MoveList { private: void generate(const Board &board); - void clear() { list.clear(); } list_t list; };