Lunar Lander#

../../../_images/lunar_lander.gif

This environment is part of the Box2D environments. Please read that page first for general information.

Action Space

Discrete(4)

Observation Shape

(8,)

Observation High

[inf inf inf inf inf inf inf inf]

Observation Low

[-inf -inf -inf -inf -inf -inf -inf -inf]

Import

gym.make("LunarLander-v2")

Description#

This environment is a classic rocket trajectory optimization problem. According to Pontryagin’s maximum principle, it is optimal to fire the engine at full throttle or turn it off. This is the reason why this environment has discrete actions: engine on or off.

There are two environment versions: discrete or continuous. The landing pad is always at coordinates (0,0). The coordinates are the first two numbers in the state vector. Landing outside of the landing pad is possible. Fuel is infinite, so an agent can learn to fly and then land on its first attempt.

To see a heuristic landing, run:

python gym/envs/box2d/lunar_lander.py

Action Space#

There are four discrete actions available: do nothing, fire left orientation engine, fire main engine, fire right orientation engine.

Observation Space#

There are 8 states: the coordinates of the lander in x & y, its linear velocities in x & y, its angle, its angular velocity, and two booleans that represent whether each leg is in contact with the ground or not.

Rewards#

Reward for moving from the top of the screen to the landing pad and coming to rest is about 100-140 points. If the lander moves away from the landing pad, it loses reward. If the lander crashes, it receives an additional -100 points. If it comes to rest, it receives an additional +100 points. Each leg with ground contact is +10 points. Firing the main engine is -0.3 points each frame. Firing the side engine is -0.03 points each frame. Solved is 200 points.

Starting State#

The lander starts at the top center of the viewport with a random initial force applied to its center of mass.

Episode Termination#

The episode finishes if:

  1. the lander crashes (the lander body gets in contact with the moon);

  2. the lander gets outside of the viewport (x coordinate is greater than 1);

  3. the lander is not awake. From the Box2D docs, a body which is not awake is a body which doesn’t move and doesn’t collide with any other body:

When Box2D determines that a body (or group of bodies) has come to rest, the body enters a sleep state which has very little CPU overhead. If a body is awake and collides with a sleeping body, then the sleeping body wakes up. Bodies will also wake up if a joint or contact attached to them is destroyed.

Arguments#

To use to the continuous environment, you need to specify the continuous=True argument like below:

import gym
env = gym.make("LunarLander-v2", continuous=True)

Version History#

  • v2: Count energy spent

  • v1: Legs contact with ground added in state vector; contact with ground give +10 reward points, and -10 if then lose contact; reward renormalized to 200; harder initial random push.

  • v0: Initial version

Credits#

Created by Oleg Klimov