chess.js icon indicating copy to clipboard operation
chess.js copied to clipboard

"strict" parsing and validation

Open SheetJSDev opened this issue 4 years ago • 0 comments

kkkkkkkk/8/8/8/8/8/8/KKKKKKKK w KQkq - 0 1 specifies a board with 8 white kings in the first row and 8 black kings in the eighth row. This is a valid string under the 1994 standard for the Forsyth-Edwards Notation.

When parsing with chess.js, it is considered valid:

> new Chess().validate_fen("kkkkkkkk/8/8/8/8/8/8/KKKKKKKK w KQkq - 0 1")
{ valid: true, error_number: 0, error: 'No errors.' }

However, the resulting board only has one king for each color:

> new Chess("kkkkkkkk/8/8/8/8/8/8/KKKKKKKK w KQkq - 0 1").board().map((r,i) => [i, r.map((c, j) => c && [i, j, c]).filter(r => r && r[2])]).filter(r => r[1].length).map(r => r[1]).flat()
[
  [ 0, 0, { type: 'k', color: 'b' } ],
  [ 7, 0, { type: 'k', color: 'w' } ]
]
> new Chess("kkkkkkkk/8/8/8/8/8/8/KKKKKKKK w KQkq - 0 1").fen()
'k7/8/8/8/8/8/8/K7 w KQkq - 0 1'

It seems that chess.js is silently "correcting" the specified board and ignoring all kings of a color after the first.

Is there a way to force chess.js to generate an error in cases like these instead of silently correcting the board? One possible approach is to add an option to validate_fen that would generate an error

SheetJSDev avatar Jul 26 '21 19:07 SheetJSDev