Table of Contents

Class BipedalWalkerHeuristics

Namespace
Gym.Environments.Envs.Box2D
Assembly
Gym.Environments.dll

Gymnasium's BipedalWalkerHeuristics: the hand-written gait that walks BipedalWalkerEnv, a state machine over three phases (stand on one leg while the other swings up, put the other leg down, push off) that alternates the legs and steers each joint toward a target angle with a proportional-derivative term, plus a hull tilt correction and vertical damping. It walks the normal terrain slowly and falls in the hardcore one.

public sealed class BipedalWalkerHeuristics
Inheritance
BipedalWalkerHeuristics
Inherited Members
Extension Methods

Remarks

Stateful: one instance per episode, fed every observation in order (StepHeuristic(NDArray)). The arithmetic is NumPy 2's on a float32 observation (NEP 50): every product and difference with the observation is float32, the comparisons with Python's constants are float32 comparisons, and SupportingKneeAngle is a Python float or, after a push-off took it from the observation, an np.float32, which changes the precision of its next increments. Gym.NET tracks that kind, so its actions are Gymnasium's bit for bit.

One difference of aliasing, not of values: Python's step_heuristic returns its own attribute array, which its next call overwrites in place before replacing it, so a caller keeping an old action sees it change. Gym.NET returns a new array each call and keeps its own copy in A.

Not thread-safe (it is a mutable state machine). Reference: gymnasium/envs/box2d/bipedal_walker.py.

Fields

PushOff

Gymnasium's PUSH_OFF: the supporting knee bends to push the hull forward; then the legs swap roles.

public const int PushOff = 3

Field Value

int

PutOtherDown

Gymnasium's PUT_OTHER_DOWN: the moving leg reaches down until its foot touches the ground.

public const int PutOtherDown = 2

Field Value

int

Speed

Gymnasium's SPEED: the horizontal speed (observation units) above which the walker would fall forward.

public const double Speed = 0.29

Field Value

double

StayOnOneLeg

Gymnasium's STAY_ON_ONE_LEG: the moving leg swings up and forward while the supporting knee straightens.

public const int StayOnOneLeg = 1

Field Value

int

SupportKneeAngle

Gymnasium's SUPPORT_KNEE_ANGLE: the supporting knee's target and cap.

public const double SupportKneeAngle = 0.1

Field Value

double

Properties

A

Gymnasium's a: the last action returned (zeros before the first call); a new copy on each read.

public double[] A { get; }

Property Value

double[]

MovingLeg

Gymnasium's moving_leg: the leg that swings (0 left, 1 right).

public int MovingLeg { get; set; }

Property Value

int

State

Gymnasium's state: the gait's phase, StayOnOneLeg, PutOtherDown or PushOff.

public int State { get; set; }

Property Value

int

SupportingKneeAngle

Gymnasium's supporting_knee_angle: the supporting knee's target, raised by 0.03 or 0.06 per step up to SupportKneeAngle, reset from the moving knee at each push-off. Setting it makes it a Python float.

public double SupportingKneeAngle { get; set; }

Property Value

double

SupportingLeg

Gymnasium's supporting_leg: the leg that carries the hull, always 1 - MovingLeg after a swap.

public int SupportingLeg { get; set; }

Property Value

int

Methods

StepHeuristic(NDArray)

Gymnasium's step_heuristic(s): advances the gait's phase from an observation and returns the four motor commands, each joint driven toward its phase's target angle, with the hull's tilt and vertical speed corrected, halved and clipped to [-1, 1].

public NDArray StepHeuristic(NDArray s)

Parameters

s NDArray

An observation of BipedalWalkerEnv: 24 values, float32 as the env returns them (a float64 one is read in float64, as NumPy would; other dtypes are read as their values in float64).

Returns

NDArray

A new float64 array of four commands (hip, knee, hip, knee), the caller's to dispose.

Remarks

Exceptions

ArgumentNullException

Thrown when s is null.

ArgumentException

Thrown for an observation of fewer than 14 values (the gait reads up to s[13], the right foot's contact), before any state changes; Python would fail midway with NumPy's IndexError.