Introduction
Introduction Statistics Contact Development Disclaimer Help
fen.c: fix promotion to rook, fix regression in promotion and PGN output for it…
git clone git://git.codemadness.org/chess-puzzles
Log
Files
Refs
README
LICENSE
---
commit a7b46089306de698b20b0400a8ec9f3ccda3f729
parent c569951f00bbd5517962401c1f090cac6a99a8c5
Author: Hiltjo Posthuma <[email protected]>
Date: Sun, 14 Jan 2024 19:09:38 +0100
fen.c: fix promotion to rook, fix regression in promotion and PGN output for it
Diffstat:
M fen.c | 18 +++++++++---------
M tests.sh | 5 +++++
2 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/fen.c b/fen.c
@@ -1145,8 +1145,12 @@ board_playmoves(struct board *b, const char *moves)
s += 2;
promote = 0;
- if (*s == 'q' || *s == 'b' || *s == 'n') {
- promote = *s;
+ /* is a piece? not validated, but should be queen, rook, bisho…
+ if (isvalidpiece(*s)) {
+ if (side == 'w')
+ promote = toupper(*s);
+ else
+ promote = tolower(*s);
s++;
}
@@ -1349,16 +1353,10 @@ board_playmoves(struct board *b, const char *moves)
/* possible promotion: queen, rook, bishop, kn…
if (promote) {
- if (side == 'w')
- piece = toupper(promote);
- else
- piece = tolower(promote);
- place(b, piece, x2, y2);
-
speak(dutchmode ? "en promoot naar " :…
speakpiece(promote);
- pgn("=%c", pgnpiece(piece));
+ pgn("=%c", pgnpiece(promote));
}
}
}
@@ -1367,6 +1365,8 @@ board_playmoves(struct board *b, const char *moves)
if (!castled) {
place(b, 0, x, y);
/* place piece or new promoted piece */
+ if (promote)
+ piece = promote;
place(b, piece, x2, y2);
}
diff --git a/tests.sh b/tests.sh
@@ -492,6 +492,11 @@ testpgn 'Black checks white (blunder), white defends with …
'1. ... Rd1+ 2. Ng1#'\
'8/7k/8/8/3r4/7N/6RR/7K b - - 0 1'\
'd4d1 h3g1'
+
+testpgn 'Test a longer sequence of moves, promotion, castling, etc'\
+ '1. d4 d5 2. Bf4 c6 3. e3 Bf5 4. Bd3 e6 5. g4 Nf6 6. gxf5 Qb6 7. fxe6 …
+ 'startpos'\
+ 'd2d4 d7d5 c1f4 c7c6 e2e3 c8f5 f1d3 e7e6 g2g4 g8f6 g4f5 d8b6 f5e6 f7e6…
}
tests_fen
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.