add '()' to support python3
This commit is contained in:
parent
9583a14856
commit
0fdbaef1a1
@ -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.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user