Previous post: Medical Drone Fleet Next post: A Character That Follows Language Into Action

Grown QWOP Walker

An evolutionary search finds a control plan for a 12-part QWOP-style runner, using a custom Rust physics engine compiled to WebAssembly. It runs in the browser on the CPU, with no GPU required.

Overview

QWOP is difficult because four keys control four leg joints, with no balance assistance. This demo uses evolutionary search to find a control plan for a 12-part runner made up of a torso, head, arms, thighs, calves, and feet. The simulation uses a custom 2D physics engine written in Rust and compiled to WebAssembly, so it can run in the browser on a CPU without a GPU.

Press AI run to watch the saved control plan in action. If the runner falls, the simulation resets and displays a “FACE-PLANT—resetting…” message. The UI shows the keys being held, the runner’s progress and speed, and the number of falls. If you’re up for it, press QWOP me to control the runner yourself. Q and W control the thighs; O and P control the calves.

The physics engine and search code live in the separate diolei/evogait repository. The page loads a saved gait plan rather than training a new one.

The Rig

The runner has 12 rigid body parts connected by 11 hinge joints. Joint limits constrain movement, and torque-limited motors apply forces to the joints.

The design follows the Box2D-based body layout in bicrick/qwop-python, adapted to the custom physics engine. The rig uses high-grip feet, relatively loose neck, elbow, and ankle joints, and no self-collision. The simulation advances at a fixed step of 25 Hz and avoids external runtime libraries.

The Control Plan

The first working gait used a repeating sequence of key presses. It chooses from nine possible actions: no keys, Q, W, O, P, QW, QP, WO, or OP. An earlier description incorrectly called these “12 combinations”; 12 is the number of body parts, while the controller has nine available actions.

The initial controller holds each action for about 0.24 seconds, or six physics steps. The saved plan adds feedback to this basic loop so it can respond to the runner’s posture.

Two signals help adjust the gait:

  • Foot contact: When a foot touches the ground, the controller resets the loop phase, helping synchronize the next movement with the step.
  • Torso position: The controller compares the torso’s position with the feet. If the torso moves too far ahead, it adjusts the drive keys; if it falls behind, it changes the corrective keys.

The saved plan contains 15 values: 12 action choices, a hold parameter, a feedback gain, and a reset flag. The shipped file, policy-best.json, contains the action sequence [7,3,5,6,3,6,6,8,0,7,7,8], with a hold value of 3.79, a feedback gain of 1.366, and reset set to false.

The widget passes these values to WalkerPol(keys,hold,k_fb,reset). The available widget code does not clearly document the units of the hold parameter and feedback gain or the exact meaning of the reset flag, so those details should not be inferred from their numeric values alone.

During an AI run, the page tries the feedback controller in WebAssembly first. If that fails, it falls back to the open-loop action sequence. The fallback matters: the live controller is not guaranteed to run exclusively in feedback mode.

For visualization, the page records 240 trace points, sampling every six physics steps. The displayed gap is the horizontal distance divided by 10, and the displayed speed is smoothed using a blend factor of 0.05. A fall lasting more than 1.5 seconds triggers a reset.

The gait was developed using evolutionary search. The search generates candidate control plans, runs each candidate in the simulator for 45 seconds, and scores its performance. The scoring function rewards forward progress while also considering posture, alternating steps, stride width, and foot scraping. Falls incur a penalty. The search retains the best-performing quarter of the candidates and gradually reduces the size of its changes as optimization proceeds.

Several lessons emerged from tuning the scoring function:

  • Penalize knee scraping. Without a penalty for a low torso combined with bent knees, the search can favor gaits that move forward while dragging the body.
  • Stop unproductive runs early. Runs that remain slumped for too long waste search time, even if the runner has not technically fallen.
  • Reward alternating steps explicitly. Forward progress alone can favor a one-sided shuffle. A staged scoring rule and both cross-beat action patterns were needed to encourage alternating movement.
  • Penalize excessive stride width. Without this penalty, the search tends to discover wide splits instead of a more useful running gait.
  • Allow falls during exploration. Early candidates must be free to try movements that initially fail. Penalizing every fall too heavily can prevent the search from discovering better strategies.

Implementation

Component Implementation
Physics Custom 2D physics solver written in Rust, with no external runtime libraries
Rig 12 rigid body parts and 11 hinge joints, based on the qwop-python body layout
Controller Repeating key sequence with foot-contact and torso-position feedback
Plan format Saved JSON containing 12 action choices and three additional parameters
Search Evolutionary search on the CPU; no GPU required
Runtime WebAssembly, fixed 25 Hz simulation step
Rendering Canvas 2D with a dark track and live telemetry
Saved reward chart Placeholder data: 60 identical values of 23.968

Why use evolutionary search instead of deep reinforcement learning?

This problem has a small, discrete action space, frequent physical contacts, and, in my case, a relatively modest CPU budget. Evolutionary search can evaluate complete candidate plans directly in the simulator, without backpropagation or a GPU-based training stack. Candidate evaluations can also be run independently, making the approach straightforward to parallelize.

That makes evolutionary search a practical fit for this demo. It does not establish that evolutionary methods are generally better than deep reinforcement learning; the choice reflects the constraints and design of this particular project.

References