Let's develop the Windy Gridworld environment:
- Import the necessary modules, NumPy, and the discrete class, from Gym:
>>> import numpy as np>>> import sys>>> from gym.envs.toy_text import discrete
- Define four actions:
>>> UP = 0>>> RIGHT = 1>>> DOWN = 2>>> LEFT = 3
- Let's start by defining the __init__ method in the WindyGridworldEnv class:
>>> class WindyGridworldEnv(discrete.DiscreteEnv): ... def __init__(self): ... self.shape = (7, 10) ... nS = self.shape[0] * self.shape[1] ... nA = 4 ... # Wind locations ... winds = np.zeros(self.shape) ... winds[:,[3,4,5,8]] = 1 ... winds[:,[6,7]] = 2 ... self.goal = (3, 7) ... # Calculate transition probabilities and rewards ... P = {} ... for s in range(nS): ... position = np.unravel_index(s, ...