env module¶
- class env.FrozenEnv¶
Bases:
env.FrozenLakeEnv
- class env.FrozenLakeEnv(desc=None, map_name='4x4', is_slippery=True, rewards=None)¶
Bases:
gym.envs.toy_text.discrete.DiscreteEnv
Winter is here. You and your friends were tossing around a frisbee at the park when you made a wild throw that left the frisbee out in the middle of the lake. The water is mostly frozen, but there are a few holes where the ice has melted. If you step into one of those holes, you’ll fall into the freezing water. At this time, there’s an international frisbee shortage, so it’s absolutely imperative that you navigate across the lake and retrieve the disc. However, the ice is slippery, so you won’t always move in the direction you intend. The surface is described using a grid like the following
SFFF FHFH FFFH HFFG
S : starting point, safe F : frozen surface, safe H : hole, fall to your doom G : goal, where the frisbee is located
The episode ends when you reach the goal or fall in a hole. You receive a reward of 1 if you reach the goal, and zero otherwise.
- metadata = {'render.modes': ['human', 'ansi']}¶
- render(mode='human')¶
Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
- Note:
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Args:
mode (str): the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
- class env.SimpleEnv(num_states=4, num_actions=2, rewards=[0, 0, 0, 1])¶
Bases:
object
- reset()¶
- step(action)¶
- env.generate_random_map(size=8, p=0.8)¶
Generates a random valid map (one that has a path from start to goal) :param size: size of each side of the grid :param p: probability that a tile is frozen