Re-initialize PSQTs for each variant
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 28 Dec 2018 13:20:37 +0000 (14:20 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 28 Dec 2018 13:20:37 +0000 (14:20 +0100)
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
src/psqt.cpp
src/ucioption.cpp

index e4a5cbc..6d697bb 100644 (file)
@@ -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();
index 82544cb..7c26957 100644 (file)
@@ -21,6 +21,7 @@
 #include <algorithm>
 
 #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];
       }
index 2df5730..35fc4f0 100644 (file)
@@ -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