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 Dynamic(gym.Space): | |
| def __init__(self, action_list = []): | |
| ' set the list of initially available actions ' | |
| self.set_actions(action_list) | |
| def sample(self): | |
| ' select a random action from the set of available actions ' | |
| return np.random.choice(self.available_actions) | |
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
| from babyrobot.envs.lib import Direction | |
| class BabyRobotEnv_v4( BabyRobotEnv_v3 ): | |
| def __init__(self, **kwargs): | |
| super().__init__(**kwargs) | |
| # initially no actions are available | |
| self.dynamic_action_space = Dynamic() |
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
| # initialize the environment | |
| env.reset() | |
| terminated = False | |
| while not terminated: | |
| # choose a random action | |
| action = env.action_space.sample() | |
| # take the action and get the information from the environment |
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
| ''' the first graphical environment ''' | |
| class BabyRobotEnv_v3( BabyRobotEnv_v2 ): | |
| def __init__(self, **kwargs): | |
| super().__init__(**kwargs) | |
| # graphical creation of the level | |
| self.level = GridLevel( **kwargs ) | |
| # add baby robot |
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
| from babyrobot.envs.lib import GridLevel | |
| from babyrobot.envs.lib import RobotDraw | |
| # draw the default grid level | |
| level = GridLevel() | |
| # add Baby Robot | |
| robot = RobotDraw(level) | |
| robot.set_cell_position([1,1]) | |
| robot.draw() |
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
| from ipycanvas import MultiCanvas | |
| layers = 2 | |
| multi_canvas = MultiCanvas(layers, width=width_pixels, height=height_pixels) | |
| draw_base(multi_canvas[0]) | |
| draw_grid(multi_canvas[0]) | |
| draw_border(multi_canvas[0]) |
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
| def draw_border(canvas): | |
| canvas.stroke_style = 'black' | |
| canvas.line_width = 5 | |
| canvas.set_line_dash([0,0]) | |
| canvas.stroke_rect(0,0,width_pixels,height_pixels) |
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
| def draw_grid( canvas ): | |
| canvas.stroke_style = '#777' # grid line color - medium gray | |
| canvas.line_width = 1 | |
| canvas.set_line_dash([4,8]) | |
| # draw the grid onto the canvas | |
| for y in range(grid_height): | |
| for x in range(grid_width): | |
| canvas.stroke_rect(cell_pixels * x, cell_pixels * y, cell_pixels, cell_pixels) |
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
| def draw_base(canvas): | |
| canvas.fill_style = 'orange' | |
| canvas.fill_rect(0, 0, canvas.width, canvas.height) | |
| draw_base(canvas) | |
| canvas |
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 the environment | |
| env = gym.make('BabyRobotEnv-v2') | |
| # initialize the environment | |
| env.reset() | |
| env.render() | |
| terminated = False | |
| while not terminated: |