atw1020 / sente

Sente is an open source python library for the game of Go
https://sente.readthedocs.io/en/latest/index.html
MIT License
21 stars 4 forks source link

Require Sabaki to jump to a certain node #33

Open jcguu95 opened 2 years ago

jcguu95 commented 2 years ago

Awesome package! Thank you so much for implementing sente. Plus, the documentation is clearly written. I'm very excited!

As discussed here, I'm trying to use sente to ask Sabaki to jump to a specific node of a specific sgf file. While sente can serve as an AI (after implementing our own genmove()), I'm certain that it won't be hard to achieve my goal. Would you mind sharing how?

atw1020 commented 2 years ago

Hi Jin, I'm glad to hear you liked my package! :)

As mentioned in the thread you linked, the GTP command you are looking for is loadsgf. However, I think that implementing this will be a little bit tricky because of the controller/responder nature of GTP and limitations in the current sente implementation of GTP.

In general, there are two kinds of programs in GTP:

Responders: Responders are programs that respond to stimuli from another program. Most AIs are responders and only do anything when they are asked. Sente's gtp.Session object is a Responder.

Controllers: Controllers are the programs that issue commands to responders. They are responsible for enforcing rules and forwarding instructions between multiple responders.

You can see a list of typical use cases in the GTP documentation. Sabaki uses the second case, where the GUI is the controller and the engine is a responder. The loadsgf command you wish to use is, like most commands issued by a controller to a responder. Therefore, what you want to implement is a controller with two responders: One responder being your AI and the other responder being Sabaki.

There are two problems with doing this. The first is kinda embarrassing for me, sente does not currently have a Controller class implemented (there are files for it but they are empty 🤦). This means that until I can implement the controller, you are on your own for implementing a GTP controller. I don't think implementing a special case controller is too difficult to do in python, you really only need to forward stone placements between the two responders and also call loadsgf. Sente will probably implement a GTP controller class in the next major update. If you choose to do this I recommend running a GTP session in a terminal with a sente session as seen in the docs. That will help you get to know the basic syntax and response structure.

The second problem is that I am unaware of any way for Sabaki to behave as a responder rather than a controller. I wouldn't be surprised if Sabaki does have such functionality, but most people who use GTP in Sabaki are trying to get Sabaki to play an engine so I wouldn't be surprised if it's buried deep somewhere. I would check the Sabaki Command line arguments.

As you can see, getting this to work with GUIs can be quite tedious. If it's absolutely necessary for your AI by all means continue, but I would reconsider how beneficial it is to get these GUIs working. Please let me know what you end up doing

jcguu95 commented 2 years ago

Hi @atw1020,

Thanks for your timely response. I did not expect the difficulties, and it's certainly helpful to learn them in advanced. Let me clarify what my goal here is, and please let me know if there are some other workarounds.

I want a better way to take notes about go. So far, most people use comments in sgf. While that's fine, it's very far from being programmable. What I have in mind is to be able to take notes in org-mode (a stronger version of markdown). You can imagine adding links like sgf://~/game.sgf::[node-id] to markdown, which serves as a link that brings us to the specified node displayed in a GUI. This way, many people can easily create notes for several sgf files all at once. For example, I can create a text file for josekis following a certain movement.

What's blocking me from achieving my goal is a programmable way to jump to a specific node and make it displayed in a GUI. That is what motivated me. Perhaps you happen to know some other software that's helpful for this? I'm excited to hear more from you. Thanks again!

atw1020 commented 2 years ago

So to make sure I'm understanding you correctly, you want to have a user click a link in this "org-mode" and have it open an SGF file to a specific move?

jcguu95 commented 2 years ago

Yes!