From 78700852f96db30149f1105f80364d092d12d90f Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Tue, 27 Jul 2021 22:15:31 +0200 Subject: [PATCH] Fix variant initialization for libraries --- .github/workflows/ffishjs.yml | 2 +- src/ffishjs.cpp | 1 + src/pyffish.cpp | 2 +- src/uci.h | 4 ++++ src/ucioption.cpp | 8 ++++++-- test.py | 5 +++++ tests/js/test.js | 3 +++ 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ffishjs.yml b/.github/workflows/ffishjs.yml index 7177f0e..b26553f 100644 --- a/.github/workflows/ffishjs.yml +++ b/.github/workflows/ffishjs.yml @@ -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 diff --git a/src/ffishjs.cpp b/src/ffishjs.cpp index bc67016..7668aab 100644 --- a/src/ffishjs.cpp +++ b/src/ffishjs.cpp @@ -372,6 +372,7 @@ private: Board::sfInitialized = true; } v = get_variant(uciVariant); + UCI::init_variant(v); this->resetStates(); if (fen == "") fen = v->startFen; diff --git a/src/pyffish.cpp b/src/pyffish.cpp index e2dfc9c..987cf73 100644 --- a/src/pyffish.cpp +++ b/src/pyffish.cpp @@ -28,9 +28,9 @@ void buildPosition(Position& pos, StateListPtr& states, const char *variant, con states = StateListPtr(new std::deque(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 diff --git a/src/uci.h b/src/uci.h index edeaab9..133f88f 100644 --- a/src/uci.h +++ b/src/uci.h @@ -25,12 +25,16 @@ #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 diff --git a/src/ucioption.cpp b/src/ucioption.cpp index c17678a..8618bb8 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -51,6 +51,11 @@ std::set 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 --- 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) diff --git a/tests/js/test.js b/tests/js/test.js index 2e3b432..36dadb9 100644 --- a/tests/js/test.js +++ b/tests/js/test.js @@ -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(); }); }); -- 1.7.0.4