Skip to content
Snippets Groups Projects
Commit dc792356 authored by tuhe's avatar tuhe
Browse files

Examples for week 2

parent b7cbf41a
No related branches found
No related tags found
No related merge requests found
**/__pycache__/*
solutions/exam
solutions
exam_tabular_examples
solutions/ex01
solutions/ex02
#solutions/ex01
#solutions/ex02
solutions/ex03
solutions/ex04
solutions/ex05
......@@ -52,8 +50,8 @@ irlc/project0/fruit*_complete*.py
# irlc/exam/exam2024spring/*.zip
# irlc/exam/exam2024spring/*.pdf
irlc/exam/exam202*/*.zip
irlc/exam/exam202*/*.pdf
#irlc/exam/exam202*/*.zip
#irlc/exam/exam202*/*.pdf
irlc/exam/exam2024august/*.zip
irlc/exam/exam2024august/*.pdf
......@@ -61,13 +59,13 @@ irlc/exam/exam2024august/*.pdf
irlc/exam/exam2025*/*.zip
irlc/exam/exam2025*/*.pdf
irlc/exam/exam2*/solution
irlc/exam/exam20*/solution
# irlc/exam/midterm2023a
# irlc/exam/midterm2023b
# irlc/lectures/lec01
irlc/lectures/lec02
# irlc/lectures/lec02
irlc/lectures/lec03
irlc/lectures/lec04
irlc/lectures/lec05
......@@ -81,4 +79,5 @@ irlc/lectures/lec12
irlc/lectures/lec13
# Always ignored.
**/__pycache__/*
# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text.
# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text.
from irlc.lectures.chapter1.dp_planning_agent import dp_visualization
from irlc.gridworld.gridworld_environments import FrozenLake
if __name__ == "__main__":
env = FrozenLake(render_mode='human')
dp_visualization(env, N=4, num_episodes=10)
env.close()
# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text.
from irlc.gridworld.gridworld_environments import FrozenLake
from gymnasium.wrappers import TimeLimit
from irlc import Agent, interactive, train
if __name__ == "__main__":
env = FrozenLake(is_slippery=True, living_reward=-1e-4, render_mode="human")
N = 40
env, agent = interactive(env, Agent(env))
env = TimeLimit(env, max_episode_steps=N)
num_episodes = 100
train(env, agent, num_episodes=num_episodes)
env.close()
# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text.
from irlc.lectures.chapter1.dp_planning_agent import dp_visualization
from irlc.gridworld.gridworld_environments import FrozenLake
if __name__ == "__main__":
env = FrozenLake(is_slippery=True, living_reward=-1e-4, render_mode='human')
dp_visualization(env, N=40, num_episodes=100)
env.close()
# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text.
from irlc.pacman.pacman_environment import PacmanEnvironment
from irlc.ex01.agent import train
from irlc.ex01.agent import Agent
from irlc import interactive
from irlc.lectures.chapter3dp.dp_pacman import SS1tiny
def ppac(layout_str, name="pac"):
env = PacmanEnvironment(layout=None, layout_str=layout_str, animate_movement=True)
agent = Agent(env)
env, agent = interactive(env, agent)
# agent = PlayWrapper(agent, env)
# env = VideoMonitor(env)
stats, _ = train(env, agent, num_episodes=5, max_steps=8)
print("Accumulated reward for all episodes:", [s['Accumulated Reward'] for s in stats])
env.close()
if __name__ == "__main__":
ppac(SS1tiny)
# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text.
from irlc.lectures.lec02.lecture_02_keyboard_pacman_g1 import ppac
from irlc.lectures.chapter3dp.dp_pacman import SS2tiny
if __name__ == "__main__":
ppac(SS2tiny)
# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text.
from irlc.pacman.pacman_environment import PacmanEnvironment
from irlc.ex02.dp_agent import DynamicalProgrammingAgent
from gymnasium.wrappers import TimeLimit
from irlc.pacman.pacman_environment import PacmanWinWrapper
from irlc.ex01.agent import train
# from irlc import VideoMonitor
# from irlc.ex02.old.dp_pacman import DPPacmanModel
from irlc.lectures.chapter3dp.dp_pacman import DPPacmanModel
# from irlc import PlayWrapper
from irlc import interactive
def simulate_1_game(layout_str):
N = 30
env = PacmanEnvironment(layout=None, layout_str=layout_str, render_mode='human')
# env = VideoMonitor(env, fps=3)
model = DPPacmanModel(env, N=N, verbose=True)
agent = DynamicalProgrammingAgent(env, model=model)
# agent = PlayWrapper(agent, env)
env, agent = interactive(env, agent)
env = TimeLimit(env, max_episode_steps=N)
env = PacmanWinWrapper(env)
stats, trajectories = train(env, agent, num_episodes=100, verbose=False, return_trajectory=True)
env.close()
SS0 = """
%%%%%%%%%%
% P . %
% %%%%%. %
% %
% %%% %%%%
%. .%
%%%%%%%%%%
"""
if __name__ == "__main__":
simulate_1_game(layout_str=SS0)
# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text.
from irlc.lectures.chapter3dp.dp_pacman import SS1tiny
from irlc.lectures.lec02.lecture_02_optimal_dp_g0 import simulate_1_game
if __name__ == "__main__":
simulate_1_game(layout_str=SS1tiny)
# This file may not be shared/redistributed without permission. Please read copyright notice in the git repo. If this file contains other copyright notices disregard this text.
from irlc.lectures.chapter3dp.dp_pacman import SS2tiny
from irlc.lectures.lec02.lecture_02_optimal_dp_g1 import simulate_1_game
if __name__ == "__main__":
simulate_1_game(layout_str=SS2tiny)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment