start a random player if checkpoint path is not specified

This commit is contained in:
rtz19970824 2017-12-19 15:39:31 +08:00
parent d7b3b6aba9
commit fae273f219
2 changed files with 22 additions and 14 deletions

View File

@ -1,3 +1,4 @@
import argparse
import subprocess import subprocess
import sys import sys
import re import re
@ -11,14 +12,17 @@ if __name__ == '__main__':
Note that, this function requires the installation of the Pyro4 library. Note that, this function requires the installation of the Pyro4 library.
""" """
# TODO : we should set the network path in a more configurable way. # TODO : we should set the network path in a more configurable way.
black_weight_path = "./checkpoints" parser = argparse.ArgumentParser()
white_weight_path = "./checkpoints_origin" parser.add_argument("--black_weight_path", type=str, default=None)
if (not os.path.exists(black_weight_path)): parser.add_argument("--white_weight_path", type=str, default=None)
print "Can't not find the network weights for black player." args = parser.parse_args()
sys.exit()
if (not os.path.exists(white_weight_path)): # black_weight_path = "./checkpoints"
print "Can't not find the network weights for white player." # white_weight_path = "./checkpoints_origin"
sys.exit() if args.black_weight_path is not None and (not os.path.exists(args.black_weight_path)):
raise ValueError("Can't not find the network weights for black player.")
if args.white_weight_path is not None and (not os.path.exists(args.white_weight_path)):
raise ValueError("Can't not find the network weights for white player.")
# kill the old server # kill the old server
kill_old_server = subprocess.Popen(['killall', 'pyro4-ns']) kill_old_server = subprocess.Popen(['killall', 'pyro4-ns'])
@ -31,14 +35,16 @@ if __name__ == '__main__':
time.sleep(1) time.sleep(1)
# start two different player with different network weights. # start two different player with different network weights.
agent_v0 = subprocess.Popen(['python', '-u', 'player.py', '--role=black'], agent_v0 = subprocess.Popen(['python', '-u', 'player.py', '--role=black', '--checkpoint_path=' + str(args.black_weight_path)],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
agent_v1 = subprocess.Popen(['python', '-u', 'player.py', '--role=white', '--checkpoint_path=./checkpoints_origin/'],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) agent_v1 = subprocess.Popen(['python', '-u', 'player.py', '--role=white', '--checkpoint_path=' + str(args.white_weight_path)],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
server_list = "" server_list = ""
while ("black" not in server_list) or ("white" not in server_list): while ("black" not in server_list) or ("white" not in server_list):
server_list = subprocess.check_output(['pyro4-nsc', 'list']) server_list = subprocess.check_output(['pyro4-nsc', 'list'])
print "Waining for the server start..." print "Waiting for the server start..."
time.sleep(1) time.sleep(1)
print server_list print server_list
print "Start black player at : " + str(agent_v0.pid) print "Start black player at : " + str(agent_v0.pid)

View File

@ -22,10 +22,12 @@ class Player(object):
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--checkpoint_path", type=str, default="./checkpoints/") parser.add_argument("--checkpoint_path", type=str, default=None)
parser.add_argument("--role", type=str, default="unknown") parser.add_argument("--role", type=str, default="unknown")
args = parser.parse_args() args = parser.parse_args()
if args.checkpoint_path == 'None':
args.checkpoint_path = None
game = Game(checkpoint_path=args.checkpoint_path) game = Game(checkpoint_path=args.checkpoint_path)
engine = GTPEngine(game_obj=game, name='tianshou', version=0) engine = GTPEngine(game_obj=game, name='tianshou', version=0)