cm-pgn icon indicating copy to clipboard operation
cm-pgn copied to clipboard

Add Multiple variations to history fails with invalid move error

Open pouyaSamie opened this issue 3 years ago • 1 comments

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.

pouyaSamie avatar Aug 09 '21 20:08 pouyaSamie

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

shaack avatar Aug 11 '21 09:08 shaack

"f3" is certainly an invalid move for black.

I suspect what you meant is:

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

shaack avatar Jun 24 '24 13:06 shaack