Introduction
Introduction Statistics Contact Development Disclaimer Help
fen.c: optimization for size: do not use true-color where its not needed - ches…
git clone git://git.codemadness.org/chess-puzzles
Log
Files
Refs
README
LICENSE
---
commit 2046625e2948b915fb5f7b6244e54f79cf2c2a8a
parent 2f8f9b16e1834cdd577d590efc51be17f3013585
Author: Hiltjo Posthuma <[email protected]>
Date: Thu, 21 Dec 2023 19:57:04 +0100
fen.c: optimization for size: do not use true-color where its not needed
- Reduces file size.
- Simplify creating a checkered pattern.
Diffstat:
M fen.c | 77 +++++++++--------------------…
1 file changed, 23 insertions(+), 54 deletions(-)
---
diff --git a/fen.c b/fen.c
@@ -180,17 +180,10 @@ showboard_svg(void)
for (ix = 0; ix < 8; ix++) {
x = flipboard ? 7 - ix : ix;
- if (x % 2 == 0) {
- if (y % 2 == 0)
- color = highlight[y][x] ? lightsquareh…
- else
- color = highlight[y][x] ? darksquarehi…
- } else {
- if (y % 2 == 0)
- color = highlight[y][x] ? darksquarehi…
- else
- color = highlight[y][x] ? lightsquareh…
- }
+ if (((x % 2) ^ (y % 2)) == 0)
+ color = highlight[y][x] ? lightsquarehi : ligh…
+ else
+ color = highlight[y][x] ? darksquarehi : darks…
printf("<g><rect x=\"%d\" y=\"%d\" width=\"45\" height…
ix * 45, iy * 45, color[0], color[1], color[2]…
@@ -211,17 +204,10 @@ showboard_svg(void)
y = flipboard ? 7 - iy : iy;
/* inverse square color for text */
- if (x % 2 == 0) {
- if (y % 2 == 0)
- color = highlight[y][x] ? darksquarehi…
- else
- color = highlight[y][x] ? lightsquareh…
- } else {
- if (y % 2 == 0)
- color = highlight[y][x] ? lightsquareh…
- else
- color = highlight[y][x] ? darksquarehi…
- }
+ if (((x % 2) ^ (y % 2)) == 0)
+ color = highlight[y][x] ? darksquarehi : darks…
+ else
+ 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…
@@ -293,9 +279,7 @@ showboard_tty(void)
showboardfen();
printf("\n\n");
- color = border;
- SETBGCOLOR(color[0], color[1], color[2]);
- SETFGCOLOR(0xff, 0xff, 0xff);
+ SETBGCOLOR(border[0], border[1], border[2]);
fputs(" ", stdout);
printf("\x1b[0m"); /* reset */
putchar('\n');
@@ -303,34 +287,26 @@ showboard_tty(void)
for (iy = 0; iy < 8; iy++) {
y = flipboard ? 7 - iy : iy;
- color = border;
- SETBGCOLOR(color[0], color[1], color[2]);
- SETFGCOLOR(0xff, 0xff, 0xff);
+ SETBGCOLOR(border[0], border[1], border[2]);
+ fputs("\x1b[97m", stdout); /* bright white */
fputs(" ", stdout);
for (ix = 0; ix < 8; ix++) {
x = flipboard ? 7 - ix : ix;
- if (x % 2 == 0) {
- if (y % 2 == 0)
- color = highlight[y][x] ? lightsquareh…
- else
- color = highlight[y][x] ? darksquarehi…
- } else {
- if (y % 2 == 0)
- color = highlight[y][x] ? darksquarehi…
- else
- color = highlight[y][x] ? lightsquareh…
- }
+ if (((x % 2) ^ (y % 2)) == 0)
+ color = highlight[y][x] ? lightsquarehi : ligh…
+ else
+ color = highlight[y][x] ? darksquarehi : darks…
SETBGCOLOR(color[0], color[1], color[2]);
fputs(" ", stdout);
piece = getpiece(x, y);
if (piece) {
if (piece >= 'A' && piece <= 'Z')
- SETFGCOLOR(0xff, 0xff, 0xff);
+ fputs("\x1b[97m", stdout); /* bright w…
else
- SETFGCOLOR(0x00, 0x00, 0x00);
+ fputs("\x1b[30m", stdout); /* black */
/* workaround: use black unicode chess symbol,…
the color is filled and better visible */
showpiece_tty(tolower(piece));
@@ -343,8 +319,8 @@ showboard_tty(void)
color = border;
SETBGCOLOR(color[0], color[1], color[2]);
- SETFGCOLOR(0xff, 0xff, 0xff);
if (showcoords) {
+ fputs("\x1b[97m", stdout); /* bright white */
putchar('8' - y);
putchar(' ');
} else {
@@ -356,7 +332,7 @@ showboard_tty(void)
}
color = border;
SETBGCOLOR(color[0], color[1], color[2]);
- SETFGCOLOR(0xff, 0xff, 0xff);
+ fputs("\x1b[97m", stdout); /* bright white */
if (showcoords) {
if (flipboard)
fputs(" h g f e d c b a ", stdout);
@@ -403,17 +379,10 @@ showboard_ascii(void)
for (ix = 0; ix < 8; ix++) {
x = flipboard ? 7 - ix : ix;
- if (x % 2 == 0) {
- if (y % 2 == 0)
- color = highlight[y][x] ? hi : light;
- else
- color = highlight[y][x] ? hi : dark;
- } else {
- if (y % 2 == 0)
- color = highlight[y][x] ? hi : dark;
- else
- color = highlight[y][x] ? hi : light;
- }
+ if (((x % 2) ^ (y % 2)) == 0)
+ color = highlight[y][x] ? hi : light;
+ else
+ color = highlight[y][x] ? hi : dark;
if (ix == 0)
putchar('|');
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.