Skip to content

feat(tutorial): add the four-digit adder stage - #103

Merged
Rn86222 merged 9 commits into
mainfrom
feat/four-bit-adder-stage
Nov 19, 2026
Merged

Rn86222 merged 9 commits into
mainfrom
feat/four-bit-adder-stage

Conversation

@Rn86222

@Rn86222 Rn86222 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Stage 6 adds two four-digit binary numbers with four of stage 5's part and shows the sum as a numeral, the first payoff on the way to the stopwatch. It is the first stage with pins of several bits and with nodes placed besides its pins, so this PR also adds what such a stage needs.

  • Stage 6, "Adding four digits":
    • Inputs A and B (four bits), outputs C and S. The full adder is handed over, and Decompose, Aggregate and False can be placed.
    • It starts with:
      • Decompose twice and Aggregate, split into single digits and wired to A, B and S.
      • A 7seg and a 4x7 Display showing S.
    • The goal says C is the fifth, sixteens digit, and shows three examples as a table.
    • The steps cover:
      • which pin is which digit, and the wires between the Decompose nodes, the adders and Aggregate, including the carry chain;
      • clicking digits while playing;
      • what the 7seg does, and which letter is which number in hexadecimal.
  • Laying out a stage: a stage's layOut places what it starts with besides its pins and returns how to clear it from there. Decorations such as the display are only placed for the player, not inside a part handed over. StageCircuit can set a node's config and split a pin, and a stage can set how far apart its pins sit.
  • Pin widths: before simulating, Check compares each stage pin's width with what the stage expects and says "A should have 4 digits, but it has 1", instead of the simulation's internal English error. A pin in a width conflict and an unconnected output are left to the simulation, which explains them.
  • Examples instead of a table: goalTableOf replaces truthTableOfCheck. It lists every combination when each input is one bit, and otherwise the stage's examples. Table cells hold values of any width, in binary, with every 1 coloured.
  • Fitting the view: a tutorial stage's editor fits its view to the nodes when it opens. It zooms out only as far as needed and keeps clear of the title bar and the play button, so a stage is in view on any window. The free mode keeps its view.
  • A failing check: an exception inside Check becomes a message instead of nothing being shown.
  • Smaller changes:
    • Decompose and Aggregate get summaries.
    • A stage offers only the parts it hands over directly, not those built into them.
    • 桁 is written in kanji throughout.
    • Stages 1 to 3 say the lamp turns ON rather than lights up.
    • describeFailure moves to src/tutorial/failure.ts.
    • bitsOf/numberOf are shared by the value editor and the tests.

Not in this PR

  • Stage 6 is not handed over yet. The first stage to do so, the counter, will test that its 7seg and Display are left out of the part.
  • Decimal values are not added next to binary ones. Brackets would read like a base, inputs are set in binary, and the sum shows on the display.
  • The message on a wrong output keeps ON and OFF for C, as the play-mode node does.
  • Errors without words of their own still show the simulation's English text after "The circuit could not be simulated".

Testing

  • npx vitest run (208 tests), npx tsc -p . and npx biome check src pass. New tests cover:
    • stage 6 cleared by its solution over all 256 combinations, using only the parts it offers
    • the width check: an input left one bit wide, an output fixed to another width, and conflicts and unconnected outputs left to the simulation
    • the width message in both languages
    • example tables, and only directly handed-over parts offered
    • fitting the view, including a renderer smaller than the padding
    • a check that throws becoming a message
  • Checked in the browser:
    • stage 6 fitting the editor in 1280x720 and 1400x1000 windows, clear of the play button, with no wire crossing a node's name
    • clearing it, and the sum on the Display while playing
    • the width message and the unconnected-output message
    • stages 1 to 5 at their usual size
    • every 1 coloured in the example table

🤖 Generated with Claude Code

Rn86222 and others added 9 commits November 20, 2026 01:44
…pin widths

- A stage lays out what it starts with through layOut, which returns how to clear
  it from there. Decorations are only placed for the player, not inside a part
  handed over. StageCircuit can now set a node's config and split a pin.
- A stage can place its pins further apart (pinDistance).
- Check compares each stage pin's bit width with what the stage expects before
  simulating, and says "A should have 4 digits, but it has 1", instead of the
  simulation's internal error.
- describeFailure moves out of the page into src/tutorial/failure.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eral bits

A truth table's cells now hold values of any width, written in binary when they
have several bits. goalTableOf replaces truthTableOfCheck: it lists every
combination when each input is one bit, and otherwise the stage's examples.
The bit helpers bitsOf and numberOf are shared by the value editor and tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stage 6, "Adding four digits", adds two four-bit numbers with four of stage 5's
part. It starts with Decompose and Aggregate split into single digits and wired
to A, B and S, and a 7seg and a 4x7 Display showing S. Its goal shows three
examples, and its steps say which pin is which digit and how the carries chain.

Decompose and Aggregate get summaries, and a stage now offers only the parts it
hands over directly, not those built into them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on, and address the review

- The width check skips a pin in a width conflict and an output nothing fixes, as
  the simulation tells what is wrong with those.
- The English message counts "1 digit" for the expected width too.
- Stage 6 calls C the fifth, sixteens digit, which is 1 when A + B is 16 or more,
  and names the letters the 7seg draws for 10 to 15 (A, b, C, d, E, F).
- StageCircuit.split refuses a pin that is split already.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…of the check itself

- The editor can fit its view to the nodes when it first gets its size, zooming
  out only as far as needed and leaving room for the title bar and the play
  button (fitsNodesInView). The tutorial turns it on, so a stage's nodes are in
  view on any window; the free mode keeps its view.
- Stage 6 places the 7seg right of Aggregate's output, so the wire to it no longer
  crosses its name, and the Display at the top right, away from the play button.
- An exception from the check outside the simulation is caught and logged, and
  the stage says that something went wrong instead of showing nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e the check

- The editor fits its view only once, and only when both sides of the renderer
  have a size, and a renderer smaller than the padding still gets a finite scale.
- checkCombinational itself turns an exception into checkFailed, which is now
  tested. The message no longer suggests resetting the stage, which would throw
  the circuit away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Stages 1 to 3 say the lamp turns ON, as the Out node shows, not that it lights.
- Stage 6 says which side of Decompose and Aggregate holds the digits, names the
  Decompose nodes and adders the wires run between, and where the output C is.
- Stage 6 tells where the sum is shown, what the 7seg does, and which letter is
  which number in hexadecimal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only one-bit values were coloured, so a stage's example table showed C's 1 in
green but the 1s of S in black. Each bit now carries its own colour, and digits
keep their width.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying create-cpu-c8345196-9409-4cce-afc4-389f413ad8ee with  Cloudflare Pages  Cloudflare Pages

Latest commit: 11ee90e
Status: ✅  Deploy successful!
Preview URL: https://234f3935.create-cpu-c8345196-9409-4cce-afc4-389f413ad8ee.pages.dev
Branch Preview URL: https://feat-four-bit-adder-stage.create-cpu-c8345196-9409-4cce-afc4-389f413ad8ee.pages.dev

View logs

@Rn86222
Rn86222 merged commit 21a0707 into main Nov 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant