From: Fabian Fichter Date: Sun, 28 Nov 2021 19:31:31 +0000 (+0100) Subject: Fix disambiguation of special moves X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=08e9de6eff8f2a4b79b52cfc1f9051f3457e42bc;p=fairystockfish.git Fix disambiguation of special moves Closes #408. --- diff --git a/setup.py b/setup.py index a243af9..fe882e6 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ pyffish_module = Extension( sources=sources, extra_compile_args=args) -setup(name="pyffish", version="0.0.66", +setup(name="pyffish", version="0.0.67", description="Fairy-Stockfish Python wrapper", long_description=long_description, long_description_content_type="text/markdown", diff --git a/src/apiutil.h b/src/apiutil.h index 0cd7bc7..f316cca 100644 --- a/src/apiutil.h +++ b/src/apiutil.h @@ -206,8 +206,11 @@ inline Disambiguation disambiguation_level(const Position& pos, Move m, Notation while (b) { Square s = pop_lsb(b); - if ( pos.pseudo_legal(make_move(s, to)) - && pos.legal(make_move(s, to)) + // Construct a potential move with identical special move flags + // and only a different "from" square. + Move testMove = Move(m ^ make_move(from, to) ^ make_move(s, to)); + if ( pos.pseudo_legal(testMove) + && pos.legal(testMove) && !(is_shogi(n) && pos.unpromoted_piece_on(s) != pos.unpromoted_piece_on(from))) others |= s; } diff --git a/src/pyffish.cpp b/src/pyffish.cpp index a80b216..71d6ec1 100644 --- a/src/pyffish.cpp +++ b/src/pyffish.cpp @@ -54,7 +54,7 @@ void buildPosition(Position& pos, StateListPtr& states, const char *variant, con } extern "C" PyObject* pyffish_version(PyObject* self) { - return Py_BuildValue("(iii)", 0, 0, 66); + return Py_BuildValue("(iii)", 0, 0, 67); } extern "C" PyObject* pyffish_info(PyObject* self) { diff --git a/test.py b/test.py index edcd37b..cb580b5 100644 --- a/test.py +++ b/test.py @@ -512,6 +512,13 @@ class TestPyffish(unittest.TestCase): result = sf.get_san("shogi", SHOGI, "f1e2", False, sf.NOTATION_SHOGI_HODGES_NUMBER) self.assertEqual(result, "G49-58") + # Disambiguation of promotion moves + fen = "p1ksS/n1n2/4P/5/+L1K1+L[] b - - 3 9" + result = sf.get_san("kyotoshogi", fen, "c4b2+", False, sf.NOTATION_SHOGI_HODGES_NUMBER) + self.assertEqual(result, "N32-44+") + result = sf.get_san("kyotoshogi", fen, "a4b2+", False, sf.NOTATION_SHOGI_HODGES_NUMBER) + self.assertEqual(result, "N52-44+") + fen = "lnsgkgsnl/1r5b1/pppppp1pp/6p2/9/2P6/PP1PPPPPP/1B5R1/LNSGKGSNL w -" result = sf.get_san("shogi", fen, "b2h8", False, sf.NOTATION_SHOGI_HODGES) self.assertEqual(result, "Bx2b=") @@ -648,6 +655,13 @@ class TestPyffish(unittest.TestCase): result = sf.get_san("seirawan", fen, "h1e1e") self.assertEqual(result, "O-O/Eh1") + # Disambiguation only when necessary + fen = "rnbqkb1r/ppp1pppp/5n2/3p4/3P4/5N2/PPP1PPPP/RNBQKB1R[EHeh] w KQABCDEFHkqabcdefh - 2 3" + result = sf.get_san("seirawan", fen, "b1d2e") + self.assertEqual(result, "Nd2/E") + result = sf.get_san("seirawan", fen, "b1d2") + self.assertEqual(result, "Nbd2") + def test_get_san_moves(self): UCI_moves = ["e2e4", "e7e5", "g1f3", "b8c6h", "f1c4", "f8c5e"] SAN_moves = ["e4", "e5", "Nf3", "Nc6/H", "Bc4", "Bc5/E"]