This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# register the local custom environment class | |
from gymnasium.envs.registration import register | |
register( id='BabyRobotEnv-v4', entry_point=BabyRobotEnv_v4 ) | |
# make the environment | |
env = gym.make("BabyRobotEnv-v4") | |
# check the environment conforms to the API standard | |
check_env(env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create an instance of our custom environment | |
env = BabyRobotEnv_v1() | |
# use the Gymnasium 'check_env' function to check the environment | |
# - returns nothing if the environment is verified as ok | |
from gymnasium.utils.env_checker import check_env | |
check_env(env) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setup = { 'width': 8, | |
'height': 5, | |
'add_maze': True, | |
'maze_seed': 42, | |
'end': [5,4] | |
} | |
walls = [((2, 0),'E'), # remove the east wall at (2,0) | |
((2, 2),'E'), # remove the east wall at (2,2) | |
((3, 2),'E'), # remove the east wall at (3,2) | |
((5, 2),'E')] # add an east wall at (5,2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for step in range(2): | |
action = Actions.East | |
new_state, reward, terminated, truncated, info = env.step(action) | |
info_str = f"{Actions(action): <5}: {new_state} reward = {reward}" | |
target_str = f"Target Reached = {info['target_reached']}" | |
env.render(info = {'side_info': [((10,100),info_str),((10,130),target_str)]}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setup = { 'start':[0,1], 'end': [2,1] , 'add_compass':True } | |
setup['side_panel'] = {'width':200,'color':'#ddd'} | |
setup['walls'] = [((0, 1),'N'),((0, 1),'S')] | |
setup['puddles'] = [((1,1),2)] | |
env = BabyRobotEnv_v6(**setup) | |
env.render() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BabyRobotEnv_v6( BabyRobotEnv_v5 ): | |
def __init__(self, **kwargs): | |
super().__init__(**kwargs) | |
def take_action(self, action): | |
''' apply the supplied action | |
returns: - the reward obtained for taking the action | |
- flag indicating if the target state was reached | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setup = {'add_compass':True} | |
walls = [((0, 0),'E'), | |
((2, 2),'W')] | |
setup['walls'] = walls | |
env = BabyRobotEnv_v5(**setup) | |
env.render() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env = BabyRobotEnv_v5(**{'side_panel':{'width':200,'color':'#ddd'}}) | |
env.render() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run the environment, taking random actions | |
env.reset() | |
info = {} | |
terminated = False | |
while not terminated: | |
# choose a random action | |
action = env.action_space.sample() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BabyRobotEnv_v5( BabyRobotEnv_v4 ): | |
def __init__(self, **kwargs): | |
super().__init__(**kwargs) | |
def render(self, info=None): | |
''' render as an HTML5 canvas ''' | |
# move baby robot to the current position | |
self.robot.move(self.x,self.y) | |
# write the info to the grid side-panel |
NewerOlder