shaack / cm-pgn

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

Add Multiple variations to history fails with invalid move error #10

Closed pouyaSamie closed 3 months ago

pouyaSamie commented 3 years ago

Hi

if you try to add more than 3 variations to a move it will fail with the invalid move error.

should add a variant and render it => fail Error: invalid move

these moves are valid I tested them on lichess.

from the History test I tried to change the history test like this

    it("should add a variant and render it", () => {
    const history = new History();
    const ply1 = history.addMove("e4");
    history.addMove("e6");
    history.addMove("d3");
    history.addMove("d5");
    history.addMove("Nd2");

    history.addMove("e5", ply1);
    history.addMove("f3", ply1);
    history.addMove("e6", ply1);
    history.addMove("Ne2", ply1);
    assert.equals(history.moves[1].variations.length, 4);
  });

if I manage to fix this issue I will post the solution here. also, I can send a pull request for render variations.

shaack commented 3 years ago

Thanks for your report. I will take a look to the problem.

shaack commented 3 months ago

"f3" is certainly an invalid move for black.

I suspect what you meant is:

const ply2 = history.addMove("e5", ply1);
history.addMove("f3", ply2);