fen.c: add output to describe piece positions as text - chess-puzzles - chess puzzle book generator
HTML git clone git://git.codemadness.org/chess-puzzles
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 16797922fca63b7c4ebea1f378ee40197930c026
DIR parent f6061bfecd18263a16740fc9e7d5963256067acc
HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Wed, 4 Mar 2026 19:40:42 +0100
fen.c: add output to describe piece positions as text
Could be useful for blind practise / visualization.
Diffstat:
M LICENSE | 2 +-
M fen.1 | 6 ++++--
M fen.c | 36 +++++++++++++++++++++++++++++--
3 files changed, 39 insertions(+), 5 deletions(-)
---
DIR diff --git a/LICENSE b/LICENSE
@@ -1,6 +1,6 @@
ISC License
-Copyright (c) 2023-2025 Hiltjo Posthuma <hiltjo@codemadness.org>
+Copyright (c) 2023-2026 Hiltjo Posthuma <hiltjo@codemadness.org>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
DIR diff --git a/fen.1 b/fen.1
@@ -1,4 +1,4 @@
-.Dd July 22, 2025
+.Dd March 4, 2026
.Dt FEN 1
.Os
.Sh NAME
@@ -9,7 +9,7 @@
.Op Fl cCfFhH
.Op Fl l
.Op Fl m mapping
-.Op Fl o Ar ascii | fen | pgn | speak | svg | tty
+.Op Fl o Ar ascii | describe | fen | pgn | speak | svg | tty
.Op Fl sS
.Op Fl t theme
.Op Ar FEN
@@ -53,6 +53,8 @@ Output format to one of the following format:
.It ascii
ASCII text representation of the board.
FEN of the board state after playing the moves.
+.It describe
+Describe piece positions as text for the board.
.It fen
FEN of the board state after playing the moves.
.It pgn
DIR diff --git a/fen.c b/fen.c
@@ -21,7 +21,7 @@
#define SETBGCOLOR(r,g,b) printf("\x1b[48;2;%d;%d;%dm", r, g, b)
enum outputmode { ModeInvalid = 0, ModeASCII, ModeFEN, ModePGN,
- ModeTTY, ModeSVG, ModeSpeak };
+ ModeTTY, ModeSVG, ModeSpeak, ModeDescribe };
enum outputmode outputmode = ModeSVG; /* default is SVG */
static int onlylastmove = 0, silent = 0, dutchmode = 0;
@@ -712,6 +712,35 @@ output_ascii(struct board *b)
fputs("\n", stdout);
}
+/* Describe piece positions */
+void
+output_describe(struct board *b)
+{
+ struct theme *t;
+ Color *color;
+ int ix, iy, x, y, piece, pi;
+ char pieces[] = "KQRBNPkqrbnp";
+
+ for (pi = 0; pi < LEN(pieces); pi++) {
+ for (iy = 0; iy < 8; iy++) {
+ y = b->flipboard ? 7 - iy : iy;
+ for (ix = 0; ix < 8; ix++) {
+ x = b->flipboard ? 7 - ix : ix;
+ piece = getpiece(b, x, y);
+ if (!piece || piece != pieces[pi])
+ continue;
+
+ if (iswhitepiece(piece))
+ fputs(dutchmode ? "witte " : "white ", stdout);
+ else
+ fputs(dutchmode ? "zwarte " : "black ", stdout);
+ speakpiece(piece);
+ printf("%s %c%c\n", dutchmode ? "op" : "on", xtofile(x), ytorank(y));
+ }
+ }
+ }
+}
+
int
findking(struct board *b, int side, int *kingx, int *kingy)
{
@@ -1455,7 +1484,7 @@ void
usage(char *argv0)
{
fprintf(stderr, "usage: %s [-cCfFhH] [-l] [-m mapping] "
- "[-o ascii|fen|pgn|speak|svg|tty] [-sS] [-t default|green|grey] "
+ "[-o ascii|describe|fen|pgn|speak|svg|tty] [-sS] [-t default|green|grey] "
"[FEN] [moves]\n", argv0);
exit(1);
}
@@ -1531,6 +1560,8 @@ outputnametomode(const char *s)
{
if (!strcmp(s, "ascii"))
return ModeASCII;
+ else if (!strcmp(s, "describe"))
+ return ModeDescribe;
else if (!strcmp(s, "fen"))
return ModeFEN;
else if (!strcmp(s, "pgn"))
@@ -1550,6 +1581,7 @@ output(struct board *b)
{
switch (outputmode) {
case ModeASCII: output_ascii(b); break;
+ case ModeDescribe: outputmode = ModeSpeak; output_describe(b); break;
case ModeFEN: output_fen(b); break;
case ModePGN: break; /* handled in parsemoves() */
case ModeSVG: output_svg(b); break;