From: Fabian Fichter Date: Fri, 5 Nov 2021 23:05:38 +0000 (+0100) Subject: Remove redundancy from S-Chess FEN X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=1f971fda302b7eca02c4f3e0cffe68208ea56011;p=fairystockfish.git Remove redundancy from S-Chess FEN Closes #83. --- diff --git a/src/position.cpp b/src/position.cpp index acce8a4..3a06a42 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -717,7 +717,11 @@ string Position::fen(bool sfen, bool showPromoted, int countStarted, std::string if (gating() && gates(WHITE) && (!seirawan_gating() || count_in_hand(WHITE, ALL_PIECES) > 0 || captures_to_hand())) for (File f = FILE_A; f <= max_file(); ++f) - if (gates(WHITE) & file_bb(f)) + if ( (gates(WHITE) & file_bb(f)) + // skip gating flags redundant with castling flags + && !(!chess960 && can_castle(WHITE_CASTLING) && f == file_of(castling_king_square(WHITE))) + && !(can_castle(WHITE_OO ) && f == file_of(castling_rook_square(WHITE_OO ))) + && !(can_castle(WHITE_OOO) && f == file_of(castling_rook_square(WHITE_OOO)))) ss << char('A' + f); // Disambiguation for chess960 "king" square @@ -732,7 +736,11 @@ string Position::fen(bool sfen, bool showPromoted, int countStarted, std::string if (gating() && gates(BLACK) && (!seirawan_gating() || count_in_hand(BLACK, ALL_PIECES) > 0 || captures_to_hand())) for (File f = FILE_A; f <= max_file(); ++f) - if (gates(BLACK) & file_bb(f)) + if ( (gates(BLACK) & file_bb(f)) + // skip gating flags redundant with castling flags + && !(!chess960 && can_castle(BLACK_CASTLING) && f == file_of(castling_king_square(BLACK))) + && !(can_castle(BLACK_OO ) && f == file_of(castling_rook_square(BLACK_OO ))) + && !(can_castle(BLACK_OOO) && f == file_of(castling_rook_square(BLACK_OOO)))) ss << char('a' + f); if (!can_castle(ANY_CASTLING) && !(gating() && (gates(WHITE) | gates(BLACK)))) diff --git a/test.py b/test.py index 1f9e1b4..4f3ffde 100644 --- a/test.py +++ b/test.py @@ -14,7 +14,7 @@ SITTUYIN = "8/8/4pppp/pppp4/4PPPP/PPPP4/8/8[KFRRSSNNkfrrssnn] w - - 0 1" MAKRUK = "rnsmksnr/8/pppppppp/8/8/PPPPPPPP/8/RNSKMSNR w - - 0 1" SHOGI = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL[-] w - - 0 1" SHOGI_SFEN = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1" -SEIRAWAN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[HEhe] w KQBCDFGkqbcdfg - 0 1" +SEIRAWAN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR[EHeh] w KQBCDFGkqbcdfg - 0 1" GRAND = "r8r/1nbqkcabn1/pppppppppp/10/10/10/10/PPPPPPPPPP/1NBQKCABN1/R8R w - - 0 1" GRANDHOUSE = "r8r/1nbqkcabn1/pppppppppp/10/10/10/10/PPPPPPPPPP/1NBQKCABN1/R8R[] w - - 0 1" XIANGQI = "rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - - 0 1" @@ -330,6 +330,14 @@ class TestPyffish(unittest.TestCase): result = sf.get_fen("xiangqi", XIANGQI, []) self.assertEqual(result, XIANGQI) + result = sf.get_fen("seirawan", SEIRAWAN, []) + self.assertEqual(result, SEIRAWAN) + + # test idempotence for S-Chess960 gating flags + fen1 = sf.get_fen("seirawan", SEIRAWAN, [], True) + fen2 = sf.get_fen("seirawan", fen1, [], True) + self.assertEqual(fen1, fen2) + fen = "rnab1kbcnr/ppppPppppp/10/4q5/10/10/PPPPP1PPPP/RNABQKBCNR[p] b KQkq - 0 3" result = sf.get_fen("capahouse", CAPA, ["f2f4", "e7e5", "f4e5", "e8e5", "P@e7"]) self.assertEqual(result, fen) diff --git a/tests/js/test.js b/tests/js/test.js index af31857..f53052a 100644 --- a/tests/js/test.js +++ b/tests/js/test.js @@ -741,7 +741,7 @@ describe('ffish.readGamePGN(pgn)', function () { let expectedFens = ["1r6/5kp1/RqQb1p1p/1p1PpP2/1Pp1B3/2P4P/6P1/5K2 b - - 14 45", "3r2kr/2pb1Q2/4ppp1/3pN2p/1P1P4/3PbP2/P1P3PP/6NK[PPqrrbbnn] b - - 1 37", "r1bqkbnr/pppp1ppp/2n5/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 3 3", - "r1bQkb1r/ppp1pppp/2P5/2n2q2/8/2N2N2/PPP2PPP/R1BEKB1R[Hh] b KQACEFHkqacefh - 0 8", + "r1bQkb1r/ppp1pppp/2P5/2n2q2/8/2N2N2/PPP2PPP/R1BEKB1R[Hh] b KQCFkqcf - 0 8", "5rk1/4p3/2p3rR/2p1P3/2Pp1B2/1P1P2P1/2N1n3/6K1 w - - 1 44"] for (let idx = 0; idx < pgnFiles.length; ++idx) {