Beispiel #1
0
def main():
    '''Simple function to bootstrap a game.

       Use this as an example to set up your training env.
    '''
    # Print all possible environments in the Pommerman registry
    print(pommerman.REGISTRY)

    # Create a set of agents (exactly four)
    agent_list = [
        # RandAgent(),
        # SuicideAgent(),
        agents.PlayerAgent(agent_control="wasd"
                           ),  # W,A,S,D to move, E to lay bomb
        StopAgent(),
        StopAgent(),
        # StopAgent(),
        # agents.SimpleAgent(),
        # agents.SimpleAgent(),
        # agents.SimpleAgent(),
        # agents.SimpleAgent(),
        agents.PlayerAgent(agent_control="arrows"
                           ),  # arrows to move, space to lay bomb
        # SuicideAgent(),
        # SuicideAgent(),
        # SuicideAgent(),
        # agents.DockerAgent("pommerman/simple-agent", port=12345),
    ]
    # Make the "Free-For-All" environment using the agent list
    env = pommerman.make('PommeRadioCompetition-v2', agent_list)

    # Run the episodes just like OpenAI Gym
    for i_episode in range(100):
        print('Start to reset')
        state = env.reset()
        print('Reset complete')
        done = False
        while not done:
            actions = env.act(state)
            # print(actions[0])
            # actions[0] = [actions[0], 1, 1]
            state, reward, done, info = env.step(actions)
            bomb_life = state[0]['bomb_life']
            bomb_strenth = state[0]['bomb_blast_strength']
            bomb_life = feature_utils.get_bomb_life(state[0])
            # obs = featurize(state[0], env.position_trav)
            env.render()
            # print(reward)
            # print()
        print(info)
        print('Episode {} finished'.format(i_episode))
    env.close()
Beispiel #2
0
def main():
    '''Simple function to bootstrap a game.
       
       Use this as an example to set up your training env.
    '''
    # Print all possible environments in the Pommerman registry
    print(pommerman.REGISTRY)

    # Create a set of agents (exactly four)
    agent_list = [
        agents.SimpleAgent(),
        agents.SimpleAgent(),
        agents.SimpleAgent(),
        agents.PlayerAgent(agent_control="arrows"),
        # agents.DockerAgent("pommerman/simple-agent", port=12345),
    ]
    # Make the "Free-For-All" environment using the agent list
    env = pommerman.make('PommeFFACompetition-v0', agent_list)

    # Run the episodes just like OpenAI Gym
    for i_episode in range(1):
        state = env.reset()
        done = False
        while not done:
            env.render()
            actions = env.act(state)
            state, reward, done, info = env.step(actions)
        print('Episode {} finished'.format(i_episode))
    env.close()
def main():
    '''Simple function to bootstrap a game.
       
       Use this as an example to set up your training env.
    '''
    # Print all possible environments in the Pommerman registry
    print(pommerman.REGISTRY)

    # Create a set of agents (exactly four)
    agent_list = [
        #agents.SimpleAgent(),
        agents.PlayerAgent(
        ),  #note player agent can act as a stand-in for a static agent
        agents.RandomAgent(),
        #agents.DockerAgent("multiagentlearning/hakozakijunctions", port=12345),
        #agents.DockerAgent("multiagentlearning/eisenach", port=12345),
        #agents.DockerAgent("multiagentlearning/skynet955", port=12345),
    ]
    # Make the "Free-For-All" environment using the agent list
    env = pommerman.make('Simple-v0', agent_list)

    # Run the episodes just like OpenAI Gym
    for i_episode in range(1):
        state = env.reset()
        done = False
        while not done:
            env.render()  #comment out to disable slow rendering
            actions = env.act(state)
            state, reward, done, info = env.step(actions)
        print('Episode {} finished'.format(i_episode))
        print("Final Result: ", info)
    env.close()
