From a4d80eb0a78adf605fe28ac1c1ca4c8a3e9f5b1e Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Wed, 2 Feb 2022 20:50:35 +0100 Subject: [PATCH] Fix SAN generation for demotions And use more consistent uppercase conversion. --- setup.py | 2 +- src/apiutil.h | 10 +++++----- src/pyffish.cpp | 2 +- test.py | 5 +++++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 87582b9..61ac464 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.68", +setup(name="pyffish", version="0.0.69", 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 11a599d..d82653b 100644 --- a/src/apiutil.h +++ b/src/apiutil.h @@ -254,7 +254,7 @@ inline const std::string move_to_san(Position& pos, Move m, Notation n) { if (is_gating(m)) { - san += std::string("/") + pos.piece_to_char()[make_piece(WHITE, gating_type(m))]; + san += std::string("/") + (char)toupper(pos.piece_to_char()[make_piece(us, gating_type(m))]); san += square(pos, gating_square(m), n); } } @@ -292,15 +292,15 @@ inline const std::string move_to_san(Position& pos, Move m, Notation n) { // Suffix if (type_of(m) == PROMOTION) - san += std::string("=") + pos.piece_to_char()[make_piece(WHITE, promotion_type(m))]; + san += std::string("=") + (char)toupper(pos.piece_to_char()[make_piece(us, promotion_type(m))]); else if (type_of(m) == PIECE_PROMOTION) - san += is_shogi(n) ? std::string("+") : std::string("=") + pos.piece_to_char()[make_piece(WHITE, pos.promoted_piece_type(type_of(pos.moved_piece(m))))]; + san += is_shogi(n) ? std::string("+") : std::string("=") + (char)toupper(pos.piece_to_char()[make_piece(us, pos.promoted_piece_type(type_of(pos.moved_piece(m))))]); else if (type_of(m) == PIECE_DEMOTION) - san += is_shogi(n) ? std::string("-") : std::string("=") + std::string(1, pos.piece_to_char()[pos.unpromoted_piece_on(from)]); + san += is_shogi(n) ? std::string("-") : std::string("=") + std::string(1, toupper(pos.piece_to_char()[pos.unpromoted_piece_on(from)])); else if (type_of(m) == NORMAL && is_shogi(n) && pos.pseudo_legal(make(from, to))) san += std::string("="); if (is_gating(m)) - san += std::string("/") + pos.piece_to_char()[make_piece(WHITE, gating_type(m))]; + san += std::string("/") + (char)toupper(pos.piece_to_char()[make_piece(us, gating_type(m))]); } // Check and checkmate diff --git a/src/pyffish.cpp b/src/pyffish.cpp index f356773..caad49c 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, 68); + return Py_BuildValue("(iii)", 0, 0, 69); } extern "C" PyObject* pyffish_info(PyObject* self) { diff --git a/test.py b/test.py index fc5e8dd..837847c 100644 --- a/test.py +++ b/test.py @@ -532,6 +532,11 @@ class TestPyffish(unittest.TestCase): result = sf.get_san("kyotoshogi", fen, "a4b2+", False, sf.NOTATION_SHOGI_HODGES_NUMBER) self.assertEqual(result, "N52-44+") + # Demotion + fen = "p+nks+l/5/5/L4/1SK+NP[-] b 0 1" + result = sf.get_san("kyotoshogi", fen, "e5e4-", False, sf.NOTATION_SAN) + self.assertEqual(result, "Ge4=L") + 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=") -- 1.7.0.4