fen.c: improve castling with chess960 - chess-puzzles - chess puzzle book generator
(HTM) git clone git://git.codemadness.org/chess-puzzles
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 7915ffd10d87934201c751632a4e1dd4c3cb65cb
(DIR) parent 37c4fe7bb023a2537fd8221042a9b62086c6532b
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Mon, 22 Jan 2024 00:55:02 +0100
fen.c: improve castling with chess960
Diffstat:
M fen.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/fen.c b/fen.c
@@ -1173,7 +1173,7 @@ board_playmoves(struct board *b, const char *moves)
/* castling */
if (piece == 'K' && y == 7 && y2 == 7) {
/* white: kingside castling */
- if (x2 > x + 1 || takepiece == 'R') {
+ if (x2 > x + 1 || (x2 > x && takepiece == 'R')) {
for (i = x2; i < 8; i++) {
if (getpiece(b, i, y2) == 'R') {
place(b, 0, x, y); /* clear previous square */
@@ -1183,7 +1183,7 @@ board_playmoves(struct board *b, const char *moves)
break;
}
}
- } else if (x2 < x - 1 || takepiece == 'R') {
+ } else if (x2 < x - 1 || (x2 < x && takepiece == 'R')) {
/* white: queenside castling */
for (i = x2; i >= 0; i--) {
if (getpiece(b, i, y2) == 'R') {
@@ -1197,7 +1197,7 @@ board_playmoves(struct board *b, const char *moves)
}
} else if (piece == 'k' && y == 0 && y2 == 0) {
/* black: kingside castling */
- if (x2 > x + 1 || takepiece == 'r') {
+ if (x2 > x + 1 || (x2 > x && takepiece == 'r')) {
for (i = x2; i < 8; i++) {
if (getpiece(b, i, y2) == 'r') {
place(b, 0, x, y); /* clear previous square */
@@ -1207,7 +1207,7 @@ board_playmoves(struct board *b, const char *moves)
break;
}
}
- } else if (x2 < x - 1 || takepiece == 'r') {
+ } else if (x2 < x - 1 || (x2 < x && takepiece == 'r')) {
/* black: queenside castling */
for (i = x2; i >= 0; i--) {
if (getpiece(b, i, y2) == 'r') {