Track a bounded route, one move at a time

Choose an origin, a direction convention and a finite list of targets before moving. In this 4×4 exercise, a snake route visits all 16 cells with 15 successful moves. The starting cell already counts as visited, so there is no extra move after the final cell.

On this page

Read the exercise board

This is an illustrative board, not a DLC map or emulator. Coordinates use (x, y): x increases to the right, y increases upward, and the origin is the lower-left cell (0, 0). The board is bounded: valid values are 0 through 3 on both axes.

Begin with the starting cell already observed and marked visited. Each Step in the exercise moves to the next cell and marks that arrival. Reset returns to the original position and clears later visits.

01230123startfinish

All 15 planned moves. The full move-number table below remains readable without JavaScript.

before
(0, 0) · 1 visited
action
No move yet; E is planned first.
after
(0, 0) · 1 visited
check
The starting cell already counts as one visit.
next
plan[0] = E; 15 moves remain.

Conceptual pseudocode · fixed teaching trace

Read the highlighted line beside its state. This is not executable DLC code.

  1. direction ← plan[next_index]
  2. attempt one bounded move
  3. if confirmed: update position + visited
  4. advance next_index after success
  5. stop after 15 confirmed moves
  6. if failed: keep confirmed + pending; inspect

Unexpected movement? Keep the last confirmed position and pending target, then reduce the first failure to one action.

The route travels right across row 0, up once, left across row 1, up once, right across row 2, up once, then left across row 3. It finishes at (0, 3). No move wraps around an edge.

The full route without the controls

Move number at each coordinate; read rows from the bottom upward
y / x0123
315: finish141312
2891011
17654
00: start123
  1. Start: position (0, 0), one visited cell, zero moves.
  2. After move 3: position (3, 0), four visited cells. The next move is upward, not rightward.
  3. After move 7: position (0, 1), eight visited cells. Turn upward again.
  4. After move 15: position (0, 3), all 16 visited. There is no move 16.

If JavaScript is unavailable, this table and trace still give the entire route.

Keep movement and work separate

The identity visited = moves + 1 holds in this example because every move succeeds, reaches a new cell and marks it visited. It is not a universal rule. A repeated cell adds a move without adding a new visit; an unsuccessful move adds neither.

Likewise, a visit is not a harvested resource or a safe excavation. If the job includes work at each cell, give that work its own result and completion count. See state and memory for a before-and-after record.

Before following a route, check the next coordinate against the bounds. At the end of each row, change row and direction deliberately. A condition that only checks the current x value can accidentally repeat the edge action.

What to carry into the underground game

Carry over the planning questions, rather than assuming this board’s rules apply underground:

  • Which axes and directions does the current game expose?
  • What does an attempted movement return or visibly change?
  • Can a cell be revisited, blocked or changed by excavation?
  • What ends this particular job: a target, a count, a resource condition or a puzzle state?

Those answers determine whether a snake route is appropriate. The official DLC description mentions route optimization, but this exercise does not establish underground wrapping, collapse, obstacles or safe digging behavior.

Sources and further reading