def testAugmented(): from core import VGDLParser from pybrain.rl.experiments.episodic import EpisodicExperiment from mdpmap import MDPconverter from agents import PolicyDrivenAgent zelda_level2 = """ wwwwwwwwwwwww wA wwk1ww w ww ww 1 w ww wwww+w wwwww1ww www wwwww 0 Gww wwwwwwwwwwwww """ from examples.gridphysics.mazes.rigidzelda import rigidzelda_game g = VGDLParser().parseGame(rigidzelda_game) g.buildLevel(zelda_level2) env = GameEnvironment(g, visualize=False, recordingEnabled=True, actionDelay=150) C = MDPconverter(g, env=env, verbose=True) Ts, R, _ = C.convert() print C.states print Ts[0] print R env.reset() agent = PolicyDrivenAgent.buildOptimal(env) env.visualize = True env.reset() task = GameTask(env) exper = EpisodicExperiment(task, agent) exper.doEpisodes(1)
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 testPolicyAgent(): 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 game_str, map_str = polarmaze_game, maze_level_2 g = VGDLParser().parseGame(game_str) g.buildLevel(map_str) env = GameEnvironment(g, visualize=False, actionDelay=100) task = GameTask(env) agent = PolicyDrivenAgent.buildOptimal(env) env.visualize = True env.reset() exper = EpisodicExperiment(task, agent) res = exper.doEpisodes(2) print res