flip puzzles if its black to move - 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 a749e990b529966883178e9cfe8ebfc6faec25b4
(DIR) parent b50c708ac5b44591b62aaa443022625c3fdd44cb
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Wed, 20 Dec 2023 22:32:00 +0100
flip puzzles if its black to move
Diffstat:
M fen.c | 2 +-
M generate.sh | 26 ++++++++++++++++----------
2 files changed, 17 insertions(+), 11 deletions(-)
---
(DIR) diff --git a/fen.c b/fen.c
@@ -451,7 +451,7 @@ showboard_ascii(void)
void
usage(char *argv0)
{
- fprintf(stderr, "usage: %s [-cCfF] [-o ascii|fen|tty|svg] [FEN] [moves]\n", argv0);
+ fprintf(stderr, "usage: %s [-cCfF] [-o ascii|fen|svg|tty] [FEN] [moves]\n", argv0);
exit(1);
}
(DIR) diff --git a/generate.sh b/generate.sh
@@ -1,5 +1,7 @@
#!/bin/sh
+fenbin="./fen"
+
index="puzzles/index.html"
rm -rf puzzles
mkdir -p puzzles/solutions
@@ -83,6 +85,16 @@ while read -r line; do
ratingdev=$(printf '%s' "$line" | cut -f 5 -d ',')
lichess=$(printf '%s' "$line" | cut -f 9 -d ',')
+ case "$tomove" in
+ "w") tomove="w";;
+ "b") tomove="b";;
+ *) tomove="w";; # default
+ esac
+
+ # first move is played so flip when white (not black).
+ flip=""
+ test "$tomove" = "w" && flip="-f"
+
# added field: points
points=$(printf '%s' "$line" | cut -f "11" -d ',')
@@ -93,9 +105,9 @@ while read -r line; do
desttxt="puzzles/$txt"
destvt="puzzles/$vt"
- ./fen_to_svg "$fen" "$firstmove" > "$destsvg"
- ./fen_to_ascii "$fen" "$firstmove" > "$desttxt"
- ./fen_to_tty "$fen" "$firstmove" > "$destvt"
+ "$fenbin" $flip -o svg "$fen" "$firstmove" > "$destsvg"
+ "$fenbin" $flip -o ascii "$fen" "$firstmove" > "$desttxt"
+ "$fenbin" $flip -o tty "$fen" "$firstmove" > "$destvt"
printf '<div class="puzzle">\n' >> "$index"
printf '<h2>Puzzle %s</h2>\n' "$i" >> "$index"
@@ -109,12 +121,6 @@ while read -r line; do
test "$lichess" != "" && printf '</a>' >> "$index"
echo "" >> "$index"
- case "$tomove" in
- "w") tomove="w";;
- "b") tomove="b";;
- *) tomove="w";; # default
- esac
-
movetext=""
# if there is a first move, inverse to move.
if test "$firstmove" != ""; then
@@ -161,7 +167,7 @@ while read -r line; do
# process move list in sequence.
destsolsvg="puzzles/solutions/${i}_${movecount}.svg"
- ./fen_to_svg "$fen" "$movelist" > "$destsolsvg"
+ "$fenbin" $flip -o svg "$fen" "$movelist" > "$destsolsvg"
printf '<img src="%s" width="180" height="180" loading="lazy" />\n' \
"solutions/${i}_${movecount}.svg" >> "$solutions"