From edb54396978f099c1d72ea408a06643f91889637 Mon Sep 17 00:00:00 2001 From: Ada Joule Date: Sun, 3 Oct 2021 12:11:58 +0700 Subject: [PATCH] Expose position.fen's showPromoted and countStarted in ffish.js --- src/ffishjs.cpp | 7 ++++++- src/position.h | 2 +- src/pyffish.cpp | 2 -- tests/js/test.js | 9 +++++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/ffishjs.cpp b/src/ffishjs.cpp index 7668aab..b6defdd 100644 --- a/src/ffishjs.cpp +++ b/src/ffishjs.cpp @@ -175,6 +175,10 @@ public: return this->pos.fen(); } + std::string fen(bool showPromoted, int countStarted) const { + return this->pos.fen(false, showPromoted, countStarted); + } + void set_fen(std::string fen) { resetStates(); moveStack.clear(); @@ -615,7 +619,8 @@ EMSCRIPTEN_BINDINGS(ffish_js) { .function("pop", &Board::pop) .function("reset", &Board::reset) .function("is960", &Board::is_960) - .function("fen", &Board::fen) + .function("fen", select_overload(&Board::fen)) + .function("fen", select_overload(&Board::fen)) .function("setFen", &Board::set_fen) .function("sanMove", select_overload(&Board::san_move)) .function("sanMove", select_overload(&Board::san_move)) diff --git a/src/position.h b/src/position.h index b930fa5..a8a523d 100644 --- a/src/position.h +++ b/src/position.h @@ -1176,7 +1176,7 @@ inline int Position::game_ply() const { } inline int Position::counting_ply(int countStarted) const { - return countStarted == 0 || (count(WHITE) <= 1 || count(BLACK) <= 1) ? st->countingPly : std::min(st->countingPly, std::max(1 + gamePly - countStarted, 0)); + return countStarted == 0 || (count(WHITE) <= 1 || count(BLACK) <= 1) ? st->countingPly : countStarted < 0 ? 0 : std::min(st->countingPly, std::max(1 + gamePly - countStarted, 0)); } inline int Position::rule50_count() const { diff --git a/src/pyffish.cpp b/src/pyffish.cpp index ab2015d..785a778 100644 --- a/src/pyffish.cpp +++ b/src/pyffish.cpp @@ -230,7 +230,6 @@ extern "C" PyObject* pyffish_getFEN(PyObject* self, PyObject *args) { if (!PyArg_ParseTuple(args, "ssO!|pppi", &variant, &fen, &PyList_Type, &moveList, &chess960, &sfen, &showPromoted, &countStarted)) { return NULL; } - countStarted = std::min(countStarted, INT_MAX); // pseudo-unsigned StateListPtr states(new std::deque(1)); buildPosition(pos, states, variant, fen, moveList, chess960); @@ -304,7 +303,6 @@ extern "C" PyObject* pyffish_isOptionalGameEnd(PyObject* self, PyObject *args) { if (!PyArg_ParseTuple(args, "ssO!|pi", &variant, &fen, &PyList_Type, &moveList, &chess960, &countStarted)) { return NULL; } - countStarted = std::min(countStarted, INT_MAX); // pseudo-unsigned StateListPtr states(new std::deque(1)); buildPosition(pos, states, variant, fen, moveList, chess960); diff --git a/tests/js/test.js b/tests/js/test.js index 36dadb9..6c60626 100644 --- a/tests/js/test.js +++ b/tests/js/test.js @@ -200,6 +200,15 @@ describe('board.fen()', function () { }); }); +describe('board.fen(showPromoted, countStarted)', function () { + it("it returns the current position in fen format. showPromoted makes promoted pieces always followed by the symbol ~ regardless of variant. countStarted overwrites the start of makruk's board honor counting.", () => { + let board = new ffish.Board("makruk", "8/6ks/3M~2r1/2K1M3/8/3R4/8/8 w - 128 18 50"); + chai.expect(board.fen(true, 0)).to.equal("8/6ks/3M~2r1/2K1M3/8/3R4/8/8 w - 128 18 50"); + chai.expect(board.fen(true, -1)).to.equal("8/6ks/3M~2r1/2K1M3/8/3R4/8/8 w - 128 0 50"); + chai.expect(board.fen(true, 89)).to.equal("8/6ks/3M~2r1/2K1M3/8/3R4/8/8 w - 128 10 50"); + }); +}); + describe('board.setFen(fen)', function () { it("it sets a custom position via fen", () => { let board = new ffish.Board(); -- 1.7.0.4