Introduction
Introduction Statistics Contact Development Disclaimer Help
fen.c: reduce filesize of SVG further - chess-puzzles - chess puzzle book gener…
git clone git://git.codemadness.org/chess-puzzles
Log
Files
Refs
README
LICENSE
---
commit 9a70ccee5e9c5462e079304c3521c2c7640bf51d
parent e536a441d52c33adea06f8ed451bd890a3ebdb9d
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 24 Dec 2023 11:38:26 +0100
fen.c: reduce filesize of SVG further
Only define drawing commands for the pieces used. Reuse them for multiple
pieces.
The pawn definition is reused, but with a different fill color.
Diffstat:
M fen.c | 73 ++++++++++++++++++++++++-----…
1 file changed, 57 insertions(+), 16 deletions(-)
---
diff --git a/fen.c b/fen.c
@@ -169,17 +169,17 @@ showpiece_svg(int c)
/* lichess default set,
extracted from https://github.com/lichess-org/lila/tree/master/publ…
switch (c) {
- case 'K': s = "<g fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" …
- case 'Q': s = "<g fill=\"#fff\" fill-rule=\"evenodd\" stroke=\"#000\" …
- case 'R': s = "<g fill=\"#fff\" fill-rule=\"evenodd\" stroke=\"#000\" …
- case 'B': s = "<g fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" …
- case 'N': s = "<g fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" …
+ case 'K': s = "<use href=\"#wk\"/>"; break;
+ case 'Q': s = "<use href=\"#wq\"/>"; break;
+ case 'R': s = "<use href=\"#wr\"/>"; break;
+ case 'B': s = "<use href=\"#wb\"/>"; break;
+ case 'N': s = "<use href=\"#wn\"/>"; break;
case 'P': s = "<use href=\"#pawn\" fill=\"#fff\"/>"; break;
- case 'k': s = "<g fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" …
- case 'q': s = "<g fill-rule=\"evenodd\" stroke=\"#000\" stroke-width=\…
- case 'r': s = "<g fill-rule=\"evenodd\" stroke=\"#000\" stroke-width=\…
- case 'b': s = "<g fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" …
- case 'n': s = "<g fill=\"none\" fill-rule=\"evenodd\" stroke=\"#000\" …
+ case 'k': s = "<use href=\"#bk\"/>"; break;
+ case 'q': s = "<use href=\"#bq\"/>"; break;
+ case 'r': s = "<use href=\"#br\"/>"; break;
+ case 'b': s = "<use href=\"#bb\"/>"; break;
+ case 'n': s = "<use href=\"#bn\"/>"; break;
case 'p': s = "<use href=\"#pawn\" fill=\"#000\"/>"; break;
}
@@ -190,16 +190,55 @@ showpiece_svg(int c)
void
output_svg(void)
{
+ const char *s;
+ char pieces[] = "pPKQRBNkqrbn"; /* pieces, check if they are used for …
+ unsigned char pieceused[sizeof("pPKQRBNkqrbn")];
const int *color;
- int ix, iy, x, y, piece;
+ int i, ix, iy, x, y, piece;
fputs("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www…
"<svg width=\"360\" height=\"360\" viewBox=\"0 0 360 360\" xml…
"<rect fill=\"#fff\" stroke=\"#000\" x=\"0\" y=\"0\" width=\"3…
+ memset(pieceused, 0, sizeof(pieceused));
+ for (i = 0; i < sizeof(pieces) / sizeof(pieces[0]); i++) {
+ for (y = 0; y < 8 && !pieceused[i]; y++) {
+ for (x = 0; x < 8; x++) {
+ if (getpiece(x, y) == pieces[i]) {
+ pieceused[i] = 1;
+ break;
+ }
+ }
+ }
+ }
+
fputs("<defs>\n", stdout);
- fputs("<path id=\"pawn\" d=\"M22.5 9c-2.21 0-4 1.79-4 4 0 .89.29 1.71.…
+ for (i = 0; i < sizeof(pieces) / sizeof(pieces[0]); i++) {
+ if (!pieceused[i])
+ continue;
+ s = NULL;
+ switch (pieces[i]) {
+ case 'K': s ="<g id=\"wk\" fill=\"none\" fill-rule=\"evenodd\…
+ case 'Q': s = "<g id=\"wq\" fill=\"#fff\" fill-rule=\"evenodd\…
+ case 'R': s = "<g id=\"wr\" fill=\"#fff\" fill-rule=\"evenodd\…
+ case 'B': s = "<g id=\"wb\" fill=\"none\" fill-rule=\"evenodd\…
+ case 'N': s = "<g id=\"wn\" fill=\"none\" fill-rule=\"evenodd\…
+ case 'P':
+ case 'p':
+ s = "<path id=\"pawn\" d=\"M22.5 9c-2.21 0-4 1.79-4 4 …
+ pieceused[0] = pieceused[1] = 0; /* unset used, only o…
+ break;
+ case 'k': s = "<g id=\"bk\" fill=\"none\" fill-rule=\"evenodd\…
+ case 'q': s = "<g id=\"bq\" fill-rule=\"evenodd\" stroke=\"#00…
+ case 'r': s = "<g id=\"br\" fill-rule=\"evenodd\" stroke=\"#00…
+ case 'b': s = "<g id=\"bb\" fill=\"none\" fill-rule=\"evenodd\…
+ case 'n': s = "<g id=\"bn\" fill=\"none\" fill-rule=\"evenodd\…
+ default: break;
+ }
+ if (s)
+ fputs(s, stdout);
+ }
fputs("</defs>\n", stdout);
for (iy = 0; iy < 8; iy++) {
@@ -529,12 +568,17 @@ ischecked(int side)
return 0;
}
+/* TODO */
int
ischeckmated(int side)
{
int kingx, kingy;
// TODO: can king move out check, without being checked?
+ // TODO: can a piece defend it.
+ // TODO: can the checking piece get taken without still being checked?
+ // TODO: handle double-checks.
+ // TODO: separate board state or just move and undo move?
if (!ischecked(side))
return 0;
@@ -543,10 +587,7 @@ ischeckmated(int side)
if (!findking(side, &kingx, &kingy))
return 0; /* should not happen */
- // TODO: can the king move? move it and check if it is not checked
- // TODO: separate board state or just move and undo move?
-
- return 0; // TODO
+ return 0;
}
void
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.