Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how would I implement receiving moves from a server? #61

Closed
ISibboI opened this issue Nov 30, 2020 · 10 comments
Closed

Question: how would I implement receiving moves from a server? #61

ISibboI opened this issue Nov 30, 2020 · 10 comments

Comments

@ISibboI
Copy link

ISibboI commented Nov 30, 2020

I would like to hook up lizgoban to OGS to make every move of an OGS game appear live in lizgoban.

For that I would be able to do the OGS adapter part, but I do not know how I would make the necessary changes to lizgoban.

My main question is: How do I programmatically enter a move into lizgoban?

@kaorahi
Copy link
Owner

kaorahi commented Dec 1, 2020

After 9ac351f, you can control lizgoban from its STDIN as follows (example on Linux).

$ cd lizgoban/
$ echo 'mimic("play", "D3"); mimic("play", "R4")' | npm start -- -j '{"repl": true}'

See const api = ... in src/main.js for the list of commands. "Debug log" in "Debug" menu will be also useful if you want to observe which API is called for each mouse/keyboard operation. For debugging, you may prefer to type mimic(...) directly on the console with "REPL" in "Debug" menu.

Please note that this feature is experimental and API etc. may be changed in future.

Enjoy!

@ISibboI
Copy link
Author

ISibboI commented Dec 1, 2020

Cool thank you very much!

@ISibboI ISibboI closed this as completed Dec 1, 2020
@qcgm1978
Copy link
Contributor

qcgm1978 commented Nov 2, 2023

Do I need to install any programs before running this command? I am getting the following error message when running it on my Mac:
截屏2023-11-02 11 55 02

Google bard told me: The error message sysctlbyname for kern.hv_vmm_present failed with status -1 means that LizGoban is unable to determine if a hypervisor VMM is present. This is not a critical error, but it may prevent LizGoban from using certain features, such as hardware acceleration.

@kaorahi
Copy link
Owner

kaorahi commented Nov 2, 2023

I think the message 'sysctlbyname ...' is unrelated to this feature. If you notice D3 and R4 stones on the board, the mimic command functions correctly.

Both 'undefined' and 'REPL is closed' messages indicate expected behaviors. The former means that the API returns nothing, while the latter shows that the echo command has finished and its pipe is closed.

@qcgm1978
Copy link
Contributor

About the mimic method, I have some questions:

  1. The application launched by the command does not use the face_image_rule customized in the config.json file in the root directory, but applies the settings in the external/config.json file.

  2. The method "type mimic(...) directly on the console with "REPL" in "Debug" menu" is invalid. C3 isn't played on the board.

截屏2023-11-10 22 09 17
  1. Can mimic be called in other ways besides running in the command line, such as Python? Can we switch to the project folder and run the command line using Python? Is this the correct way to use the interface?

@kaorahi
Copy link
Owner

kaorahi commented Nov 10, 2023

(1)
external/config.json is the default path for the configuration file. The folder containing LizGoban*.exe is also checked in the case of the all-in-one package. See the definitions of default_path_for, default_config_paths, and parse_argv in option.js for details.

(2)
It seems that you are starting lizgoban using echo ... | npm .... Please try just npm start without echo command. You can type any JS code after LizGoban> prompt. echo is not needed here. Just mimic(...) is OK.

(3)
Here is an example. You need d1fe0df or later.

#!/bin/python3

import subprocess
import time

working_directory = '/PATH/TO/LIZGOBAN'
command = 'npm start -- -j \'{"repl": true}\''

process = subprocess.Popen(
    command,
    shell=True,
    stdin=subprocess.PIPE,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    text=True,
    cwd=working_directory,
)

process.stdin.write('mimic("play", "D3")\n')
process.stdin.flush()

time.sleep(3)

process.stdin.write('mimic("play", "R4")\n')
process.stdin.flush()

time.sleep(3)

process.stdin.write('app.quit()\n')
process.stdin.flush()

process.wait()

@qcgm1978
Copy link
Contributor

qcgm1978 commented Nov 11, 2023

You are right. I have been running npm start -- -c config.json, mistakenly thinking that the root directory is the default location of config.json.

npm start without echo command worked. However, running the debug mode in VS Code seems to not support the repl module.

The Python code also ran successfully. I need to further consider how to dynamically obtain data information for synchronous analysis.

Thanks for your guidance!

update: Success! I was able to request data from the website https://19x19.com/engine/live/list/117738?from=%2Fengine%2Flive%2Fdata%2F117738&to=%2Fengine%2Flive%2Fdata%2F117738&liveType=TOP_LIVE and sync it to the application for analysis. Thank you very much!

@qcgm1978
Copy link
Contributor

Encountered a new issue:

The following method works in the command line:

mimic('read_sgf','(;AP[golaxy]CA[UTF-8]KM[6.5]PB[金湊笌]PW[金珉舒]RE[B+R]SZ[19];B[pd];W[dp])')

However, it is invalid when running in Python. The sgf string would not be loaded.

s='(;AP[golaxy]CA[UTF-8]KM[6.5]PB[金凑笌]PW[金珉舒]RE[B+R]SZ[19];B[pd];W[dp])'
command=f"mimic('read_sgf','{s}')"
self.process.stdin.write(command)
self.process.stdin.flush()

@kaorahi
Copy link
Owner

kaorahi commented Nov 14, 2023

missing \n? This works for me.

command=f"mimic('read_sgf','{s}')\n"

@qcgm1978
Copy link
Contributor

You're right. It works if \n added. What's more I have to replace all \n in sgf str if it has or it also doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants