Exemplo n.º 1
0
def main(args, team1='left', team2='right', rng=numpy.random.RandomState()):
    """Sets up the teams, launches the server and monitor, starts the
  trainer.
  """
    if not os.path.exists(args.logDir):
        os.makedirs(args.logDir)
    num_agents = args.offenseAgents + args.defenseAgents
    binary_dir = os.path.dirname(os.path.realpath(__file__))
    server_port = args.port + num_agents
    coach_port = args.port + num_agents + 1
    olcoach_port = args.port + num_agents + 2
    serverOptions = ' server::port=%i server::coach_port=%i ' \
                    'server::olcoach_port=%i server::coach=1 ' \
                    'server::game_logging=%i server::text_logging=%i ' \
                    'server::game_log_dir=%s server::text_log_dir=%s '\
                    'server::synch_mode=%i ' \
                    'server::fullstate_l=%i server::fullstate_r=%i' \
                    %(server_port, coach_port, olcoach_port,
                      args.logging, args.logging,
                      args.logDir, args.logDir,
                      args.sync,
                      args.fullstate, args.fullstate)
    team1, team1Cmd = getAgentDirCmd(binary_dir, team1, server_port,
                                     coach_port, args.logDir, args.record)
    team2, team2Cmd = getAgentDirCmd(binary_dir, team2, server_port,
                                     coach_port, args.logDir, args.record)
    try:
        # Launch the Server
        server = launch(SERVER_CMD + serverOptions, name='server')
        time.sleep(0.2)
        assert server.poll() is None,\
          '[start.py] Failed to launch Server with command: \"%s\"' \
          %(SERVER_CMD + serverOptions)
        if not args.headless:
            monitorOptions = ' --port=%i' % (server_port)
            launch(MONITOR_CMD + monitorOptions, name='monitor')
        # Launch the Trainer
        from Trainer import Trainer
        trainer = Trainer(args=args,
                          rng=rng,
                          server_port=server_port,
                          coach_port=coach_port)
        trainer.initComm()
        # Start Team1
        launch(team1Cmd, False)
        trainer.waitOnTeam(True)  # wait to make sure of team order
        # Start Team2
        launch(team2Cmd, False)
        trainer.waitOnTeam(False)
        # Make sure all players are connected
        trainer.checkIfAllPlayersConnected()
        trainer.setTeams()
        # Run HFO
        trainer.run(necProcesses)
    except KeyboardInterrupt:
        print '[start.py] Exiting for CTRL-C'
    finally:
        print '[start.py] Cleaning up server and other processes'
        for p in processes:
            try:
                p.send_signal(SIGKILL)
            except:
                pass
            time.sleep(0.1)
Exemplo n.º 2
0
def main(args, team1='left', team2='right', rng=numpy.random.RandomState()):
  """Sets up the teams, launches the server and monitor, starts the
  trainer.
  """
  if not os.path.exists(args.logDir):
    os.makedirs(args.logDir)
  num_agents   = args.offenseAgents + args.defenseAgents
  binary_dir   = os.path.dirname(os.path.realpath(__file__))
  server_port  = args.port + num_agents
  coach_port   = args.port + num_agents + 1
  olcoach_port = args.port + num_agents + 2
  serverOptions = ' server::port=%i server::coach_port=%i ' \
                  'server::olcoach_port=%i server::coach=1 ' \
                  'server::game_logging=%i server::text_logging=%i ' \
                  'server::game_log_dir=%s server::text_log_dir=%s '\
                  'server::synch_mode=%i ' \
                  'server::fullstate_l=%i server::fullstate_r=%i' \
                  %(server_port, coach_port, olcoach_port,
                    args.logging, args.logging,
                    args.logDir, args.logDir,
                    args.sync,
                    args.fullstate, args.fullstate)
  team1, team1Cmd = getAgentDirCmd(binary_dir, team1, server_port, coach_port,
                                   args.logDir, args.record)
  team2, team2Cmd = getAgentDirCmd(binary_dir, team2, server_port, coach_port,
                                   args.logDir, args.record)
  try:
    # Launch the Server
    server = launch(SERVER_CMD + serverOptions, name='server')
    time.sleep(0.2)
    assert server.poll() is None,\
      '[start.py] Failed to launch Server with command: \"%s\"' \
      %(SERVER_CMD + serverOptions)
    if not args.headless:
      monitorOptions = ' --port=%i'%(server_port)
      launch(MONITOR_CMD + monitorOptions, name='monitor')
    # Launch the Trainer
    from Trainer import Trainer
    trainer = Trainer(args=args, rng=rng, server_port=server_port,
                      coach_port=coach_port)
    trainer.initComm()
    # Start Team1
    launch(team1Cmd,False)
    trainer.waitOnTeam(True) # wait to make sure of team order
    # Start Team2
    launch(team2Cmd,False)
    trainer.waitOnTeam(False)
    # Make sure all players are connected
    trainer.checkIfAllPlayersConnected()
    trainer.setTeams()
    # Run HFO
    trainer.run(necProcesses)
  except KeyboardInterrupt:
    print '[start.py] Exiting for CTRL-C'
  finally:
    print '[start.py] Cleaning up server and other processes'
    for p in processes:
      try:
        p.send_signal(SIGKILL)
      except:
        pass
      time.sleep(0.1)