diff -r d20887f0e8b3 -r d0c3d3016650 src/chess/fen.c --- a/src/chess/fen.c Thu Sep 03 15:28:54 2026 +0200 +++ b/src/chess/fen.c Thu Sep 03 16:18:24 2026 +0200 @@ -77,40 +77,12 @@ return 1; } -static bool fen_castling_chkmoved(GameState *gamestate, - Rank rank, File file) { - - for (unsigned i = 0 ; i < gamestate->movecount ; i++) { - if (gamestate->moves[i].fromfile == file - && gamestate->moves[i].fromrank == rank) { - return true; - } - } - - return false; -} - static size_t fen_castling(char *str, GameState *gamestate) { - bool K, Q, k, q; - - if (fen_castling_chkmoved(gamestate, rankidx('1'), fileidx('e'))) { - K = Q = false; - } else { - K = !fen_castling_chkmoved(gamestate, rankidx('1'), fileidx('h')); - Q = !fen_castling_chkmoved(gamestate, rankidx('1'), fileidx('a')); - } - if (fen_castling_chkmoved(gamestate, rankidx('8'), fileidx('e'))) { - k = q = false; - } else { - k = !fen_castling_chkmoved(gamestate, rankidx('8'), fileidx('h')); - q = !fen_castling_chkmoved(gamestate, rankidx('8'), fileidx('a')); - } - size_t i = 0; - if (K) str[i++] = 'K'; - if (Q) str[i++] = 'Q'; - if (k) str[i++] = 'k'; - if (q) str[i++] = 'q'; + if (!gamestate->castling.K) str[i++] = 'K'; + if (!gamestate->castling.Q) str[i++] = 'Q'; + if (!gamestate->castling.k) str[i++] = 'k'; + if (!gamestate->castling.q) str[i++] = 'q'; if (!i) str[i++] = '-'; return i;