Introduction
Introduction Statistics Contact Development Disclaimer Help
generate.sh: add initial solutions/spoiler page - chess-puzzles - chess puzzle …
git clone git://git.codemadness.org/chess-puzzles
Log
Files
Refs
README
LICENSE
---
commit 5df80ee4eebb2000bcac5530f58e6c84e9b92818
parent 098952703cf713b7569ae0cb826a08a239e3b46a
Author: Hiltjo Posthuma <[email protected]>
Date: Mon, 18 Dec 2023 22:16:22 +0100
generate.sh: add initial solutions/spoiler page
Diffstat:
M generate.sh | 68 +++++++++++++++++++++++++++--…
1 file changed, 60 insertions(+), 8 deletions(-)
---
diff --git a/generate.sh b/generate.sh
@@ -1,7 +1,10 @@
#!/bin/sh
index="puzzles/index.html"
-mkdir -p puzzles
+rm -rf puzzles
+mkdir -p puzzles/solutions
+
+solutions="$(mktemp)"
cat > "$index" <<!
<!DOCTYPE html>
@@ -20,6 +23,9 @@ body {
float: left;
margin-right: 25px;
}
+footer {
+ clear: both;
+}
</style>
</head>
<body>
@@ -69,8 +75,10 @@ LC_ALL=C awk -F ',' '
while read -r line; do
i="$count"
fen=$(printf '%s' "$line" | cut -f 2 -d ',')
+
tomove=$(printf '%s' "$line" | cut -f 2 -d ',' | cut -f 2 -d ' ')
- moves=$(printf '%s' "$line" | cut -f 3 -d ',' | cut -b 1-4 ) # first m…
+ allmoves="$(printf '%s' "$line" | cut -f 3 -d ',')"
+ firstmove=$(printf '%s' "$line" | cut -f 3 -d ',' | cut -f 1 -d ' ' ) …
rating=$(printf '%s' "$line" | cut -f 4 -d ',')
ratingdev=$(printf '%s' "$line" | cut -f 5 -d ',')
lichess=$(printf '%s' "$line" | cut -f 9 -d ',')
@@ -85,11 +93,11 @@ while read -r line; do
desttxt="puzzles/$txt"
destvt="puzzles/$vt"
- ./fen_to_svg "$fen" "$moves" > "$destsvg"
- ./fen_to_ascii "$fen" "$moves" > "$desttxt"
- ./fen_to_tty "$fen" "$moves" > "$destvt"
+ ./fen_to_svg "$fen" "$firstmove" > "$destsvg"
+ ./fen_to_ascii "$fen" "$firstmove" > "$desttxt"
+ ./fen_to_tty "$fen" "$firstmove" > "$destvt"
- printf '<div class="puzzle">' >> "$index"
+ printf '<div class="puzzle">\n' >> "$index"
printf '<h2>Puzzle %s</h2>\n' "$i" >> "$index"
test "$lichess" != "" && printf '<a href="%s">' "$lichess" >> "$index"
@@ -109,7 +117,7 @@ while read -r line; do
movetext=""
# if there is a first move, inverse to move.
- if test "moves" != ""; then
+ if test "$firstmove" != ""; then
case "$tomove" in
"w") movetext=", black to move";;
"b") movetext=", white to move";;
@@ -125,16 +133,60 @@ while read -r line; do
printf '%s%s\n' "$points" "$movetext" >> "$desttxt"
printf '\n%s%s\n' "$points" "$movetext" >> "$destvt"
+ # solutions per puzzle.
+ printf '<div class="puzzle-solution">\n' >> "$solutions"
+ printf '<h2>Puzzle %s</h2>\n' "$i" >> "$solutions"
+
+ m="${allmoves}"
+ movecount=0
+ # create a move list, removing one move each step, for generating
+ # the solution images.
+ while [ "$m" != "" ]; do
+ prevmoves="$m"
+
+ echo "$m"
+
+ m="${m% }"
+ m="${m%[a-h][0-9][a-h][0-9]}"
+ m="${m%[qnb]}" # possible promotion
+ m="${m% }"
+
+ test "$prevmoves" = "$m" && break # same, break also
+ done | sort | while read -r movelist; do
+ # first move is already shown, skip it.
+ if test "$movecount" = "0"; then
+ movecount=$((movecount + 1))
+ continue
+ fi
+
+ # process move list in sequence.
+ destsolsvg="puzzles/solutions/${i}_${movecount}.svg"
+ ./fen_to_svg "$fen" "$movelist" > "$destsolsvg"
+
+ printf '<img src="%s" width="180" height="180" loading="lazy" …
+ "solutions/${i}_${movecount}.svg" >> "$solutions"
+
+ movecount=$((movecount + 1))
+ done
+ printf '</div>\n' >> "$solutions"
+
printf '</div>\n' >> "$index"
# DEBUG
- #echo "$count" >&2
+ #echo "$count: $line" >&2
count=$((count + 1))
done
+# solutions / spoilers
+echo "<footer><br/><br/><details>\n<summary>Solutions</summary>\n" >> "$index"
+cat "$solutions" >> "$index"
+echo "</details>\n<br/><br/></footer>\n" >> "$index"
+
cat >> "$index" <<!
</main>
</body>
</html>
!
+
+rm -f "$solutions"
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.