Tianshou/AlphaGo/self-play.py

41 lines
971 B
Python
Raw Normal View History

2017-12-05 23:17:20 +08:00
from game import Game
from engine import GTPEngine
2017-12-05 23:42:18 +08:00
import re
2017-12-05 23:17:20 +08:00
g = Game()
2017-12-07 17:51:58 +08:00
pattern = "[A-Z]{1}[0-9]{1}"
2017-12-05 23:17:20 +08:00
g.show_board()
e = GTPEngine(game_obj=g)
num = 0
black_pass = False
white_pass = False
while not (black_pass and white_pass):
if num % 2 == 0:
2017-12-05 23:42:18 +08:00
res = e.run_cmd(str(num) + " genmove BLACK")
2017-12-05 23:17:20 +08:00
num += 1
2017-12-07 17:51:58 +08:00
# print(res)
match = re.search(pattern, res)
if match is not None:
print(match.group())
else:
print("pass")
2017-12-05 23:42:18 +08:00
if re.search("pass", res) is not None:
2017-12-05 23:17:20 +08:00
black_pass = True
2017-12-05 23:42:18 +08:00
else:
black_pass = False
2017-12-05 23:17:20 +08:00
else:
2017-12-05 23:42:18 +08:00
res = e.run_cmd(str(num) + " genmove WHITE")
2017-12-05 23:17:20 +08:00
num += 1
2017-12-07 17:51:58 +08:00
match = re.search(pattern, res)
if match is not None:
print(match.group())
else:
print("pass")
2017-12-05 23:42:18 +08:00
if re.search("pass", res) is not None:
2017-12-05 23:17:20 +08:00
white_pass = True
2017-12-05 23:42:18 +08:00
else:
white_pass = False
2017-12-05 23:17:20 +08:00
g.show_board()