shaack / cm-pgn

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

Variation on White's first move #22

Open jmt1423 opened 4 months ago

jmt1423 commented 4 months ago

Hey! Love the project and what I can do with it, I was just wondering if it is possible to add a variation on the first move of the game with pgn.history.addMove().

So as an example the variation tree should look like:

  1. e4 (1.d4) e5

If it isn't possible I'd be happy to try and work on a solution and create a PR for it, but would like some clarification before I start trying a different solution. Thanks!

shaack commented 3 months ago

@jmt1423 You are right, it is not possible to add a variation on the first move with addMove, because, if you set the parameter previous to null, the method assumes, that you want to add the move at the end of the main history. I don't have a quick idea how to solve this, do you have one?

Maybe setting the string "start" as parameter previous in that case?

const history = new History()
history.addMove("e4")
history.addMove("d4", "start")
history.addMove("e5")