URI:
       pedantic fix: "is in check" for illegal king position - chess-puzzles - chess puzzle book generator
  HTML git clone git://git.codemadness.org/chess-puzzles
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit f6061bfecd18263a16740fc9e7d5963256067acc
   DIR parent aef0f99f15006e8c8866938af32cebb8bb8ea7bf
  HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Fri,  9 Jan 2026 18:40:40 +0100
       
       pedantic fix: "is in check" for illegal king position
       
       Check the first king that is in check depending on who's side it is to play.
       
       This tests for an illegal king position which is of course illegal.
       
       Test with only white kings used to be in check/highlighted (fixed now):
       ./fen -o tty '8/1KK2KK1/1KK2KK1/8/3PP3/P6P/1P4P1/2PPPP2 w - - 0 1'
       
       ./fen -o tty '8/1Kk2KK1/1KK2KK1/8/3PP3/P6P/1P4P1/2PPPP2 w - - 0 1'
       ./fen -o tty '8/1Kk2KK1/1KK2KK1/8/3PP3/P6P/1P4P1/2PPPP2 b - - 0 1'
       
       Diffstat:
         M fen.c                               |       3 ++-
       
       1 file changed, 2 insertions(+), 1 deletion(-)
       ---
   DIR diff --git a/fen.c b/fen.c
       @@ -769,7 +769,8 @@ isincheck(struct board *b, int side)
                        x = kingx + king[j];
                        y = kingy + king[j + 1];
                        piece = getpiece(b, x, y);
       -                if (piece && strchr("kK", piece))
       +                if ((side == 'w' && piece == 'k') ||
       +                    (side == 'b' && piece == 'K'))
                                return 1;
                }