def main():
    print(pommerman.REGISTRY)

    # Create a set of agents (exactly four)
    agent_list = [
        agents.PlayerAgent(agent_control="arrows"),
        agents.SimpleAgent(),
        agents.SimpleAgent(),
        agents.SimpleAgent()
    ]

    # Play with AI with agent list bellow
    # agent_list = [
    # agents.SimpleAgent(),
    # agents.PlayerAgent(agent_control="arrows"), # Arrows = Move, Space = Bomb
    # agents.SimpleAgent(),
    # agents.PlayerAgent(agent_control="wasd"), # W,A,S,D = Move, E = Bomb
    # ]

    # Make the "Free-For-All" environment using the agent list
    env = pommerman.make('PommeFFACompetition-v0', agent_list)

    # Run the episodes just like OpenAI Gym
    for i_episode in range(3):
        state = env.reset()
        done = False
        while not done:
            env.render()
            actions = env.act(state)
            state, reward, done, info = env.step(actions)
        print('Episode {} finished'.format(i_episode))
    env.close()
Beispiel #5
0
def main(unused_args):
    '''Simple function to bootstrap a game.
       
       Use this as an example to set up your training env.
    '''
    # Print all possible environments in the Pommerman registry
    print(pommerman.REGISTRY)

    # Create a set of agents (exactly four)
    agent_list = [
        agents.PlayerAgent(agent_control="arrows"),
        # custom_agents.ActorCriticAgent(name='smith', update_turn=0, savepath='saved_models', load=FLAGS.load, load_replay=False),
        # custom_agents.ActorCriticAgent(name='smith', update_turn=1, savepath='saved_models', load=FLAGS.load),
        # custom_agents.ActorCriticAgent(name='smith', update_turn=2, savepath='saved_models', load=FLAGS.load),
        # custom_agents.ActorCriticAgent(name='smith', update_turn=3, savepath='saved_models', load=FLAGS.load),
        # custom_agents.ActorCriticAgent(name='john', savepath='saved_models', load=FLAGS.load),
        # custom_agents.ActorCriticAgent(name='romanov', savepath='saved_models', load=FLAGS.load),
        # custom_agents.ActorCriticAgent(name='witch', savepath='saved_models', load=FLAGS.load),
        custom_agents.StaticAgent(),
        custom_agents.StaticAgent(),
        custom_agents.StaticAgent(),
        # custom_agents.DebugAgent(),
        # agents.SimpleAgent(),
        # agents.SimpleAgent(),
        # agents.SimpleAgent(),
        # agents.RandomAgent(),
        # agents.DockerAgent("pommerman/simple-agent", port=12345),
    ]
    # Make the "Free-For-All" environment using the agent list
    env = pommerman.make('PommeFFACompetition-v0', agent_list)
    # env = pommerman.make('PommeTeamCompetition-v0', agent_list)

    # Run the episodes just like OpenAI Gym
    for i_episode in range(int(1e6)):
        state = env.reset()
        done = False
        while not done:
            if FLAGS.render:
                env.render()
            actions = env.act(state)
            # print(actions)
            # quit()
            state, reward, done, info = env.step(actions)
            # if len(state[0]['alive']) < 4:
            #     reward = agent_list[0].episode_end(-1)
            #     break
            # input()
        # reward = agent_list[0].prev_sub_reward
        # avg_reward = agent_list[0].avg_sub_reward
        # if i_episode % 5 == 0:
        #     print('Episode {} finished - Reward: {:.3f} - Avg: {:.3f}'.format(i_episode, reward, avg_reward))
        # print(info)
    env.close()
def main():
    env = pommerman.make('PommeFFACompetition-v0', [
        agents.PlayerAgent(),
        agents.SimpleAgent(),
        agents.RandomAgent(),
        StoppingAgent(),
    ])

    for i_episode in range(1):
        state = env.reset()
        done = False
        while not done:
            env.render()
            actions = env.act(state)
            state, reward, done, info = env.step(actions)
            if done:
                win_player = info['winners'][0] + 1
                print(f'win {win_player}P')
        print(f'Episode {i_episode} finished')
    env.close()
    def start_gameplay(self, num_players=4, simulation=True):
        # Create a set of agents (exactly four)
        agent_list = [agents.SimpleAgent() for i in range(num_players)]

        if not simulation:
            agent_list[0] = agents.PlayerAgent()

        # Make the "Free-For-All" environment using the agent list
        env = pommerman.make('PommeFFACompetition-v0', agent_list)

        # Run the episodes just like OpenAI Gym
        for i_episode in range(1):
            state = env.reset()
            env.save_json('./replay')
            done = False
            while not done:
                env.render()
                actions = env.act(state)
                self.game_replay.append(actions)
                state, reward, done, info = env.step(actions)
        env.close()
        self.game_replay.append(num_players)
        self.game_over_screen.show()