From 0fdbaef1a19e6de4ae866fd59ea05428dfe12bfa Mon Sep 17 00:00:00 2001 From: mcgrady00h <281130306@qq.com> Date: Mon, 25 Dec 2017 15:33:17 +0800 Subject: [PATCH 1/3] add '()' to support python3 --- AlphaGo/play.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/AlphaGo/play.py b/AlphaGo/play.py index 5777982..4e4aa6f 100644 --- a/AlphaGo/play.py +++ b/AlphaGo/play.py @@ -5,7 +5,14 @@ import re import Pyro4 import time import os -import cPickle + +python_version = sys.version_info + +if python_version < (3, 0): + import cPickle +else: + import _pickle as cPickle + class Data(object): def __init__(self): @@ -53,7 +60,7 @@ if __name__ == '__main__': # start a name server if no name server exists if len(os.popen('ps aux | grep pyro4-ns | grep -v grep').readlines()) == 0: start_new_server = subprocess.Popen(['pyro4-ns', '&']) - print "Start Name Sever : " + str(start_new_server.pid) # + str(start_new_server.wait()) + print("Start Name Sever : " + str(start_new_server.pid)) # + str(start_new_server.wait()) time.sleep(1) # start two different player with different network weights. @@ -73,12 +80,15 @@ if __name__ == '__main__': server_list = "" while (black_role_name not in server_list) or (white_role_name not in server_list): - server_list = subprocess.check_output(['pyro4-nsc', 'list']) - print "Waiting for the server start..." + if python_version < (3, 0): + server_list = subprocess.check_output(['pyro4-nsc', 'list']) + else: + server_list = subprocess.check_output(['pyro4-nsc', 'list']) + print("Waiting for the server start...") time.sleep(1) - print server_list - print "Start black player at : " + str(agent_v0.pid) - print "Start white player at : " + str(agent_v1.pid) + print(server_list) + print("Start black player at : " + str(agent_v0.pid)) + print("Start white player at : " + str(agent_v1.pid)) data = Data() player = [None] * 2 @@ -109,12 +119,12 @@ if __name__ == '__main__': board = eval(board[board.index('['):board.index(']') + 1]) for i in range(size[game_name]): for j in range(size[game_name]): - print show[board[i * size[game_name] + j]] + " ", - print "\n", + print(show[board[i * size[game_name] + j]] + " ",) + print("\n",) data.boards.append(board) start_time = time.time() move = player[turn].run_cmd(str(num) + ' genmove ' + color[turn] + '\n') - print role[turn] + " : " + str(move), + print(role[turn] + " : " + str(move),) num += 1 match = re.search(pattern, move) if match is not None: @@ -133,7 +143,7 @@ if __name__ == '__main__': prob = eval(prob) data.probs.append(prob) score = player[turn].run_cmd(str(num) + ' get_score') - print "Finished : ", score.split(" ")[1] + print("Finished : ", score.split(" ")[1]) # TODO: generalize the player if eval(score.split(" ")[1]) > 0: data.winner = 1 @@ -157,8 +167,8 @@ if __name__ == '__main__': print(e) subprocess.call(["kill", "-9", str(agent_v0.pid)]) subprocess.call(["kill", "-9", str(agent_v1.pid)]) - print "Kill all player, finish all game." + print("Kill all player, finish all game.") subprocess.call(["kill", "-9", str(agent_v0.pid)]) subprocess.call(["kill", "-9", str(agent_v1.pid)]) - print "Kill all player, finish all game." + print("Kill all player, finish all game.") From 64da200e5d4d4cff8c1642f4def897cefadbb87d Mon Sep 17 00:00:00 2001 From: Dong Yan Date: Mon, 25 Dec 2017 16:26:51 +0800 Subject: [PATCH 2/3] move , from inside of () to outside of () --- AlphaGo/play.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AlphaGo/play.py b/AlphaGo/play.py index 4e4aa6f..b3cc02a 100644 --- a/AlphaGo/play.py +++ b/AlphaGo/play.py @@ -75,7 +75,7 @@ if __name__ == '__main__': agent_v1 = subprocess.Popen( ['python', '-u', 'player.py', '--game=' + game_name, '--role=' + white_role_name, - '--checkpoint_path=' + str(args.black_weight_path), '--debug=' + str(args.debug)], + '--checkpoint_path=' + str(args.white_weight_path), '--debug=' + str(args.debug)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) server_list = "" @@ -119,12 +119,12 @@ if __name__ == '__main__': board = eval(board[board.index('['):board.index(']') + 1]) for i in range(size[game_name]): for j in range(size[game_name]): - print(show[board[i * size[game_name] + j]] + " ",) - print("\n",) + print(show[board[i * size[game_name] + j]] + " "), + print("\n"), data.boards.append(board) start_time = time.time() move = player[turn].run_cmd(str(num) + ' genmove ' + color[turn] + '\n') - print(role[turn] + " : " + str(move),) + print(role[turn] + " : " + str(move)), num += 1 match = re.search(pattern, move) if match is not None: From fcb160dff674f3d587dfd61a79ceffaeacb18ba1 Mon Sep 17 00:00:00 2001 From: Dong Yan Date: Mon, 25 Dec 2017 16:35:43 +0800 Subject: [PATCH 3/3] fix python 2,3 print format error --- AlphaGo/play.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AlphaGo/play.py b/AlphaGo/play.py index b3cc02a..e67621a 100644 --- a/AlphaGo/play.py +++ b/AlphaGo/play.py @@ -143,7 +143,7 @@ if __name__ == '__main__': prob = eval(prob) data.probs.append(prob) score = player[turn].run_cmd(str(num) + ' get_score') - print("Finished : ", score.split(" ")[1]) + print("Finished : {}".format(score.split(" ")[1])) # TODO: generalize the player if eval(score.split(" ")[1]) > 0: data.winner = 1