Fix variant initialization for libraries
authorFabian Fichter <ianfab@users.noreply.github.com>
Tue, 27 Jul 2021 20:15:31 +0000 (22:15 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Thu, 29 Jul 2021 06:15:58 +0000 (08:15 +0200)
.github/workflows/ffishjs.yml
src/ffishjs.cpp
src/pyffish.cpp
src/uci.h
src/ucioption.cpp
test.py
tests/js/test.js

index 7177f0e..b26553f 100644 (file)
@@ -36,7 +36,7 @@ jobs:
           node-version: ${{ matrix.node-version }}
       - name: Build ffishjs
         working-directory: src
-        run: make -f Makefile_js build debug=yes optimize=no
+        run: make -f Makefile_js build debug=yes
       - name: Install dependencies
         working-directory: tests/js
         run: npm install
index bc67016..7668aab 100644 (file)
@@ -372,6 +372,7 @@ private:
       Board::sfInitialized = true;
     }
     v = get_variant(uciVariant);
+    UCI::init_variant(v);
     this->resetStates();
     if (fen == "")
       fen = v->startFen;
index e2dfc9c..987cf73 100644 (file)
@@ -28,9 +28,9 @@ void buildPosition(Position& pos, StateListPtr& states, const char *variant, con
     states = StateListPtr(new std::deque<StateInfo>(1)); // Drop old and create a new one
 
     const Variant* v = variants.find(std::string(variant))->second;
+    UCI::init_variant(v);
     if (strcmp(fen, "startpos") == 0)
         fen = v->startFen.c_str();
-    Options["UCI_Chess960"] = chess960;
     pos.set(v, std::string(fen), chess960, &states->back(), Threads.main());
 
     // parse move list
index edeaab9..133f88f 100644 (file)
--- a/src/uci.h
+++ b/src/uci.h
 
 #include "types.h"
 
+#include "variant.h"
+
 namespace Stockfish {
 
 class Position;
 
 namespace UCI {
 
+void init_variant(const Variant* v);
+
 class Option;
 
 /// Custom comparator because UCI options should be case insensitive
index c17678a..8618bb8 100644 (file)
@@ -51,6 +51,11 @@ std::set<string> standard_variants = {
     "capablanca", "gothic", "janus", "caparandom", "grand", "shogi", "xiangqi"
 };
 
+void init_variant(const Variant* v) {
+    pieceMap.init(v);
+    Bitboards::init_pieces();
+}
+
 /// 'On change' actions, triggered by an option's value change
 void on_clear_hash(const Option&) { Search::clear(); }
 void on_hash_size(const Option& o) { TT.resize(size_t(o)); }
@@ -67,8 +72,7 @@ void on_variant_set(const Option &o) {
     Eval::NNUE::init();
 
     const Variant* v = variants.find(o)->second;
-    pieceMap.init(v);
-    Bitboards::init_pieces();
+    init_variant(v);
     PSQT::init(v);
 }
 void on_variant_change(const Option &o) {
diff --git a/test.py b/test.py
index 13d2c85..bc17df2 100644 (file)
--- a/test.py
+++ b/test.py
@@ -284,6 +284,11 @@ class TestPyffish(unittest.TestCase):
         result = sf.legal_moves("diana", "rbnk1r/pppbpp/3p2/5P/PPPPPB/RBNK1R w KQkq - 2 3", [])
         self.assertIn("d1f1", result)
 
+        # Test configurable piece perft
+        legals = ['a3a4', 'b3b4', 'c3c4', 'd3d4', 'e3e4', 'f3f4', 'g3g4', 'e1e2', 'f1f2', 'b1a2', 'b1b2', 'b1c2', 'c1b2', 'c1c2', 'c1d2', 'a1a2', 'g1g2', 'd1c2', 'd1d2', 'd1e2']
+        result = sf.legal_moves("yarishogi", sf.start_fen("yarishogi"), [])
+        self.assertCountEqual(legals, result)
+
     def test_get_fen(self):
         result = sf.get_fen("chess", CHESS, [])
         self.assertEqual(result, CHESS)
index 2e3b432..36dadb9 100644 (file)
@@ -110,6 +110,9 @@ describe('board.numberLegalMoves()', function () {
     const board = new ffish.Board("crazyhouse", "r1b3nr/pppp1kpp/2n5/2b1p3/4P3/2N5/PPPP1PPP/R1B1K1NR/QPbq w KQ - 0 7");
     chai.expect(board.numberLegalMoves()).to.equal(90);
     board.delete();
+    const yariboard = new ffish.Board("yarishogi");
+    chai.expect(yariboard.numberLegalMoves()).to.equal(20);
+    yariboard.delete();
   });
 });