Code export

The game can show you the algorithm you built as real code. The code icon in the top-right of the program area (and the "Export as code" link on the win modal) opens the export modal.

The feature

The generator

features/level/export-algorithm.ts is the pure generator, shared by the modal and its tests. It maps blocks to language statements:

BlockC / JavaScriptPython
move-forwardmove_forward(); / moveForward();move_forward()
turn-left/rightturn_left(); ...turn_left()
forfor (int i = 1; i <= n; i++) { / let ifor i in range(1, n + 1):
whilewhile (!target_reached()) {while not target_reached():
ifif (path_ahead()) { ... } else { ... }if path_ahead(): ... else: ...
switchan if / else if / else chainif / elif / else

A switch exports as an if-else chain because that is the honest translation: each branch is a path condition, and default becomes the final else. Empty Python bodies get a pass, because Python requires one. while exports as "while the target is not reached", which is exactly what the block means.

Symbol naming follows each language's convention: snake_case in C and Python, camelCase in JavaScript. Nested loops are labelled i, j, k (and k beyond), with the same letters shown in the block UI (lib/loopLetter.ts), so the code and the blocks never disagree about which loop is which.

The formatting rules

The formatting is a deliberate contract, locked by tests:

The result reads like a human wrote it, not like a printer dumped a tree.

Where the pieces live

ExportModal.tsx renders the modal; the win modal's Outcome modal link opens it on top; export-algorithm.test.ts locks the formatting contract for all three languages.

Next: Accessibility.