Fix SAN generation for demotions
authorFabian Fichter <ianfab@users.noreply.github.com>
Wed, 2 Feb 2022 19:50:35 +0000 (20:50 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Wed, 2 Feb 2022 19:50:35 +0000 (20:50 +0100)
And use more consistent uppercase conversion.

setup.py
src/apiutil.h
src/pyffish.cpp
test.py

index 87582b9..61ac464 100644 (file)
--- 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",
index 11a599d..d82653b 100644 (file)
@@ -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<PIECE_PROMOTION>(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
index f356773..caad49c 100644 (file)
@@ -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 (file)
--- 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=")