Created
August 18, 2018 08:56
-
-
Save mooskagh/6510320ed4c13c4c07ba5cca0afd4557 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
############################################################################## | |
# Running: | |
# ./ucimove.py tcec-2.log ./lc0-tcec -t 1 --verbose-move-stats | |
############################################################################## | |
import sys | |
import subprocess | |
MOVES = ("d2d4 g8f6 g1f3 d7d5 c2c4 e7e6 g2g3 f8b4 c1d2 b4e7 f1g2 " | |
"e8g8 e1g1 d5c4 d1a4 c7c6 a4c4") | |
class Engine: | |
def __init__(self, logfile, args): | |
self.process = subprocess.Popen( | |
args, | |
stdin=subprocess.PIPE, | |
stdout=subprocess.PIPE, | |
universal_newlines=True) | |
self.log = open(logfile, 'a') | |
self.Log('') | |
self.Log('=====================================================') | |
self.Log(' '.join(args)) | |
self.Log(MOVES) | |
self.Log('=====================================================') | |
def Log(self, line): | |
self.log.write("%s\n" % line) | |
def Send(self, s): | |
self.Log('') | |
self.Log("]> %s" % s) | |
print("> %s" % s) | |
self.process.stdin.write("%s\n" % s) | |
self.process.stdin.flush() | |
def Wait(self, s): | |
while True: | |
line = self.process.stdout.readline().rstrip() | |
self.Log("< %s" % line) | |
if line.startswith(s): | |
print("< %s" % line) | |
return line | |
eng = Engine(sys.argv[1], sys.argv[2:]) | |
for x in range(1000): | |
eng.Send('ucinewgame') | |
eng.Send('isready') | |
eng.Wait('readyok') | |
eng.Send("position startpos moves %s" % MOVES) | |
eng.Send("go nodes %d" % x) | |
resp = eng.Wait("bestmove") | |
bestmove = resp.split()[1] | |
eng.Send('quit') | |
eng.log.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment