chess-puzzles

chess puzzle book generator
git clone git://git.codemadness.org/chess-puzzles
Log | Files | Refs | README | LICENSE

commit d1450a9bf4d9b009733094038420a82a6872a8ae
parent 09a541233ed6f1abf9f4498b37d1281a78f65ce8
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Tue, 19 Dec 2023 00:31:55 +0100

implement detecting castling for moves

Diffstat:
Mfen_to_svg.c | 33++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/fen_to_svg.c b/fen_to_svg.c @@ -286,7 +286,38 @@ main(int argc, char *argv[]) place(piece, x2, y2); s += 2; - /* possible promotion? (queen, knight, bishop) */ + /* castling */ + if (piece == 'K' && y == 7 && y2 == 7 && x == 4) { + /* white: kingside castling: "e1g1" */ + if (x2 == 6) { + place('R', x2 - 1, y2); + x2 = 7; + y2 = 7; + place(0, x2, y2); /* clear rook square */ + } else if (x2 == 2) { + /* white: queenside castling: "e1c1" */ + place('R', x2 + 1, y2); + x2 = 0; + y2 = 7; + place(0, x2, y2); + } + } else if (piece == 'k' && y == 0 && y2 == 0 && x == 4) { + /* black: kingside castling: "e8g8" */ + if (x2 == 6) { + place('r', x2 - 1, y2); + x2 = 7; + y2 = 0; + place(0, x2, y2); /* clear rook square */ + } else if (x2 == 2) { + /* black: queenside castling: "e8c8" */ + place('r', x2 + 1, y2); + x2 = 0; + y2 = 0; + place(0, x2, y2); /* clear rook square */ + } + } + + /* possible promotion: queen, knight, bishop */ if (*s == 'q' || *s == 'n' || *s == 'b') { if (side_to_move == 'w') piece = toupper(*s);