Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
made wind power kwarg
  • Loading branch information
jjshoots committed Apr 13, 2022
commit 6e96aabab051ee1ef7f61d7b7b1b8ebd5302bb61
13 changes: 9 additions & 4 deletions gym/envs/box2d/lunar_lander.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
SIDE_ENGINE_POWER = 0.6

INITIAL_RANDOM = 1000.0 # Set 1500 to make game harder
WIND_POWER = 15.0

LANDER_POLY = [(-14, +17), (-17, 0), (-17, -10), (+17, -10), (+17, 0), (+14, +17)]
LEG_AWAY = 20
Expand Down Expand Up @@ -157,6 +156,7 @@ def __init__(
continuous: bool = False,
gravity: float = -10.0,
enable_wind: bool = False,
wind_power: float = 15.0,
):
EzPickle.__init__(self)

Expand All @@ -165,7 +165,13 @@ def __init__(
), f"gravity (current value: {gravity}) must be between -12 and 0"
self.gravity = gravity

assert (
0.0 < wind_power and wind_power < 20.0
), f"wind_power (current value: {wind_power}) must be between 0 and 20"
self.wind_power = wind_power

self.enable_wind = enable_wind
self.wind_power = wind_power
self.wind_idx = np.random.randint(-9999, 9999)

self.screen = None
Expand Down Expand Up @@ -356,7 +362,7 @@ def step(self, action):
math.sin(0.02 * self.wind_idx)
+ (math.sin(math.pi * 0.01 * self.wind_idx))
)
* WIND_POWER
* self.wind_power
)
self.wind_idx += 1
self.lander.ApplyForceToCenter(
Expand Down Expand Up @@ -653,8 +659,7 @@ def heuristic(env, s):
def demo_heuristic_lander(env, seed=None, render=False):

# wind power must be reduced for heuristic landing
global WIND_POWER
WIND_POWER = 1.0
env.wind_power = 1.0

total_reward = 0
steps = 0
Expand Down
4 changes: 4 additions & 0 deletions tests/envs/test_lunar_lander.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ def test_lunar_lander_continuous():
@pytest.mark.skipif(Box2D is None, reason="Box2D not installed")
def test_lunar_lander_wind():
_test_lander(LunarLander(enable_wind=True), seed=0)
_test_lander(LunarLander(enable_wind=True, wind_power=5.0), seed=0)
_test_lander(LunarLander(enable_wind=True, wind_power=0.1), seed=0)


@pytest.mark.skipif(Box2D is None, reason="Box2D not installed")
def test_lunar_lander_wind_continuous():
_test_lander(LunarLander(continuous=True, enable_wind=True), seed=0)
_test_lander(LunarLander(continuous=True, enable_wind=True, wind_power=5.0), seed=0)
_test_lander(LunarLander(continuous=True, enable_wind=True, wind_power=0.1), seed=0)


@pytest.mark.skipif(Box2D is None, reason="Box2D not installed")
Expand Down