Exemplo n.º 1
0
from gym import logger

from pong.pong_game import PongGame
from pong.gym_agents import RandomAgent

if __name__ == '__main__':
    # You can set the level to logger.DEBUG or logger.WARN if you
    # want to change the amount of output.
    logger.set_level(logger.INFO)

    env = PongGame()
    env.seed(0)
    agent1 = RandomAgent()
    agent2 = RandomAgent()

    episode_count = 1
    reward = 0
    done = False
    print(env.action_space.n)

    for i in range(episode_count):
        ob = env.reset()
        while True:
            action1 = agent1.act(ob, player=0)
            action2 = agent2.act(ob, player=1)
            ob, reward = env.step(action1, a2=action2)
            if done:
                break
            env.render()

    # Close the env and write monitor result info to disk
Exemplo n.º 2
0
from pong.gym_agents import *
from pong.monitor import PongMonitor

possible_opponents = {
    1: RandomAgent,
    2: GreedyAgent,
    3: AggressiveAgent,
    4: LazyAgent
}

print("Welcome in Pong")
selected_opponent, = input(
    "Select opponent for MCTS (1 - Random, 2 - Safe, 3 - Aggressive, 4 - Lazy): "
).split()

game = PongGame()
game = PongMonitor(game, ".", force=True)
game.reset()

opponent = possible_opponents[int(selected_opponent)]()
mcts_agent = GreedyAgent()

tree = Mcts(game, simulation_agent=mcts_agent)
# tree = Mcts(game)

count = 0

while not game.done:
    count = count + 1
    start = time()
    tree.run(30, verbose=True)