Created
August 18, 2018 08:53
-
-
Save mooskagh/7aebe158913119edc74d2ef5ced4af96 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: | |
# ./ucihost.py tcec.log ./lc0-tcec -t 1 --verbose-move-stats | |
############################################################################## | |
import sys | |
import subprocess | |
GAME = [ | |
'd2d4', 'g8f6', 'g1f3', 'd7d5', 'c2c4', 'e7e6', 'g2g3', 'f8b4', 'c1d2', | |
'b4e7', 'f1g2', 'e8g8', 'e1g1', 'd5c4', 'd1a4', 'c7c6', 'a4c4', 'b7b6', | |
'b1c3', 'c8a6', 'c4b3', 'b8d7', 'f1d1', 'f6d5', 'e2e4', 'd5c3', 'b3c3', | |
'a6b7', 'd2f4', 'd8c8', 'a1c1', 'f8d8', 'c3e1', 'e7f8', 'f3d2', 'd7f6', | |
'd2c4', 'h7h6', 'b2b4', 'c8d7', 'a2a3', 'd7e8', 'f4e5', 'f6g4', 'e5f4', | |
'g4f6', 'h2h3', 'a8c8', 'f4e3', 'b7a6', 'd1d2', 'f6d7', 'e4e5', 'a6b5', | |
'e1d1', 'a7a5', 'b4a5', 'b6a5', 'c4a5', 'f8a3', 'c1b1', 'c8c7', 'd1c2', | |
'd8c8', 'a5c4', 'a3f8', 'c4d6', 'f8d6', 'e5d6', 'c7a7', 'c2d1', 'd7f6', | |
'd4d5', 'a7d7', 'd5e6', 'e8e6', 'd1c2', 'c8e8', 'e3c5', 'd7d8', 'g1h2', | |
'f6d7', 'c5b4', 'd7f6', 'b1a1', 'h6h5', 'a1a7', 'h5h4', 'a7e7', 'e8e7', | |
'd6e7', 'h4g3', 'f2g3', 'd8d2', 'c2d2', 'b5c4', 'd2d8', 'g8h7', 'd8d6', | |
'e6e2', 'd6d2', 'e2d2', 'b4d2', 'c4d5', 'g2f1', 'd5e6', 'd2b4', 'e6d7', | |
'f1d3', 'g7g6', 'g3g4', 'f6d5', 'b4c5', 'f7f6', 'h3h4', 'h7g7', 'd3c4', | |
'g7f7', 'h4h5', 'f7g7', 'h2g3', 'd7e8', 'g3h4', 'g6h5', 'g4h5', 'd5f4', | |
'c5d6', 'f4g2', 'h4h3', 'g2e3', 'c4e6', 'e3d5', 'h3h4', 'g7h8', 'h4g4', | |
'h8h7', 'd6c5', 'h7g7', 'e6f5', 'g7h6', 'g4h4', 'h6g7', 'c5a3', 'd5c7', | |
'a3c1', 'c7d5', 'h5h6', 'g7f7', 'c1a3', 'd5e3', 'f5e4', 'e3d5', 'a3c5', | |
'f7g8' | |
] | |
NODES_VARIANTS = [100, 1000, 10000] | |
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.args = args | |
def start(self, title): | |
self.Log('') | |
self.Log('=====================================================') | |
self.Log(' '.join(self.args)) | |
self.Log(' '.join(GAME)) | |
self.Log(title) | |
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 nodes in NODES_VARIANTS: | |
go_cmd = "go nodes %d" % nodes | |
eng.start(go_cmd) | |
eng.Send('ucinewgame') | |
eng.Send('isready') | |
eng.Wait('readyok') | |
moves = 'moves' | |
bestmoves = [] | |
for x in GAME: | |
eng.Send("position startpos %s" % moves) | |
moves += ' ' + x | |
eng.Send(go_cmd) | |
resp = eng.Wait("bestmove") | |
bestmove = resp.split()[1] | |
bestmoves.append(bestmove) | |
eng.Log("######## Bestmoves [%s] [%s]" % (go_cmd, sys.argv[1])) | |
for x in bestmoves: | |
eng.Log(x) | |
eng.Send('quit') | |
eng.log.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment