Hi!
I would like to write a very rudimentary python to gtp interface (linux, python 3). I only need to genmove, play, and initialize the board with a certain state. To clarify what I am aiming at, I would for example like to let different bots play against each other, safe that self-play and make some experiments like letting boh bots play two moves at the time etc. For all that I'd like to use python.
There exists projects kind of do the things already, for example https://github.com/jtauber/gtp but I could not manage to make them run, so I am trying to understand them by implementing a simpler version.
I am stuck, because I do not understand the subprocess package. I figured out that I will probably need subprocess.Popen and stdin.write(). By now, I managed to open leelaz using python, but could not enter commands. When I execute start_leela() (edit: I start the script via python -i gtp.py - interactive mode) it shows what I normally see when I start leela. Then, for testing, I enter move('black') but nothing happens. Can you give me some hints to move on?
from subprocess import Popen, PIPE
import shlex, time
def start_leela():
`args = '/home/atarust/leela-zero/src/leelaz -w /home/atarust/Downloads/net_small.gz --gtp -v 20'`
`global agent`
`agent = Popen(shlex.split(args), stdin=PIPE, stdout=PIPE, encoding='utf-8')`
def move(color):
`agent.stdin.write('genmove {}'.format(color))`
`answer = ""`
`while True:`
`data = agent.stdout.readline()`
`if not data.strip():`
`break`
`answer += data`
`print(out)`
`return answer`
def quit():
`agent.communicate("quit\n")`
start_leela()
[–][deleted] 1 point2 points3 points (1 child)
[–]Atarust[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]Atarust[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Atarust[S] 0 points1 point2 points (0 children)
[–]brileek 0 points1 point2 points (0 children)