From: Fabian Fichter Date: Fri, 23 Apr 2021 15:49:44 +0000 (+0200) Subject: Fix ambiguous castling notation X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=2611663b2516310ef0e1029c760dc2ed0b699e3c;p=fairystockfish.git Fix ambiguous castling notation Use chess960 castling notation when castling move would be ambiguous. Closes #295. --- diff --git a/src/uci.cpp b/src/uci.cpp index 524b081..0e9237d 100644 --- a/src/uci.cpp +++ b/src/uci.cpp @@ -472,7 +472,12 @@ string UCI::move(const Position& pos, Move m) { if (is_gating(m) && gating_square(m) == to) from = to_sq(m), to = from_sq(m); else if (type_of(m) == CASTLING && !pos.is_chess960()) + { to = make_square(to > from ? pos.castling_kingside_file() : pos.castling_queenside_file(), rank_of(from)); + // If the castling move is ambiguous with a normal king move, switch to 960 notation + if (pos.pseudo_legal(make_move(from, to))) + to = to_sq(m); + } string move = (type_of(m) == DROP ? UCI::dropped_piece(pos, m) + (Options["Protocol"] == "usi" ? '*' : '@') : UCI::square(pos, from)) + UCI::square(pos, to); diff --git a/src/variants.ini b/src/variants.ini index df10ccb..b388f2d 100644 --- a/src/variants.ini +++ b/src/variants.ini @@ -589,7 +589,7 @@ doubleStep = false castling = false startFen = r6r/1nbqkbn1/pppppppp/8/8/PPPPPPPP/1NBQKBN1/R6R w - - 0 1 -# Diana Chess // Kingside castling not working! +# Diana Chess # https://greenchess.net/rules.php?v=diana [diana:losalamos] pieceToCharTable = PNBRQ................Kpnbrq................k diff --git a/test.py b/test.py index dae8d9b..ce86be9 100644 --- a/test.py +++ b/test.py @@ -59,6 +59,15 @@ promotionPieceTypes = qh flagPiece = k whiteFlag = *8 blackFlag = *1 + +[diana:losalamos] +pieceToCharTable = PNBRQ................Kpnbrq................k +bishop = b +promotionPieceTypes = rbn +castling = true +castlingKingsideFile = e +castlingQueensideFile = b +startFen = rbnkbr/pppppp/6/6/PPPPPP/RBNKBR w KQkq - 0 1 """ sf.load_variant_config(ini_text) @@ -265,6 +274,11 @@ class TestPyffish(unittest.TestCase): result = sf.legal_moves("capablanca", CAPA, moves) self.assertIn("f1i1", result) + # Check that chess960 castling notation is used for otherwise ambiguous castling move + # d1e1 is a normal king move, so castling has to be d1f1 + result = sf.legal_moves("diana", "rbnk1r/pppbpp/3p2/5P/PPPPPB/RBNK1R w KQkq - 2 3", []) + self.assertIn("d1f1", result) + def test_get_fen(self): result = sf.get_fen("chess", CHESS, []) self.assertEqual(result, CHESS)