Fix Sittuyin pawn promotion notation
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 25 Apr 2020 09:29:42 +0000 (11:29 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 25 Apr 2020 09:29:42 +0000 (11:29 +0200)
Add disambiguation to SAN notation for Sittuyin promotions.

src/pyffish.cpp
test.py

index 751dd1a..d324c89 100644 (file)
@@ -156,14 +156,20 @@ Disambiguation disambiguation_level(const Position& pos, Move m, Notation n) {
     }
 
     // Pawn captures always use disambiguation
-    if ((n == NOTATION_SAN || n == NOTATION_LAN) && pt == PAWN && pos.capture(m) && from != to)
-        return FILE_DISAMBIGUATION;
+    if (n == NOTATION_SAN && pt == PAWN)
+    {
+        if (pos.capture(m))
+            return FILE_DISAMBIGUATION;
+        if (type_of(m) == PROMOTION && from != to && pos.sittuyin_promotion())
+            return SQUARE_DISAMBIGUATION;
+    }
 
     // A disambiguation occurs if we have more then one piece of type 'pt'
     // that can reach 'to' with a legal move.
     Bitboard others, b;
-    others = b = ((pos.capture(m) ? attacks_bb(~us, pt == HORSE ? KNIGHT : pt, to, pos.pieces())
-                                  : moves_bb(  ~us, pt == HORSE ? KNIGHT : pt, to, pos.pieces())) & pos.pieces(us, pt)) & ~square_bb(from);
+    others = b = ((pos.capture(m) ? attacks_bb(~us, pt, to, AttackRiderTypes[pt] & ASYMMETRICAL_RIDERS ? Bitboard(0) : pos.pieces())
+                                  : moves_bb(  ~us, pt, to, MoveRiderTypes[pt] & ASYMMETRICAL_RIDERS ? Bitboard(0) : pos.pieces()))
+                & pos.pieces(us, pt)) & ~square_bb(from);
 
     while (b)
     {
@@ -238,7 +244,7 @@ const std::string move_to_san(Position& pos, Move m, Notation n) {
             else
                 san += '-';
         }
-        else if (pos.capture(m) && from != to)
+        else if (pos.capture(m))
             san += 'x';
         else if (n == NOTATION_LAN || n == NOTATION_SHOGI_HODGES || (n == NOTATION_SHOGI_HOSKING && d == SQUARE_DISAMBIGUATION) || n == NOTATION_JANGGI)
             san += '-';
diff --git a/test.py b/test.py
index 6083455..5680980 100644 (file)
--- a/test.py
+++ b/test.py
@@ -238,6 +238,10 @@ class TestPyffish(unittest.TestCase):
         result = sf.get_san("chess", fen, "c7b8q")
         self.assertEqual(result, "cxb8=Q+")
 
+        fen = "1r2k3/P1P5/8/8/8/8/8/4K3 w - - 0 1"
+        result = sf.get_san("chess", fen, "c7b8q", False, sf.NOTATION_LAN)
+        self.assertEqual(result, "c7xb8=Q+")
+
         result = sf.get_san("capablanca", CAPA, "e2e4")
         self.assertEqual(result, "e4")
 
@@ -258,6 +262,10 @@ class TestPyffish(unittest.TestCase):
         result = sf.get_san("sittuyin", fen, "h4h4f")
         self.assertEqual(result, "h4=F")
 
+        fen = "k7/2K3P1/8/4P3/8/8/8/1R6[] w - - 0 1"
+        result = sf.get_san("sittuyin", fen, "e5f6f")
+        self.assertEqual(result, "e5f6=F")
+
         result = sf.get_san("shogi", SHOGI, "i3i4")
         self.assertEqual(result, "P-1f")