fix a bug in FEN en passant parsing, handle en passant takes - chess-puzzles - chess puzzle book generator
 (HTM) git clone git://git.codemadness.org/chess-puzzles
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 10e231516543327f556abc8b73c31c1e114ede48
 (DIR) parent f2415a87c11df764bacefa67d70efd1c57bd66ff
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Wed, 20 Dec 2023 23:53:58 +0100
       
       fix a bug in FEN en passant parsing, handle en passant takes
       
       Add a few tests for them.
       
       Diffstat:
         M fen.c                               |       8 ++++++--
         M tests.sh                            |      10 +++++++++-
       
       2 files changed, 15 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/fen.c b/fen.c
       @@ -549,8 +549,7 @@ next:
                                break;
                        case 3: /* en passant square */
                                if (*s >= 'a' && *s <= 'h' &&
       -                                *(s + 1) >= '1' && *(s + 1) >= '6') {
       -
       +                                *(s + 1) >= '1' && *(s + 1) <= '6') {
                                        square[0] = *s;
                                        square[1] = *(s + 1);
                                        square[2] = '\0';
       @@ -599,6 +598,7 @@ next:
                /* process moves */
                square[2] = '\0';
                x = y = x2 = y2 = -1;
       +
                for (s = moves; *s; s++) {
                        if (*s == ' ')
                                continue;
       @@ -677,6 +677,10 @@ next:
                                                black_can_castle[0] = 0;
                                }
        
       +                        /* taken en passant? */
       +                        if (x2 == enpassantsquare[0] && y2 == enpassantsquare[1])
       +                                place(0, x2, piece == 'P' ? y2 + 1 : y2 - 1);
       +
                                /* the en passant square resets after a move */
                                enpassantsquare[0] = -1;
                                enpassantsquare[1] = -1;
 (DIR) diff --git a/tests.sh b/tests.sh
       @@ -6,7 +6,7 @@ testfen() {
                fen="$2"
                moves="$3"
        
       -        output=$(./fen_to_fen "$fen" "$moves")
       +        output=$(./fen -o fen "$fen" "$moves")
                if test "$output" = "$expect"; then
                        echo "OK"
                else
       @@ -78,3 +78,11 @@ testfen 'r4k1r/ppp1p1p1/8/2Pp1p2/6P1/4P2p/PP1P1P1P/R3K2R w - d6 0 9'\
        testfen 'r4k1r/p1ppp1p1/8/1pP2p2/6P1/4P2p/PP1P1P1P/R3K2R w - b6 0 9'\
                'r4k1r/ppppp1p1/8/2P2p2/6P1/4P2p/PP1P1P1P/R3K2R b - - 0 8'\
                'b7b5'
       +# white takes en passant
       +testfen 'rnbqkbnr/pppp1pp1/4P3/7p/8/8/PPP1PPPP/RNBQKBNR b KQkq - 0 3'\
       +        'rnbqkbnr/pppp1pp1/8/3Pp2p/8/8/PPP1PPPP/RNBQKBNR w KQkq e6 0 3'\
       +        'd5e6'
       +# black takes en passant
       +testfen 'rnbqkbnr/ppppppp1/8/8/3P4/4P1p1/PPP2P1P/RNBQKBNR w KQkq - 0 4'\
       +        'rnbqkbnr/ppppppp1/8/8/3P2Pp/4P3/PPP2P1P/RNBQKBNR b KQkq g3 0 3'\
       +        'h4g3'