2017-12-10 20:23:10 +08:00
|
|
|
import argparse
|
|
|
|
import Pyro4
|
|
|
|
from game import Game
|
|
|
|
from engine import GTPEngine
|
|
|
|
|
|
|
|
@Pyro4.expose
|
|
|
|
class Player(object):
|
2017-12-15 22:19:44 +08:00
|
|
|
"""
|
|
|
|
This is the class which defines the object called by Pyro4 (Python remote object).
|
|
|
|
It passes the command to our engine, and return the result.
|
|
|
|
"""
|
2017-12-10 20:23:10 +08:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
self.role = kwargs['role']
|
|
|
|
self.engine = kwargs['engine']
|
|
|
|
|
|
|
|
def run_cmd(self, command):
|
|
|
|
return self.engine.run_cmd(command)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser()
|
2017-12-28 15:55:07 +08:00
|
|
|
parser.add_argument("--checkpoint_path", type=str, default="None")
|
2017-12-10 20:23:10 +08:00
|
|
|
parser.add_argument("--role", type=str, default="unknown")
|
2017-12-28 15:55:07 +08:00
|
|
|
parser.add_argument("--debug", type=str, default="False")
|
|
|
|
parser.add_argument("--game", type=str, default="go")
|
2017-12-10 20:23:10 +08:00
|
|
|
args = parser.parse_args()
|
2017-12-27 01:04:09 +08:00
|
|
|
if args.checkpoint_path == 'None':
|
|
|
|
args.checkpoint_path = None
|
|
|
|
game = Game(name=args.game, role=args.role,
|
|
|
|
checkpoint_path=args.checkpoint_path,
|
|
|
|
debug=eval(args.debug))
|
2017-12-10 20:23:10 +08:00
|
|
|
engine = GTPEngine(game_obj=game, name='tianshou', version=0)
|
|
|
|
|
|
|
|
daemon = Pyro4.Daemon() # make a Pyro daemon
|
|
|
|
ns = Pyro4.locateNS() # find the name server
|
2017-12-23 14:45:07 +08:00
|
|
|
player = Player(role=args.role, engine=engine)
|
2017-12-27 01:04:09 +08:00
|
|
|
print("Init " + args.role + " player finished")
|
2017-12-10 20:23:10 +08:00
|
|
|
uri = daemon.register(player) # register the greeting maker as a Pyro object
|
2017-12-27 01:04:09 +08:00
|
|
|
print("Start on name " + args.role)
|
2017-12-26 19:29:35 +08:00
|
|
|
ns.register(args.role, uri) # register the object with a name in the name server
|
2017-12-27 01:04:09 +08:00
|
|
|
print("Start requestLoop " + str(uri))
|
2017-12-10 20:23:10 +08:00
|
|
|
daemon.requestLoop() # start the event loop of the server to wait for calls
|
|
|
|
|