def callback(env):

    initial_global_obs = env.render(observer='global', mode="rgb_array")
    observation_shape = initial_global_obs.shape

    recorder = VideoRecorder()
    recorder.start("human_player_video_test.mp4", observation_shape)

    def _callback(prev_obs, obs, action, rew, env_done, info):

        global_obs = env.render(observer='global', mode="rgb_array")
        recorder.add_frame(global_obs)
        if rew != 0:
            print(f'Reward: {rew}')
        if env_done:
            print(f'Done!')

        if len(info) > 0:
            print(info)

    return _callback
Example #2
0
def callback(env):
    render_window = RenderWindow(2208, 1168)

    global_obs = env.render(observer='global', mode="rgb_array").swapaxes(0, 2)
    observation_shape = global_obs.shape
    recorder = VideoRecorder()
    recorder.start("human_player_video_test.mp4", observation_shape)

    def _callback(prev_obs, obs, action, rew, env_done, info):

        global_obs = env.render(observer='global', mode="rgb_array")
        recorder.add_frame(global_obs.swapaxes(0, 2))
        render_window.render(global_obs.swapaxes(0, 2))
        if rew != 0:
            print(f'Reward: {rew}')
        if env_done:
            print(f'Done!')
            #recorder.close()

        if len(info) > 0:
            print(info)

    return _callback
Example #3
0
        'Single-Player/Mini-Grid/minigrid-spiders.yaml',
        player_observer_type=gd.ObserverType.SPRITE_2D,
        global_observer_type=gd.ObserverType.SPRITE_2D,
        level=4)

    env = gym.make(f'GDY-{name}-v0')

    env.reset()

    start = timer()

    frames = 0

    fps_samples = []

    player_recorder = VideoRecorder()
    player_visualization = env.render(mode='rgb_array')
    player_recorder.start("player_video_test.mp4", player_visualization.shape)

    global_recorder = VideoRecorder()
    global_visualization = env.render(observer='global', mode='rgb_array')
    global_recorder.start("global_video_test.mp4", global_visualization.shape)

    for s in range(1000):

        frames += 1
        obs, reward, done, info = env.step(env.action_space.sample())

        env.render()

        player_observation = env.render(mode='rgb_array')
Example #4
0
    start = timer()

    frames = 0

    fps_samples = []

    game.reset()

    grid_height = grid.get_height()
    grid_width = grid.get_width()

    player1_initial_observation = np.array(player1.observe(), copy=False)
    player2_initial_observation = np.array(player2.observe(), copy=False)
    global_initial_observation = np.array(game.observe(), copy=False)

    player1_recorder = VideoRecorder()
    player1_recorder.start("player1_raw_video_test.mp4",
                           player1_initial_observation.shape)

    player2_recorder = VideoRecorder()
    player2_recorder.start("player2_raw_video_test.mp4",
                           player2_initial_observation.shape)

    global_recorder = VideoRecorder()
    global_recorder.start("global_raw_video_test.mp4",
                          global_initial_observation.shape)

    player1_recorder.add_frame(player1_initial_observation)
    player2_recorder.add_frame(player2_initial_observation)
    global_recorder.add_frame(global_initial_observation)
                                level=2)

    env_original = gym.make(f'GDY-GriddlyRTS-Adv-v0')
    # env_original = gym.make(f'GDY-GriddlyRTS-Adv-v0')

    env_original.reset()

    env = InvalidMaskingRTSWrapper(env_original)

    start = timer()

    frames = 0

    fps_samples = []

    player1_recorder = VideoRecorder()
    player1_visualization = env.render(observer=0, mode='rgb_array')
    player1_recorder.start("player1_video_test.mp4", player1_visualization.shape)

    player2_recorder = VideoRecorder()
    player2_visualization = env.render(observer=1, mode='rgb_array')
    player2_recorder.start("player2_video_test.mp4", player2_visualization.shape)

    global_recorder = VideoRecorder()
    global_visualization = env.render(observer='global', mode='rgb_array')
    global_recorder.start("global_video_test.mp4", global_visualization.shape)

    for s in range(10000):

        frames += 1
Example #6
0
        level=4)

    env = gym.make(f'GDY-{name}-v0')

    env.reset()

    start = timer()

    frames = 0

    fps_samples = []

    player_observation_shape = env.unwrapped.player_observation_shape
    global_observation_shape = env.unwrapped.global_observation_shape

    player_recorder = VideoRecorder()
    player_recorder.start("player_video_test.mp4", player_observation_shape)

    global_recorder = VideoRecorder()
    global_recorder.start("global_video_test.mp4", global_observation_shape)

    for s in range(1000):

        frames += 1
        obs, reward, done, info = env.step(env.action_space.sample())

        #env.render()

        #player_observation = env.render(mode='rgb_array')
        global_observation = env.render(observer='global', mode='rgb_array')
Example #7
0
                                level=0)

    env = gym.make(f'GDY-{name}-v0')

    env.reset()

    start = timer()

    frames = 0

    fps_samples = []

    player_observation_shape = env.unwrapped.player_observation_shape
    global_observation_shape = env.unwrapped.global_observation_shape

    player_recorder = VideoRecorder()
    player_recorder.start("player_video_test.mp4", player_observation_shape)

    global_recorder = VideoRecorder()
    global_recorder.start("global_video_test.mp4", global_observation_shape)

    for s in range(1000):

        frames += 1
        obs, reward, done, info = env.step(env.action_space.sample())
        player_observation = env.render()
        global_observation = env.render(observer='global')

        player_recorder.add_frame(player_observation.swapaxes(0, 2))
        global_recorder.add_frame(global_observation.swapaxes(0, 2))
Example #8
0
                                player_observer_type=gd.ObserverType.ISOMETRIC,
                                level=1)

    env = gym.make(f'GDY-GriddlyRTS-Adv-v0')

    env.reset()

    start = timer()

    frames = 0

    fps_samples = []

    observation_shape = env.observation_space.shape

    player1_recorder = VideoRecorder()
    player1_recorder.start("player1_video_test.mp4", observation_shape)

    player2_recorder = VideoRecorder()
    player2_recorder.start("player2_video_test.mp4", observation_shape)

    global_recorder = VideoRecorder()
    global_recorder.start("global_video_test.mp4", observation_shape)

    for s in range(1000):

        frames += 1

        action = env.action_space.sample()

        player_id = action['player']
import numpy as np

from griddly import GriddlyLoader, gd
from griddly.RenderTools import RenderToFile, RenderWindow, VideoRecorder

if __name__ == '__main__':
    # A nice tool to save png images
    file_renderer = RenderToFile()

    # Another nice tool for rendering the game state
    player_1_render_window = RenderWindow(500, 500)
    player_2_render_window = RenderWindow(500, 500)
    global_render_window = RenderWindow(500, 500)

    # ANOTHER nice tool for creating videos of the games (requires opencv-python)
    global_video_recorder = VideoRecorder()
    player_1_video_recorder = VideoRecorder()
    player_2_video_recorder = VideoRecorder()

    # The entry point for all raw interfaces
    loader = GriddlyLoader()

    # Load the game description
    grid = loader.load_game('RTS/basicRTS.yaml')

    # Load a custom string
    level_string = """  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  W  .  .  .  .  .  M  M  M 
                        .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  W  .  .  .  .  .  .  M  M 
                        .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  W  .  .  .  .  .  .  .  M 
                        .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  W  .  .  .  .  .  .  .  . 
                        .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  W  .  .  .  .  .  .  .  .