Closed joshrouwhorst closed 3 years ago
~~Yes, thanks for reporting. This looks like a problem of chess.js, because, when I initialize chess.js with this fen: r1bqk2r/pppp1ppp/2n2n2/4p3/1bB1P3/2NP4/PPP2PPP/R1BQK1NR w KQkq - 1 5~~
chess.js returns "null", when moving "Nge2":
<script src="https://cdnjs.cloudflare.com/ajax/libs/chess.js/0.10.3/chess.min.js"></script>
<script>
let chess = new Chess("r1bqk2r/pppp1ppp/2n2n2/4p3/1bB1P3/2NP4/PPP2PPP/R1BQK1NR w KQkq - 1 5")
let result = chess.move("Nge2")
console.log(result) // is null
</script>
What do you think, did we both miss something or is it a failure in chess.js?
OK, I got it, it is described in the documentation of chess.js, under .move(move, [ options ])
about the sloppy
flag, is written:
// correctly parses incorrectly disambiguated moves
chess = new Chess(
'r2qkbnr/ppp2ppp/2n5/1B2pQ2/4P3/8/PPP2PPP/RNB1K2R b KQkq - 3 7'
)
chess.move('Nge7') // Ne7 is unambiguous because the knight on c6 is pinned
// -> null
chess.move('Nge7', { sloppy: true })
// -> { color: 'b', from: 'g8', to: 'e7', flags: 'n', piece: 'n', san: 'Ne7' }
So move Nge2 is wrong because it is unambiguous, correct would be "Ne2".
But I have adjusted something, I have now also included the "sloppy" flag in the constructor of Pgn, so now it works if you use new Pgn(sloppyPgn, {sloppy: true})
.
That worked for me! Thanks!
Hi, I'm working on building my own PGN viewer and this package looks like it would be really helpful. I am getting an IllegalMoveException on what seems to be a legal move, however.
Here is the PGN:
The error I get is this:
IllegalMoveException: r1bqk2r/pppp1ppp/2n2n2/4p3/1bB1P3/2NP4/PPP2PPP/R1BQK1NR w KQkq - 1 5 => Nge2
I tried running the PGN through the Chess Tempo PGN viewer and did not have an issue. Unless there is something I'm missing I don't believe any Nge2 moves in this are illegal.
Let me know if any other info would be helpful! Thanks!