def testRecordingToGif(human=False): from pybrain.rl.experiments.episodic import EpisodicExperiment from core import VGDLParser from examples.gridphysics.mazes import polarmaze_game, maze_level_2 from agents import PolicyDrivenAgent, InteractiveAgent from tools import makeGifVideo game_str, map_str = polarmaze_game, maze_level_2 g = VGDLParser().parseGame(game_str) g.buildLevel(map_str) env = GameEnvironment(g, visualize=human, recordingEnabled=True, actionDelay=200) task = GameTask(env) if human: agent = InteractiveAgent() else: agent = PolicyDrivenAgent.buildOptimal(env) exper = EpisodicExperiment(task, agent) res = exper.doEpisodes(1) print res actions = [a for _, a, _ in env._allEvents] print actions makeGifVideo(env, actions, initstate=env._initstate)
def testRolloutVideo(actions=[0, 0, 2, 2, 0, 3] * 2): from examples.gridphysics.mazes import polarmaze_game, maze_level_1 from core import VGDLParser from tools import makeGifVideo game_str, map_str = polarmaze_game, maze_level_1 g = VGDLParser().parseGame(game_str) g.buildLevel(map_str) makeGifVideo(GameEnvironment(g, visualize=True), actions)