fen_to_*.c: handle possible piece promotion for moves - 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 098952703cf713b7569ae0cb826a08a239e3b46a
(DIR) parent b8fe22e0b3297f81eca81b3c5ad8f2fd7e918c38
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Mon, 18 Dec 2023 22:15:46 +0100
fen_to_*.c: handle possible piece promotion for moves
Diffstat:
M fen_to_ascii.c | 14 ++++++++++++++
M fen_to_svg.c | 14 ++++++++++++++
M fen_to_tty.c | 13 +++++++++++++
3 files changed, 41 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/fen_to_ascii.c b/fen_to_ascii.c
@@ -1,5 +1,6 @@
/* TODO: option to flip board? */
+#include <ctype.h>
#include <stdio.h>
#include <string.h>
@@ -265,6 +266,19 @@ main(int argc, char *argv[])
squaretoxy(square, &x2, &y2);
place(piece, x2, y2);
s += 2;
+
+ /* possible promotion? (queen, knight, bishop) */
+ if (*s == 'q' || *s == 'n' || *s == 'b') {
+ if (side_to_move == 'w')
+ piece = toupper(*s);
+ else
+ piece = *s;
+ place(piece, x2, y2);
+ s++;
+ }
+
+ /* switch which side it is to move */
+ side_to_move = side_to_move == 'b' ? 'w' : 'b';
}
}
/* highlight last move */
(DIR) diff --git a/fen_to_svg.c b/fen_to_svg.c
@@ -1,5 +1,6 @@
/* TODO: option to flip board? */
+#include <ctype.h>
#include <stdio.h>
#include <string.h>
@@ -276,6 +277,19 @@ main(int argc, char *argv[])
squaretoxy(square, &x2, &y2);
place(piece, x2, y2);
s += 2;
+
+ /* possible promotion? (queen, knight, bishop) */
+ if (*s == 'q' || *s == 'n' || *s == 'b') {
+ if (side_to_move == 'w')
+ piece = toupper(*s);
+ else
+ piece = *s;
+ place(piece, x2, y2);
+ s++;
+ }
+
+ /* switch which side it is to move */
+ side_to_move = side_to_move == 'b' ? 'w' : 'b';
}
}
/* highlight last move */
(DIR) diff --git a/fen_to_tty.c b/fen_to_tty.c
@@ -320,6 +320,19 @@ main(int argc, char *argv[])
squaretoxy(square, &x2, &y2);
place(piece, x2, y2);
s += 2;
+
+ /* possible promotion? (queen, knight, bishop) */
+ if (*s == 'q' || *s == 'n' || *s == 'b') {
+ if (side_to_move == 'w')
+ piece = toupper(*s);
+ else
+ piece = *s;
+ place(piece, x2, y2);
+ s++;
+ }
+
+ /* switch which side it is to move */
+ side_to_move = side_to_move == 'b' ? 'w' : 'b';
}
}
/* highlight last move */