From 1326b70c353c9606912ed8bd803a7e65a74ac5e5 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Tue, 5 May 2020 19:29:09 +0200 Subject: [PATCH] Fix SAN notation for Shogi-style promotions Closes #120. --- src/pyffish.cpp | 8 ++++---- test.py | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pyffish.cpp b/src/pyffish.cpp index e3c2365..9d555ab 100644 --- a/src/pyffish.cpp +++ b/src/pyffish.cpp @@ -70,10 +70,10 @@ std::string piece(const Position& pos, Move m, Notation n) { else if (n == NOTATION_XIANGQI_WXF && popcount(pos.pieces(us, pt) & file_bb(from)) > 2) return std::to_string(popcount(forward_file_bb(us, from) & pos.pieces(us, pt)) + 1); // Moves of promoted pieces - else if (type_of(m) != DROP && pos.unpromoted_piece_on(from)) + else if (is_shogi(n) && type_of(m) != DROP && pos.unpromoted_piece_on(from)) return "+" + std::string(1, toupper(pos.piece_to_char()[pos.unpromoted_piece_on(from)])); // Promoted drops - else if (type_of(m) == DROP && dropped_piece_type(m) != in_hand_piece_type(m)) + else if (is_shogi(n) && type_of(m) == DROP && dropped_piece_type(m) != in_hand_piece_type(m)) return "+" + std::string(1, toupper(pos.piece_to_char()[in_hand_piece_type(m)])); else if (pos.piece_to_char_synonyms()[pc] != ' ') return std::string(1, toupper(pos.piece_to_char_synonyms()[pc])); @@ -259,9 +259,9 @@ const std::string move_to_san(Position& pos, Move m, Notation n) { if (type_of(m) == PROMOTION) san += std::string("=") + pos.piece_to_char()[make_piece(WHITE, promotion_type(m))]; else if (type_of(m) == PIECE_PROMOTION) - san += std::string("+"); + 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))))]; else if (type_of(m) == PIECE_DEMOTION) - san += std::string("-"); + san += is_shogi(n) ? std::string("-") : std::string("=") + std::string(1, 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)) diff --git a/test.py b/test.py index c85e502..2611232 100644 --- a/test.py +++ b/test.py @@ -425,22 +425,24 @@ class TestPyffish(unittest.TestCase): def test_get_san_moves(self): UCI_moves = ["e2e4", "e7e5", "g1f3", "b8c6h", "f1c4", "f8c5e"] SAN_moves = ["e4", "e5", "Nf3", "Nc6/H", "Bc4", "Bc5/E"] - result = sf.get_san_moves("seirawan", SEIRAWAN, UCI_moves) self.assertEqual(result, SAN_moves) UCI_moves = ["c3c4", "g7g6", "b2h8"] SAN_moves = ["P-7f", "P-3d", "Bx2b="] - result = sf.get_san_moves("shogi", SHOGI, UCI_moves) self.assertEqual(result, SAN_moves) UCI_moves = ["h3e3", "h10g8", "h1g3", "c10e8", "a1a3", "i10h10"] SAN_moves = ["C2=5", "H8+7", "H2+3", "E3+5", "R9+2", "R9=8"] - result = sf.get_san_moves("xiangqi", XIANGQI, UCI_moves, False, sf.NOTATION_XIANGQI_WXF) self.assertEqual(result, SAN_moves) + UCI_moves = ["e2e4", "d7d5", "f1a6+", "d8d6"] + SAN_moves = ["e4", "d5", "Ba6=A", "Qd6"] + result = sf.get_san_moves("shogun", SHOGUN, UCI_moves) + self.assertEqual(result, SAN_moves) + def test_gives_check(self): result = sf.gives_check("capablanca", CAPA, []) self.assertFalse(result) -- 1.7.0.4