mliebelt / pgn-viewer

Simple PGN viewer with the necessary features to display chess games
GNU General Public License v3.0
164 stars 44 forks source link

GoTo specific move number #482

Open mliebelt opened 10 months ago

mliebelt commented 10 months ago

Discussed in https://github.com/mliebelt/PgnViewerJS/discussions/481

Originally posted by **RasmusRow** December 17, 2023 Hi, I can't seem to figure out if it's possible to programmatically forward/rewind the game to a specific move number. Just like the notation already provided in the library, but I'd like to be able to implement some custom functionality that allows to me to click a button somewhere on the page that triggers the same event as when I click on a move number in the notations. I hope it makes sense :) Thank you for your work!
mliebelt commented 10 months ago

You are right, there is no API to do something like that. I checked the API again, at the moment, you can only do manual moves from one position to the next.

So let me write down the requirement: The user should be able to jump to any position in the game denoted by the move number. The move number is denoted by the array index of the half moves done. In the game e4 e5 Nf3 Nc6 the move numbers are: 1 e4 2 e5 3 Nf3 4 Nc6.

What about variants? We cannot say which move number will be which move in which variant (at least not so simple). For the moment, this would only work for the main line.

mliebelt commented 10 months ago

There is a similar functionality already implemented, see #171 The ideas from that implementation could be moved.

Requirements would be:

  1. This works only to repeat moves already done.
  2. The moves are the moves of the main line (only). Later on, we may find a way to address moves from the variant (like in the 5th move, the 1st variant, the 3rd move == 5.v1.3. Too complicated at the moment.
  3. The moves are counted from 0 onward, so the moves of the notation 1. e4 e5 2. Nf3 Nc6 will be: 0 e4 1 e5 2 Nf3 3 Nc6.
mliebelt commented 10 months ago

Did a quick hack, there are many things missing (yet). But demonstrates that jumping to a move is not a big deal ..