Skip to main content
Back to articles
2026 / 10
| 3 min read

Following a Hewbot program from commands to replay

Run a ten-command Hewbot route in the browser, then inspect the tape and a replay that carries no source.

hew simulation learning
On this page

In Hewbot’s first mission, the robot starts facing east and the flag is seven squares across and two squares down. We can describe that route with three instructions: walk the first leg, turn right, then walk the second. The program has to turn those instructions into one command per line on standard output.

Open First Steps and replace the starter with this program:

fn main() {
    for i in 0..7 { println("MOVE"); }
    println("RIGHT");
    for i in 0..2 { println("MOVE"); }
}

The first loop prints seven MOVE lines. RIGHT changes which way the robot faces, so the two moves from the second loop take it south. Click Run and the robot reaches the flag in ten steps. The turn counts as a step even though the robot stays in the same square.

The loops shorten the source without shortening the route. Writing all ten commands as separate println calls would ask the robot to do the same work. Under Bot tape (stdout), we can inspect what the program actually printed:

MOVE
MOVE
MOVE
MOVE
MOVE
MOVE
MOVE
RIGHT
MOVE
MOVE

That tape sits between the Hew program and the animation. For this mission, the program finishes producing commands before the browser replays them through the simulator. Replay can show the same run again without compiling the program again, and Pause and Step let us inspect individual moves.

The current execution client tries the browser compiler and sandbox for supported programs. It can use a compilation service for richer one-shot programs. You can run this example with the app’s browser compiler, without a native Hew installation.

When the next move needs a sensor

A fixed tape is enough for the first route because nothing changes along the way. Later missions ask a supplied actor program to call the player’s decision function against a world model written in Hew, producing a tape that the browser can replay. That keeps the decisions and their simulated world in one Hew run; reading sensors does not automatically mean making a network request for each move.

The FPGA missions have a different execution path. Their supplied policy reads sensor lines on standard input, and the browser sandbox is invoked against the growing sensor history as the simulated world advances. When a circuit is attached, its outputs change the sensor signals the policy reads.

Keeping a run to watch later

After the route succeeds, Share run opens a preview of the completed recording. Source inclusion starts unchecked. The default recording contains the visible replay and source-cost numbers, while omitting the Hew source, toolbox modules, circuit design, transcript and compiler output.

The sharing code puts a compressed recording into the replay link’s URL fragment, or offers a complete JSON file when a link cannot carry it. Creating either does not upload the recording. The viewer draws the recorded frames without executing the player’s Hew or circuit; the recording is not a verified leaderboard entry.

Choosing Include the frozen winning source and circuit adds the solution from that successful run. The preview lists what will be included. Later editor changes and unused toolbox files are excluded, so the source shown beside a recording stays tied to the run that produced it.

To change this route, replace 0..7 with 0..6 in the first loop and run it again. The program still compiles, but the robot ends one column short of the flag. Compare the new tape and final position with the successful recording.