shaack / cm-pgn

Parse and create PGNs (Portable Game Notation for chess games)
MIT License
29 stars 20 forks source link

Can this give the FEN of a specific move? #7

Closed purefan closed 3 years ago

purefan commented 4 years ago

say I want to know the fen after e4 e5 Nf3, is there a way to do this with cm-pgn?

shaack commented 3 years ago

Yes, after parsing pgn.history.moves is an array, where every move has an attribute fen, like this:

const gamePgn = `[SetUp "1"]
[FEN "4k3/pppppppp/8/8/8/8/PPPPPPPP/4K3 w - - 0 1"]

1. e4`

const pgn = new Pgn(gamePgn)
Assert.equals(pgn.history.moves[0].fen, "4k3/pppppppp/8/8/4P3/8/PPPP1PPP/4K3 b - e3 0 1")