kaorahi / lizgoban

Leela Zero & KataGo visualizer
GNU General Public License v3.0
169 stars 28 forks source link

About move mapping between PV and Main Board #110

Closed qcgm1978 closed 7 months ago

qcgm1978 commented 7 months ago

In this project, the Main Board is responsible for the main chess process, and the PV is responsible for the AI's recommendation for the current move. There is a common problem that users may have questions about certain moves on the PV board. They may want to know how the AI would respond if they played a different move. This requires more flexible interaction with the PV board.

One possible solution is to use hotkeys. For example, on a Mac, pressing Command+number key would automatically display the changes on the PV board in the Main Board. This would allow users to quickly and easily explore different moves and see how the AI would respond.

The code and effect video are as follows.

https://github.com/kaorahi/lizgoban/assets/3024299/bbb1b752-b613-4117-91a8-61a40f0a34da

document.addEventListener('keydown', e => {
  if (/^M-\d+$/.test(key)) {
          map_var_to_main({ e, ind: parseInt(e.key-1) });
  }
...
})
map_var_to_main = async function ({ clicked_move, e = {}, ind }) {
        const variation = R[`game_${R.sequence_cursor}`][R.move_count].variation;
        if (!ind) {
            ind = clicked_move ? variation.findIndex(h => h == clicked_move) : variation.length - 1;
        }
        if (!read_only && !R.attached) {
            for (let i = 0; i <= ind; i++) {
                // todo don't know why ko not correct if not async callback
                await new Promise(r => {
                    const force_create = !Boolean(ind);
                    const bool = play_here({ e, coord2idx, canvas, force_create, move: variation[i] });
                    if (bool) {
                        set_showing_movenum_p(false);
                        hover_off(canvas);
                    }
                    setTimeout(() => {
                        r();
                    }, 100);
                });
            }
        }
    }
kaorahi commented 7 months ago

Is this just a free discussion, or do you expect me to take some action?

Anyway, your proposal isn't clear to me since your code appears to depend on other unspecified modifications to the original code.

If I understand correctly, this is similar to the functionality of , key. Currently, we use , key to play the PV on the main board. Your update seems to introduce (1) animation and (2) an "until this move" feature to this existing function. Is my understanding correct?

To seriously investigate PVs, I prefer to push RET key repeatedly because PV obtained with , key is often unreliable. My main use of , key is for quickly setting up random game situations for demos or debugging.

qcgm1978 commented 7 months ago

Sorry, I overlooked the functions of the , key and return key. On the one hand, this is because I don't understand the project's functionality well enough. On the other hand, I'm concerned that the code changes I made may have affected some of the functions.

You're right, the function I proposed is very similar to the functions of these two keys. The only difference is that it allows for more precise control using the number keys. However, this seems unnecessary.

Additionally, it seems like the README should include some instructions about the keyboard shortcuts. This would help to ensure that users don't overlook these features. For example, a table could be provided, similar to the following( Of course, this is a matter of personal preference. Some users may prefer to read the README, while others may prefer to look at the help page in the application. ):

Shortcut keys

Game

Key Function
up/left arrow previous move (Shift = 15 moves)
down/right arrow next move (Shift = 15 moves)
Home first move
End last move
BS/Del undo
p pass
# show comment
kaorahi commented 7 months ago

thx for the suggestion. At least, I'll add some text to README so users can notice the app's Help menu.

For information about the displayed marks, shortcut keys, and other features, refer to the "Help" menu in the app.

Generally, maintaining the same content in two places can lead to inconsistencies unless it's auto-generated from a single source.

kaorahi commented 7 months ago

README is updated.