Last active
January 3, 2023 17:20
-
-
Save WhatIThinkAbout/2d86444c3b9ec813dce28e2ede37eda0 to your computer and use it in GitHub Desktop.
Baby Robot Environment V1
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
| import numpy as np | |
| from gymnasium.spaces import Discrete,MultiDiscrete | |
| class BabyRobotEnv_v1(gym.Env): | |
| def __init__(self, **kwargs): | |
| super().__init__() | |
| # dimensions of the grid | |
| self.width = kwargs.get('width',3) | |
| self.height = kwargs.get('height',3) | |
| # define the maximum x and y values | |
| self.max_x = self.width - 1 | |
| self.max_y = self.height - 1 | |
| # there are 5 possible actions: move N,E,S,W or stay in same state | |
| self.action_space = Discrete(5) | |
| # the observation will be the coordinates of Baby Robot | |
| self.observation_space = MultiDiscrete([self.width, self.height]) | |
| # Baby Robot's position in the grid | |
| self.x = 0 | |
| self.y = 0 | |
| def step(self, action): | |
| obs = np.array([self.x,self.y]) | |
| reward = -1 | |
| done = True | |
| truncated = False | |
| info = {} | |
| return obs, reward, done, truncated, info | |
| def reset(self, seed=None, options=None): | |
| super().reset(seed=seed) | |
| # reset Baby Robot's position in the grid | |
| self.x = 0 | |
| self.y = 0 | |
| info = {} | |
| return np.array([self.x,self.y]),info | |
| def render(self): | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment