The last class to be implemented is the Environment class. Actually, the environment is provided by the gym command, though you need a good wrapper around it in order to have it work with the previous agent class. That's exactly what this class does. At initialization, it starts the Lunar Lander game and sets key variables such as nS, nA (dimensions of state and action), agent, and the cumulative reward (useful for testing the solution by providing an average of the last 100 episodes):
class Environment: def __init__(self, game="LunarLander-v2"): # Initializing np.set_printoptions(precision=2) self.env = gym.make(game) self.env = wrappers.Monitor(self.env, tempfile.mkdtemp(), force=True, video_callable=False)