lichess-org / chessground

Mobile/Web chess UI for lichess.org
https://lichess.org
GNU General Public License v3.0
1.02k stars 262 forks source link

Certain fens showing the wrong king in check #243

Closed thinktt closed 1 year ago

thinktt commented 1 year ago
import { Chessground } from './node_modules/chessground/chessground.js';

const config = {
  fen: '2k1R3/8/1BK5/7p/P6P/5P2/8/8 b - - 26 61',;
  check: true,
}

const cg = Chessground(document.getElementById('chessground'), config)

Screenshot 2022-12-27 205156

Only seems to happen with certain random fens. Other fens causing the issue as well:

6r1/1p5k/3p4/p4p1R/2P2P2/4P3/PK5P/6R1 b - - 0 30
6r1/1p5k/3p4/p4p1R/2P2P2/4P3/PK5P/6R1 b - - 0 30
r7/1b1r1pQk/p6p/1pp4P/2P1P3/4PNR1/PPn1BKP1/8 b - - 3 33
R5k1/8/6K1/8/3Pp3/4P3/8/8 b - - 24 63
8/kQK5/8/8/3P4/2P1P3/8/8 b - - 8 59

Note, at least all these examples are with the White king when it is blacks move

Workaround: Simply make sure you set check to the actual color that is in check.

const config = {
  fen: '2k1R3/8/1BK5/7p/P6P/5P2/8/8 b - - 26 61',
  check: 'black',
}
niklasf commented 1 year ago

This is by design. Since chessground itself does not know about chess rules, the configuration needs to be explicit.

true means the side that is configured as movable (not necessarily the turn from the FEN). In the given examples, this is always white by default, so it's always the white king that is assumed to be in check.

I would recommend using only 'white' | 'black' | false.

https://github.com/lichess-org/chessground/blob/755388ed3a84593eb99396ba616f47c41fa438d0/src/config.ts#L11

thinktt commented 1 year ago

Makes sense. Thanks.