Introduction
Introduction Statistics Contact Development Disclaimer Help
add util functions for (x,y) to (file, rank) and vice versa - chess-puzzles - c…
git clone git://git.codemadness.org/chess-puzzles
Log
Files
Refs
README
LICENSE
---
commit 6af435b4416d90cb27e447e2f0bf505721374e12
parent b7a52ecde26555a060898faaa5643851368c7467
Author: Hiltjo Posthuma <[email protected]>
Date: Mon, 25 Dec 2023 18:49:58 +0100
add util functions for (x,y) to (file, rank) and vice versa
Diffstat:
M fen.c | 46 +++++++++++++++++++++++------…
1 file changed, 35 insertions(+), 11 deletions(-)
---
diff --git a/fen.c b/fen.c
@@ -97,12 +97,36 @@ getpiece(int x, int y)
}
int
+xtofile(int c)
+{
+ return 'a' + c;
+}
+
+int
+ytorank(int c)
+{
+ return '8' - c;
+}
+
+int
+filetox(int c)
+{
+ return c - 'a';
+}
+
+int
+ranktoy(int c)
+{
+ return '8' - c;
+}
+
+int
squaretoxy(const char *s, int *x, int *y)
{
if (*s >= 'a' && *s <= 'h' &&
*(s + 1) >= '1' && *(s + 1) <= '8') {
- *x = *s - 'a';
- *y = '8' - *(s + 1);
+ *x = filetox(*s);
+ *y = ranktoy(*(s + 1));
return 1;
}
return 0;
@@ -153,8 +177,8 @@ showboardfen(void)
putchar(' ');
if (enpassantsquare[0] != -1 && enpassantsquare[1] != -1) {
- putchar('a' + enpassantsquare[0]);
- putchar('8' - enpassantsquare[1]);
+ putchar(xtofile(enpassantsquare[0]));
+ putchar(ytorank(enpassantsquare[1]));
} else {
putchar('-');
}
@@ -277,7 +301,7 @@ output_svg(void)
color = highlight[y][x] ? lightsquarehi : ligh…
printf("<text x=\"%d\" y=\"%d\" fill=\"#%02x%02x%02x\"…
- (ix + 1) * 45 - 2, (iy * 45) + 10, color[0], c…
+ (ix + 1) * 45 - 2, (iy * 45) + 10, color[0], c…
}
iy = 7;
y = flipboard ? 0 : 7;
@@ -298,7 +322,7 @@ output_svg(void)
}
printf("<text x=\"%d\" y=\"%d\" fill=\"#%02x%02x%02x\"…
- (ix * 45) + 2, (iy + 1) * 45 - 3, color[0], co…
+ (ix * 45) + 2, (iy + 1) * 45 - 3, color[0], co…
}
}
@@ -384,7 +408,7 @@ output_tty(void)
SETBGCOLOR(color[0], color[1], color[2]);
if (showcoords) {
fputs("\x1b[97m", stdout); /* bright white */
- putchar('8' - y);
+ putchar(ytorank(y));
putchar(' ');
} else {
fputs(" ", stdout);
@@ -455,7 +479,7 @@ output_ascii(void)
}
if (showcoords) {
putchar(' ');
- putchar('8' - y);
+ putchar(ytorank(y));
}
putchar('\n');
}
@@ -857,15 +881,15 @@ parsemoves(const char *moves)
if (piece != 'p' && piece != 'P') {
pgn("%c", toupper(piece));
/* TODO: check ambiguity for certain p…
- pgn("%c%c", 'a' + x, '8' - y);
+ pgn("%c%c", xtofile(x), ytorank(y));
}
if (tookpiece) {
/* pawn captures are prefixed by the f…
if (piece == 'p' || piece == 'P')
- pgn("%c", 'a' + x);
+ pgn("%c", xtofile(x));
pgn("x");
}
- pgn("%c%c", 'a' + x2, '8' - y2);
+ pgn("%c%c", xtofile(x2), ytorank(y2));
/* possible promotion: queen, knight, bishop */
if (*s == 'q' || *s == 'n' || *s == 'b') {
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.