From e4381feb7a039d7fd790258d4294681dc203d70d Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Fri, 28 Dec 2018 14:20:37 +0100 Subject: [PATCH] Re-initialize PSQTs for each variant This allows to consider the board size of the variant when initializing the PSQTs, which fixes some issues with non-standard board sizes, and reduces the differences between the normal and the large-board version. No functional change for 8x8 variants. --- src/main.cpp | 4 ++-- src/psqt.cpp | 5 +++-- src/ucioption.cpp | 7 ++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e4a5cbc..6d697bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,7 @@ #include "syzygy/tbprobe.h" namespace PSQT { - void init(); + void init(const Variant* v); } int main(int argc, char* argv[]) { @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) { variants.init(); UCI::init(Options); - PSQT::init(); + PSQT::init(variants.find("chess")->second); Bitboards::init(); Position::init(); Bitbases::init(); diff --git a/src/psqt.cpp b/src/psqt.cpp index 82544cb..7c26957 100644 --- a/src/psqt.cpp +++ b/src/psqt.cpp @@ -21,6 +21,7 @@ #include #include "types.h" +#include "variant.h" Value PieceValue[PHASE_NB][PIECE_NB] = { { VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg, @@ -114,7 +115,7 @@ Score psq[PIECE_NB][SQUARE_NB + 1]; // init() initializes piece-square tables: the white halves of the tables are // copied from Bonus[] adding the piece value, then the black halves of the // tables are initialized by flipping and changing the sign of the white scores. -void init() { +void init(const Variant* v) { for (PieceType pt = PAWN; pt <= KING; ++pt) { @@ -127,7 +128,7 @@ void init() { for (Square s = SQ_A1; s <= SQ_MAX; ++s) { - File f = std::min(file_of(s), ~file_of(s)); + File f = std::max(std::min(file_of(s), File(v->maxFile - file_of(s))), FILE_A); psq[ pc][ s] = score + (pt == KING ? KingBonus[std::min(rank_of(s), RANK_8)][std::min(f, FILE_D)] : Bonus[pc][std::min(rank_of(s), RANK_8)][std::min(f, FILE_D)]); psq[~pc][~s] = -psq[pc][s]; } diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 2df5730..35fc4f0 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -34,6 +34,10 @@ using std::string; UCI::OptionsMap Options; // Global object +namespace PSQT { + void init(const Variant* v); +} + namespace UCI { /// 'On change' actions, triggered by an option's value change @@ -43,7 +47,8 @@ void on_logger(const Option& o) { start_logger(o); } void on_threads(const Option& o) { Threads.set(o); } void on_tb_path(const Option& o) { Tablebases::init(o); } void on_variant_change(const Option &o) { - const Variant * v = variants.find(o)->second; + const Variant* v = variants.find(o)->second; + PSQT::init(v); sync_cout << "info string variant " << (std::string)o << " files " << v->maxFile + 1 << " ranks " << v->maxRank + 1 -- 1.7.0.4