From fcaa571b420341c6f1ab484cb8798fd31701b7a0 Mon Sep 17 00:00:00 2001 From: rtz19970824 Date: Fri, 12 Jan 2018 21:48:01 +0800 Subject: [PATCH] add the interface in engine.py --- .gitignore | 1 + AlphaGo/engine.py | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8ee6691..3395b0a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ checkpoint .DS_Store data .log +go-* diff --git a/AlphaGo/engine.py b/AlphaGo/engine.py index d298aea..caa446e 100644 --- a/AlphaGo/engine.py +++ b/AlphaGo/engine.py @@ -5,6 +5,7 @@ # $Author: renyong15 © # +import sys from game import Game import copy import numpy as np @@ -187,9 +188,23 @@ class GTPEngine(): board = board.flatten().tolist() return board, True + def cmd_print_board(self, args, **kwargs): + board = copy.deepcopy(self._game.board) + print(board) + return None, True + def cmd_get_prob(self, args, **kwargs): return self._game.prob, True -if __name__ == "main": +if __name__ == "__main__": print ("test engine.py") + game = Game(name='reversi') + engine = GTPEngine(game_obj=game) + print ("Engine initialized!") + cmd = raw_input + while not engine.disconnect: + command = cmd() + result = engine.run_cmd(command) + sys.stdout.write(result) + sys.stdout.flush()