Ejemplo n.º 1
0
    num_episodes = (num_train_ep + num_test_ep) * num_repetitions
    # Directory
    save_dir = args.save_dir or mkdir()

    print("Starting Training - id={}; num_opponents={}; num_teammates={}; "
          "num_episodes={};".format(agent_id, num_op, num_team, num_episodes))
    # Initialize connection with the HFO server
    hfo_interface = HFOAttackingPlayer(agent_id=agent_id,
                                       num_opponents=num_op,
                                       num_teammates=num_team)
    hfo_interface.connect_to_server()

    # Agent set-up
    reward_function = basic_reward
    features_manager = DiscreteFeatures(num_team, num_op)
    actions_manager = DiscreteActionsV5()
    agent = QLearningAgentTest(num_states=features_manager.get_num_states(),
                               num_actions=actions_manager.get_num_actions(),
                               learning_rate=0.1,
                               discount_factor=0.9,
                               epsilon=0.8)
    # Save metrics structures
    avr_rewards_list = []
    avr_epsilons_list = []
    trained_eps_list = []
    q_tables_list = []
    # Test one first time without previous train:
    av_reward = test(num_episodes=num_test_ep,
                     agent=agent,
                     game_interface=hfo_interface,
                     features=features_manager,
Ejemplo n.º 2
0
    save_dir = args.save_dir

    print("Q Table file: ", load_file)
    print("Starting Test - num_opponents={}; num_teammates={}; "
          "num_episodes={};".format(num_op, num_team, num_episodes))
    # Initialize connection with the HFO server
    hfo_interface = HFOAttackingPlayer(agent_id=agent_id,
                                       num_opponents=num_op,
                                       num_teammates=num_team)
    hfo_interface.connect_to_server()

    # Agent set-up
    reward_function = reward_functions.basic_reward
    features_manager = discrete_features_v2.DiscreteFeaturesV2(
        num_team, num_op)
    actions_manager = DiscreteActionsV5(
        origin_pos=learning_agent.ORIGIN_POSITIONS["MID LEFT"])
    agent = learning_agent.QLearningAgentV5(
        num_states=features_manager.get_num_states(),
        num_actions=actions_manager.get_num_actions(),
        dir=save_dir)
    agent.load_q_table(load_file)

    # Run training using Q-Learning
    av_reward = learning_agent.test(num_episodes=num_episodes,
                                    agent=agent,
                                    game_interface=hfo_interface,
                                    features=features_manager,
                                    actions=actions_manager,
                                    reward_funct=reward_function)
    print("Av reward = {}".format(av_reward))