From 77fdc2b44e2de8340a735e88b8f7bdd8aa6963aa Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 04:35:22 +0900 Subject: [PATCH 01/10] feat(tutorial): add the decimal digit stage Stage 8 counts 0 to 9 while Up is ON and carries back to 0. It starts with the counter of stage 7, made to add 0001 only while Up is ON with a Const, a Broadcast and an And, and with Count split into digits. The player makes Carry from the eights and ones digits and Up, and goes back to 0000 with Not Carry spread by a Broadcast and joined with S by an And. The goal tells how Check switches Up over the time steps, so a failure can be replayed, and Up stays OFF while Count is 1001 to catch a Carry that ignores Up. Co-Authored-By: Claude Opus 5.5 --- src/i18n/en.ts | 12 ++++ src/i18n/ja.ts | 12 ++++ src/tutorial/circuit.ts | 4 ++ src/tutorial/stages.test.ts | 26 +++++++ src/tutorial/stages.ts | 135 ++++++++++++++++++++++++++++++++++-- 5 files changed, 185 insertions(+), 4 deletions(-) diff --git a/src/i18n/en.ts b/src/i18n/en.ts index c35da6a..91c3e78 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -64,6 +64,17 @@ const stageTexts: Record = { 'Press the play button and go through the time steps with the right arrow. Press "Auto" to go on by itself, one time step a second. The circuit works when the Display at the top right shows 0 to F in turn.', ], }, + "decimal-digit": { + title: "One decimal digit", + goal: "Writing numbers with 0 to 9, carrying over after 9 as everyday numbers do, is called decimal. Make Count go up by 1 only at the time steps when Up is ON, and go back to 0000 after 1001. At a time step when Count is 1001 and Up is ON, make Carry ON: it tells the digit above to go up. Check turns Up ON for time steps 1 to 9, OFF for 10 and 11, and ON again from 12.", + steps: [ + 'The Const, Broadcast and And on the left send 0001 to B of "Adding four digits" when Up is ON, and 0000 when it is OFF. A Broadcast spreads a one-digit value over several digits: 1111 for ON, 0000 for OFF. An And given values of several digits makes each digit 1 only where both are 1.', + "Make Carry. From 0000 to 1001, only 1001 has 1 in both the eights and the ones digit. Join the top pin (eights) and the bottom pin (ones) on the right of the Decompose below the FlipFlop with an And, join its output and Up with another And, and connect that to Carry.", + "Place a Broadcast, click the pin on its right, enter 4 in the box that appears and press Apply. Its output now has four digits. Do this before connecting it.", + "Go back to 0000 when Carry is ON. S is not connected to the FlipFlop yet. Turn Carry over with a Not, spread it to four digits with that Broadcast, join it and S with an And, and connect the And to the input of the FlipFlop.", + "While playing, click Up to switch it ON and OFF, and go through the time steps with the right arrow. The circuit works when the number on the Display goes up only while Up is ON, and goes back to 0 after 9.", + ], + }, }; export const en = { @@ -90,6 +101,7 @@ export const en = { FLIPFLOP: "Outputs what it received at the time step before (0 at the first time step)", CONST: "Always outputs the value written in it", + BROADCAST: "Spreads a one-digit value over several digits", }, about: (name: string) => `About ${name}`, ofStage: "Available parts", diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index c02fc73..9d81ee7 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -25,6 +25,7 @@ export const ja: Messages = { AGGREGATE: "上のピンを大きい桁として、1つの数にまとめる", FLIPFLOP: "1つ前のステップで受け取った値を出す(最初のステップでは 0)", CONST: "中に書いた値をいつも出す", + BROADCAST: "1桁の値を、同じ値が並んだ何桁もの値に広げる", }, about: (name) => `${name} について`, ofStage: "使える部品", @@ -188,6 +189,17 @@ export const ja: Messages = { "再生ボタンを押し、右の矢印でステップを進めます。「自動」を押すと、1秒に1ステップずつひとりでに進みます。右上の Display に 0 から F が順に出れば、うまく動いています。", ], }, + "decimal-digit": { + title: "10進の1桁", + goal: "ふだんの数のように、0 から 9 までを使い、9 の次で桁が上がる書き方を10進数といいます。Up が ON のステップだけ Count が 1 増え、1001 の次は 0000 に戻るようにしましょう。Count が 1001 で Up が ON のステップでは、Carry を ON にします。Carry は、上の桁に桁上がりを知らせる合図です。確かめるときは、Up を 1〜9 ステップ目は ON、10・11 ステップ目は OFF、12 ステップ目からはまた ON にします。", + steps: [ + "左の Const・Broadcast・And は、Up が ON のときは 0001 を、OFF のときは 0000 を「4桁の足し算」の B に送っています。Broadcast は、1桁の値を、同じ値が並んだ何桁もの値に広げます(ON なら 1111、OFF なら 0000)。And に何桁もの値をつなぐと、桁ごとに、両方が 1 の桁だけ 1 になります。", + "Carry を作ります。0000 から 1001 のうち、8 の桁と 1 の桁がどちらも 1 なのは 1001 だけです。FlipFlop の下の Decompose の右側の、一番上(8 の桁)と一番下(1 の桁)のピンを And でまとめ、その出力と Up をもう1つの And でまとめて、Carry につなぎます。", + "Broadcast を置き、右側のピンをクリックして、出てきた欄に 4 を入れて「適用」を押します。出力が4桁になります。線をつなぐ前にしておきます。", + "Carry が ON のときに 0000 に戻す部分を作ります。S はまだ FlipFlop につながっていません。Carry を Not で反対にし、その Broadcast で4桁に広げ、S と And でまとめて、FlipFlop の入力につなぎます。", + "再生中は、Up をクリックして ON と OFF を切り替えながら、右の矢印でステップを進めます。Up が ON のときだけ Display の数が進み、9 の次に 0 に戻れば、うまく動いています。", + ], + }, }, }, componentProperties: { diff --git a/src/tutorial/circuit.ts b/src/tutorial/circuit.ts index 5e012c1..f3c29c0 100644 --- a/src/tutorial/circuit.ts +++ b/src/tutorial/circuit.ts @@ -41,6 +41,10 @@ export class StageCircuit { return node; } + setBitWidth(node: CCNode, componentPin: CCComponentPin, bitWidth: number) { + this.split(node, componentPin, [bitWidth]); + } + split(node: CCNode, componentPin: CCComponentPin, widths: readonly number[]) { const [first, ...rest] = widths; const existing = this.store.nodePins.getManyByNodeIdAndComponentPinId( diff --git a/src/tutorial/stages.test.ts b/src/tutorial/stages.test.ts index eb88894..d4f7603 100644 --- a/src/tutorial/stages.test.ts +++ b/src/tutorial/stages.test.ts @@ -120,6 +120,32 @@ describe("the counter stage", () => { }); }); +describe("the decimal digit stage", () => { + it("shows Count held at 1001 while Up is OFF, and the carry back to 0000", () => { + const decimal = nullthrows(findTutorialStage("decimal-digit")); + const table = nullthrows(goalTableOf(decimal.check)); + const digitsOf = (values: boolean[][]) => + values.map((value) => value.map(Number).join("")); + + expect(table.inputs).toEqual(["Up"]); + expect(table.outputs).toEqual(["Count", "Carry"]); + expect( + table.rows.map(({ stepNumber, inputs, outputs }) => [ + stepNumber, + ...digitsOf(inputs), + ...digitsOf(outputs), + ]), + ).toEqual([ + [1, "1", "0000", "0"], + [2, "1", "0001", "0"], + [10, "0", "1001", "0"], + [11, "0", "1001", "0"], + [12, "1", "1001", "1"], + [13, "1", "0000", "0"], + ]); + }); +}); + describe("setUpTutorialStage with decorations", () => { it("places the display only for the player, not inside the part handed over", () => { const fourBit = nullthrows(findTutorialStage("four-bit-adder")); diff --git a/src/tutorial/stages.ts b/src/tutorial/stages.ts index 1b49ab1..9484181 100644 --- a/src/tutorial/stages.ts +++ b/src/tutorial/stages.ts @@ -2,6 +2,7 @@ import nullthrows from "nullthrows"; import type { BitNotation } from "../common/bitLabel"; import { bitsOf, numberOf } from "../common/bits"; import type { Rect } from "../common/rect"; +import type { Vector2 } from "../common/vector2"; import type CCStore from "../store"; import { type CCComponent, @@ -12,6 +13,7 @@ import type { CCComponentPin } from "../store/componentPin"; import { aggregate, and, + broadcast, const_, decompose, display, @@ -42,6 +44,7 @@ export const tutorialStageIds = [ "full-adder", "four-bit-adder", "counter", + "decimal-digit", ] as const; export type TutorialStageId = (typeof tutorialStageIds)[number]; export type StageTitleOf = (id: TutorialStageId) => string; @@ -260,12 +263,15 @@ const fullAdderStage = defineStage("full-adder", { const digitCount = 4; -/** A 7seg showing a number on a Display at the top right; returns the 7seg's input */ -function placeNumeral(circuit: StageCircuit): CCNodePinId { - const digit = circuit.place(seven_segment.component.id, { x: 290, y: -250 }); +/** A 7seg at `position` showing a number on a Display right of it; returns the 7seg's input */ +function placeNumeral( + circuit: StageCircuit, + position: Vector2 = { x: 290, y: -250 }, +): CCNodePinId { + const digit = circuit.place(seven_segment.component.id, position); const screen = circuit.place( display.component.id, - { x: 430, y: -250 }, + { x: position.x + 140, y: position.y }, { resolution: { x: 4, y: 7 }, pixelOrder: "row-major" }, ); circuit.connect( @@ -406,6 +412,126 @@ const counterStage = defineStage("counter", { }, }); +const decimalDigitCount = 10; + +/** Count goes up while Up is ON and back to 0 after 9; Carry is ON when it goes back */ +const decimalDigitStage = defineStage("decimal-digit", { + parts: [flipflop, const_, broadcast, and, not, decompose].map( + (part) => part.component.id, + ), + givenParts: ["four-bit-adder"], + tableNotation: "digits", + pinDistance: 600, + check: sequentialCheck( + { inputs: oneBitInputs("Up"), outputs: ["Count", "Carry"] }, + { + initialState: 0, + step: (count, { Up }) => { + const isUp = isOn(Up); + const carries = isUp && count === decimalDigitCount - 1; + return { + outputs: { Count: bitsOf(count, digitCount), Carry: bit(carries) }, + next: carries ? 0 : isUp ? count + 1 : count, + }; + }, + }, + // Up is OFF while Count stays at 9, so a Carry that ignores Up is caught + Array.from({ length: 24 }, (_, index) => ({ + Up: bit(index + 1 < 10 || index + 1 > 11), + })), + [1, 2, 10, 11, 12, 13], + ), + layOut(circuit, { decorate }) { + const memory = circuit.place(flipflop.component.id, { x: 250, y: -100 }); + const adder = circuit.place(fourBitAdderStage.componentId, { + x: -120, + y: -100, + }); + const one = circuit.place( + const_.component.id, + { x: -420, y: -330 }, + { mode: "binary", data: bitsOf(1, digitCount) }, + ); + const spreadUp = circuit.place(broadcast.component.id, { x: -420, y: 60 }); + const step = circuit.place(and.component.id, { x: -260, y: -40 }); + const digits = circuit.place(decompose.component.id, { x: 250, y: 130 }); + circuit.setBitWidth(spreadUp, broadcast.outputPin.Out, digitCount); + circuit.split( + digits, + decompose.outputPin.Out, + new Array(digitCount).fill(1), + ); + const count = circuit.pinOf(memory, flipflop.outputPin.Out); + circuit.connect(count, circuit.pin("Count")); + circuit.connect(count, circuit.pinOf(adder, "A")); + circuit.connect(count, circuit.pinOf(digits, decompose.inputPin.In)); + circuit.connect( + circuit.pin("Up"), + circuit.pinOf(spreadUp, broadcast.inputPin.In), + ); + circuit.connect( + circuit.pinOf(one, const_.outputPin.Out), + circuit.pinOf(step, and.inputPin.A), + ); + circuit.connect( + circuit.pinOf(spreadUp, broadcast.outputPin.Out), + circuit.pinOf(step, and.inputPin.B), + ); + circuit.connect( + circuit.pinOf(step, and.outputPin.Out), + circuit.pinOf(adder, "B"), + ); + if (decorate) { + circuit.connect(count, placeNumeral(circuit, { x: 420, y: -330 })); + } + return () => { + const nineAt = circuit.place(and.component.id, { x: 420, y: 150 }); + const carries = circuit.place(and.component.id, { x: 500, y: 100 }); + const stays = circuit.place(not.component.id, { x: 0, y: 60 }); + const spreadStays = circuit.place(broadcast.component.id, { + x: 120, + y: 60, + }); + const kept = circuit.place(and.component.id, { x: 70, y: -100 }); + circuit.setBitWidth(spreadStays, broadcast.outputPin.Out, digitCount); + const digit = (index: number) => + circuit.pinOf(digits, decompose.outputPin.Out, index); + circuit.connect(digit(0), circuit.pinOf(nineAt, and.inputPin.A)); + circuit.connect( + digit(digitCount - 1), + circuit.pinOf(nineAt, and.inputPin.B), + ); + circuit.connect( + circuit.pinOf(nineAt, and.outputPin.Out), + circuit.pinOf(carries, and.inputPin.A), + ); + circuit.connect( + circuit.pin("Up"), + circuit.pinOf(carries, and.inputPin.B), + ); + const carry = circuit.pinOf(carries, and.outputPin.Out); + circuit.connect(carry, circuit.pin("Carry")); + circuit.connect(carry, circuit.pinOf(stays, not.inputPin.In)); + circuit.connect( + circuit.pinOf(stays, not.outputPin.Out), + circuit.pinOf(spreadStays, broadcast.inputPin.In), + ); + circuit.connect( + circuit.pinOf(adder, "S"), + circuit.pinOf(kept, and.inputPin.A), + ); + circuit.connect( + circuit.pinOf(spreadStays, broadcast.outputPin.Out), + circuit.pinOf(kept, and.inputPin.B), + ); + circuit.connect( + circuit.pinOf(kept, and.outputPin.Out), + circuit.pinOf(memory, flipflop.inputPin.In), + ); + }; + }, +}); + export const tutorialStages: readonly TutorialStage[] = [ andStage, aOnlyStage, @@ -414,6 +540,7 @@ export const tutorialStages: readonly TutorialStage[] = [ fullAdderStage, fourBitAdderStage, counterStage, + decimalDigitStage, ]; /** Between the columns of input and output pins, also for a stage without inputs */ From cd287f92a93b3056c8c3b660d28e2210385d3607 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 04:45:10 +0900 Subject: [PATCH 02/10] fix(tutorial): make stage 8 buildable as its steps say, and keep stage layouts apart - The adder sits below the FlipFlop, so the wire from Count to A no longer looks like S already going into the FlipFlop. - The steps say to change the 1 in the width box to 4, and to take Not's input from the And that drives Carry, as Carry itself has no output. - The goal says that 1001 is 9, that Carry turns ON, and that Check switches Up. - The solution's Ands no longer overlap, and a test now checks that no stage places a node over another, before or after it is solved. Co-Authored-By: Claude Opus 5.5 --- src/i18n/en.ts | 8 ++++---- src/i18n/ja.ts | 8 ++++---- src/tutorial/stages.test.ts | 31 +++++++++++++++++++++++++++++++ src/tutorial/stages.ts | 32 +++++++++++++++++--------------- 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 91c3e78..84a65b1 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -66,12 +66,12 @@ const stageTexts: Record = { }, "decimal-digit": { title: "One decimal digit", - goal: "Writing numbers with 0 to 9, carrying over after 9 as everyday numbers do, is called decimal. Make Count go up by 1 only at the time steps when Up is ON, and go back to 0000 after 1001. At a time step when Count is 1001 and Up is ON, make Carry ON: it tells the digit above to go up. Check turns Up ON for time steps 1 to 9, OFF for 10 and 11, and ON again from 12.", + goal: "Writing numbers with 0 to 9, carrying over after 9 as everyday numbers do, is called decimal. Make Count go up by 1 only at the time steps when Up is ON, and go back to 0000 after 1001. 1001 is 9, 8 plus 1. At a time step when Count is 1001 and Up is ON, make Carry turn ON: it tells the digit above to go up. Check turns Up ON for time steps 1 to 9, OFF for 10 and 11, and ON again from 12.", steps: [ 'The Const, Broadcast and And on the left send 0001 to B of "Adding four digits" when Up is ON, and 0000 when it is OFF. A Broadcast spreads a one-digit value over several digits: 1111 for ON, 0000 for OFF. An And given values of several digits makes each digit 1 only where both are 1.', "Make Carry. From 0000 to 1001, only 1001 has 1 in both the eights and the ones digit. Join the top pin (eights) and the bottom pin (ones) on the right of the Decompose below the FlipFlop with an And, join its output and Up with another And, and connect that to Carry.", - "Place a Broadcast, click the pin on its right, enter 4 in the box that appears and press Apply. Its output now has four digits. Do this before connecting it.", - "Go back to 0000 when Carry is ON. S is not connected to the FlipFlop yet. Turn Carry over with a Not, spread it to four digits with that Broadcast, join it and S with an And, and connect the And to the input of the FlipFlop.", + "Place a Broadcast, click the pin on its right, change the 1 in the box that appears to 4 and press Apply. Its output now has four digits. Do this before connecting it.", + "Go back to 0000 when Carry is ON. S is not connected to the FlipFlop yet. Connect the output of the And that goes to Carry to a Not as well to turn it over, spread it to four digits with that Broadcast, join it and S with an And, and connect the And to the input of the FlipFlop.", "While playing, click Up to switch it ON and OFF, and go through the time steps with the right arrow. The circuit works when the number on the Display goes up only while Up is ON, and goes back to 0 after 9.", ], }, @@ -101,7 +101,7 @@ export const en = { FLIPFLOP: "Outputs what it received at the time step before (0 at the first time step)", CONST: "Always outputs the value written in it", - BROADCAST: "Spreads a one-digit value over several digits", + BROADCAST: "Repeats a one-digit value over several digits", }, about: (name: string) => `About ${name}`, ofStage: "Available parts", diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index 9d81ee7..ae9661d 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -191,12 +191,12 @@ export const ja: Messages = { }, "decimal-digit": { title: "10進の1桁", - goal: "ふだんの数のように、0 から 9 までを使い、9 の次で桁が上がる書き方を10進数といいます。Up が ON のステップだけ Count が 1 増え、1001 の次は 0000 に戻るようにしましょう。Count が 1001 で Up が ON のステップでは、Carry を ON にします。Carry は、上の桁に桁上がりを知らせる合図です。確かめるときは、Up を 1〜9 ステップ目は ON、10・11 ステップ目は OFF、12 ステップ目からはまた ON にします。", + goal: "ふだんの数のように、0 から 9 までを使い、9 の次で桁が上がる書き方を10進数といいます。Up が ON のステップだけ Count が 1 増え、1001 の次は 0000 に戻るようにしましょう。1001 は、8 と 1 を足した 9 です。Count が 1001 で Up が ON のステップでは、Carry が ON になるようにします。Carry は、上の桁に桁上がりを知らせる合図です。「確かめる」を押すと、Up を 1〜9 ステップ目は ON、10・11 ステップ目は OFF、12 ステップ目からはまた ON にして調べます。", steps: [ "左の Const・Broadcast・And は、Up が ON のときは 0001 を、OFF のときは 0000 を「4桁の足し算」の B に送っています。Broadcast は、1桁の値を、同じ値が並んだ何桁もの値に広げます(ON なら 1111、OFF なら 0000)。And に何桁もの値をつなぐと、桁ごとに、両方が 1 の桁だけ 1 になります。", - "Carry を作ります。0000 から 1001 のうち、8 の桁と 1 の桁がどちらも 1 なのは 1001 だけです。FlipFlop の下の Decompose の右側の、一番上(8 の桁)と一番下(1 の桁)のピンを And でまとめ、その出力と Up をもう1つの And でまとめて、Carry につなぎます。", - "Broadcast を置き、右側のピンをクリックして、出てきた欄に 4 を入れて「適用」を押します。出力が4桁になります。線をつなぐ前にしておきます。", - "Carry が ON のときに 0000 に戻す部分を作ります。S はまだ FlipFlop につながっていません。Carry を Not で反対にし、その Broadcast で4桁に広げ、S と And でまとめて、FlipFlop の入力につなぎます。", + "Carry を作ります。0000 から 1001 のうち、8の位と1の位がどちらも 1 なのは 1001 だけです。FlipFlop の下の Decompose の右側の、一番上(8の位)と一番下(1の位)のピンを And でまとめ、その出力と Up をもう1つの And でまとめて、Carry につなぎます。", + "Broadcast を置き、右側のピンをクリックして、出てきた欄の 1 を 4 に書きかえて「適用」を押します。出力が4桁になります。線をつなぐ前にしておきます。", + "Carry が ON のときに 0000 に戻す部分を作ります。S はまだ FlipFlop につながっていません。Carry につないだ And の出力を Not にもつないで反対にし、その Broadcast で4桁に広げ、S と And でまとめて、FlipFlop の入力につなぎます。", "再生中は、Up をクリックして ON と OFF を切り替えながら、右の矢印でステップを進めます。Up が ON のときだけ Display の数が進み、9 の次に 0 に戻れば、うまく動いています。", ], }, diff --git a/src/tutorial/stages.test.ts b/src/tutorial/stages.test.ts index d4f7603..fc0229b 100644 --- a/src/tutorial/stages.test.ts +++ b/src/tutorial/stages.test.ts @@ -1,5 +1,6 @@ import nullthrows from "nullthrows"; import { describe, expect, it } from "vitest"; +import { getCCComponentEditorRendererNodeGeometry } from "../pages/edit/Editor/renderer/Node/geometry"; import type { CCComponentId } from "../store/component"; import { and, @@ -85,6 +86,36 @@ describe("tutorialStages", () => { ); }); +describe("the layout of every stage", () => { + it.each(tutorialStages.map((s) => [s.id, s] as const))( + "%s places no node over another, also once solved", + (_, laidOut) => { + const store = createTestStore(); + setUpTutorialStage(store, laidOut, titleOf)(); + const rects = store.nodes + .getManyByParentComponentId(laidOut.componentId) + .map((node) => ({ + name: nullthrows(store.components.get(node.componentId)).name, + ...getCCComponentEditorRendererNodeGeometry(store, node.id).rect, + })); + const overlaps = rects.flatMap((a, i) => + rects + .slice(i + 1) + .filter( + (b) => + a.position.x < b.position.x + b.size.x && + b.position.x < a.position.x + a.size.x && + a.position.y < b.position.y + b.size.y && + b.position.y < a.position.y + a.size.y, + ) + .map((b) => `${a.name} and ${b.name}`), + ); + + expect(overlaps).toEqual([]); + }, + ); +}); + describe("setUpTutorialStage", () => { it("hands over the parts of earlier stages, built and named after them", () => { const store = createTestStore(); diff --git a/src/tutorial/stages.ts b/src/tutorial/stages.ts index 9484181..2153780 100644 --- a/src/tutorial/stages.ts +++ b/src/tutorial/stages.ts @@ -421,7 +421,7 @@ const decimalDigitStage = defineStage("decimal-digit", { ), givenParts: ["four-bit-adder"], tableNotation: "digits", - pinDistance: 600, + pinDistance: 560, check: sequentialCheck( { inputs: oneBitInputs("Up"), outputs: ["Count", "Carry"] }, { @@ -442,19 +442,21 @@ const decimalDigitStage = defineStage("decimal-digit", { [1, 2, 10, 11, 12, 13], ), layOut(circuit, { decorate }) { - const memory = circuit.place(flipflop.component.id, { x: 250, y: -100 }); + // The adder sits well below the FlipFlop, so that the wire from Count to A + // crosses over and does not look like S already going into the FlipFlop + const memory = circuit.place(flipflop.component.id, { x: 200, y: -100 }); const adder = circuit.place(fourBitAdderStage.componentId, { - x: -120, - y: -100, + x: -60, + y: 120, }); const one = circuit.place( const_.component.id, - { x: -420, y: -330 }, + { x: -350, y: -300 }, { mode: "binary", data: bitsOf(1, digitCount) }, ); - const spreadUp = circuit.place(broadcast.component.id, { x: -420, y: 60 }); - const step = circuit.place(and.component.id, { x: -260, y: -40 }); - const digits = circuit.place(decompose.component.id, { x: 250, y: 130 }); + const spreadUp = circuit.place(broadcast.component.id, { x: -380, y: 100 }); + const step = circuit.place(and.component.id, { x: -220, y: 40 }); + const digits = circuit.place(decompose.component.id, { x: 200, y: 170 }); circuit.setBitWidth(spreadUp, broadcast.outputPin.Out, digitCount); circuit.split( digits, @@ -482,17 +484,17 @@ const decimalDigitStage = defineStage("decimal-digit", { circuit.pinOf(adder, "B"), ); if (decorate) { - circuit.connect(count, placeNumeral(circuit, { x: 420, y: -330 })); + circuit.connect(count, placeNumeral(circuit, { x: 380, y: -330 })); } return () => { - const nineAt = circuit.place(and.component.id, { x: 420, y: 150 }); - const carries = circuit.place(and.component.id, { x: 500, y: 100 }); - const stays = circuit.place(not.component.id, { x: 0, y: 60 }); + const nineAt = circuit.place(and.component.id, { x: 340, y: 230 }); + const carries = circuit.place(and.component.id, { x: 440, y: 130 }); + const stays = circuit.place(not.component.id, { x: 340, y: 30 }); const spreadStays = circuit.place(broadcast.component.id, { - x: 120, - y: 60, + x: 340, + y: -30, }); - const kept = circuit.place(and.component.id, { x: 70, y: -100 }); + const kept = circuit.place(and.component.id, { x: 60, y: -60 }); circuit.setBitWidth(spreadStays, broadcast.outputPin.Out, digitCount); const digit = (index: number) => circuit.pinOf(digits, decompose.outputPin.Out, index); From 252d29b6574172e732171edb39b8ce118785817e Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 19:15:05 +0900 Subject: [PATCH 03/10] fix(tutorial): teach the word bit where the editor first shows it The Const box shows "4 bits" in stage 7, and in stage 8 the box for the width of a Broadcast's pin and the notice on a refused wire speak of bit widths. Stage 7 now says that a digit of a binary number is called a bit, and stage 8 says that the box is the bit width, the number of bits of the output. Co-Authored-By: Claude Opus 5.5 --- src/i18n/en.ts | 4 ++-- src/i18n/ja.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 84a65b1..5096147 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -59,7 +59,7 @@ const stageTexts: Record = { goal: "After pressing the play button, a number with an arrow button on each side appears at the bottom. The number is called the time step, and the right arrow goes to the next one. The circuit runs one time step at a time. Make Count go up by 1 at each time step, and go back to 0000 after 1111. 0000 to 1111 are 0 to F in hexadecimal.", steps: [ "Place a FlipFlop. A FlipFlop outputs what it received at the time step before, and 0 at the first time step. Connect its output to Count and to the 7seg at the top right.", - "Place a Const. A Const always outputs the value written in it. Change 00000000 in its box to 0001 and press Apply (four digits, to match the B it connects to).", + 'Place a Const. A Const always outputs the value written in it. Change 00000000 in its box to 0001 and press Apply (four digits, to match the B it connects to). The "4 bits" below the box is the number of digits: a digit of a binary number is called a bit.', 'Place "Adding four digits". Connect the output of the FlipFlop to its A, the Const to its B, and its S to the input of the FlipFlop. Then the number the FlipFlop outputs plus 1 comes out of the FlipFlop at the next time step. C is not used.', 'Press the play button and go through the time steps with the right arrow. Press "Auto" to go on by itself, one time step a second. The circuit works when the Display at the top right shows 0 to F in turn.', ], @@ -70,7 +70,7 @@ const stageTexts: Record = { steps: [ 'The Const, Broadcast and And on the left send 0001 to B of "Adding four digits" when Up is ON, and 0000 when it is OFF. A Broadcast spreads a one-digit value over several digits: 1111 for ON, 0000 for OFF. An And given values of several digits makes each digit 1 only where both are 1.', "Make Carry. From 0000 to 1001, only 1001 has 1 in both the eights and the ones digit. Join the top pin (eights) and the bottom pin (ones) on the right of the Decompose below the FlipFlop with an And, join its output and Up with another And, and connect that to Carry.", - "Place a Broadcast, click the pin on its right, change the 1 in the box that appears to 4 and press Apply. Its output now has four digits. Do this before connecting it.", + "Place a Broadcast and click the pin on its right. The box that appears is the bit width, the number of bits of the output. Change its 1 to 4 and press Apply, and the output has four digits. Do this before connecting it.", "Go back to 0000 when Carry is ON. S is not connected to the FlipFlop yet. Connect the output of the And that goes to Carry to a Not as well to turn it over, spread it to four digits with that Broadcast, join it and S with an And, and connect the And to the input of the FlipFlop.", "While playing, click Up to switch it ON and OFF, and go through the time steps with the right arrow. The circuit works when the number on the Display goes up only while Up is ON, and goes back to 0 after 9.", ], diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index ae9661d..1e36aa6 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -184,7 +184,7 @@ export const ja: Messages = { goal: "再生ボタンを押すと、下に数字と、その左右に矢印のボタンが出ます。この数字を「ステップ」といい、右の矢印を押すと次のステップに進みます。回路はステップごとに動きます。Count が 1 ステップごとに 1 ずつ増え、1111 の次は 0000 に戻るようにしましょう。0000 から 1111 は、16進数の 0 から F です。", steps: [ "FlipFlop を置きます。FlipFlop は、1つ前のステップで受け取った値を出します。最初のステップでは 0 を出します。FlipFlop の出力を、Count と、右上の 7seg につなぎます。", - "Const を置きます。Const は、中に書いた値をいつも出します。欄の 00000000 を 0001 に書きかえて、「適用」を押します(つなぐ先の B に合わせて、4桁で書きます)。", + "Const を置きます。Const は、中に書いた値をいつも出します。欄の 00000000 を 0001 に書きかえて、「適用」を押します(つなぐ先の B に合わせて、4桁で書きます)。欄の下の「4 ビット」は、書いた値の桁の数です。2進数の1桁を「ビット」といいます。", "「4桁の足し算」を置き、FlipFlop の出力を A に、Const を B に、S を FlipFlop の入力につなぎます。こうすると、FlipFlop が出している数に 1 を足した数が、次のステップで FlipFlop から出てきます。C は使いません。", "再生ボタンを押し、右の矢印でステップを進めます。「自動」を押すと、1秒に1ステップずつひとりでに進みます。右上の Display に 0 から F が順に出れば、うまく動いています。", ], @@ -195,7 +195,7 @@ export const ja: Messages = { steps: [ "左の Const・Broadcast・And は、Up が ON のときは 0001 を、OFF のときは 0000 を「4桁の足し算」の B に送っています。Broadcast は、1桁の値を、同じ値が並んだ何桁もの値に広げます(ON なら 1111、OFF なら 0000)。And に何桁もの値をつなぐと、桁ごとに、両方が 1 の桁だけ 1 になります。", "Carry を作ります。0000 から 1001 のうち、8の位と1の位がどちらも 1 なのは 1001 だけです。FlipFlop の下の Decompose の右側の、一番上(8の位)と一番下(1の位)のピンを And でまとめ、その出力と Up をもう1つの And でまとめて、Carry につなぎます。", - "Broadcast を置き、右側のピンをクリックして、出てきた欄の 1 を 4 に書きかえて「適用」を押します。出力が4桁になります。線をつなぐ前にしておきます。", + "Broadcast を置き、右側のピンをクリックします。出てきた欄はビット幅、つまり出力のビット数です。1 を 4 に書きかえて「適用」を押すと、出力が4桁になります。線をつなぐ前にしておきます。", "Carry が ON のときに 0000 に戻す部分を作ります。S はまだ FlipFlop につながっていません。Carry につないだ And の出力を Not にもつないで反対にし、その Broadcast で4桁に広げ、S と And でまとめて、FlipFlop の入力につなぎます。", "再生中は、Up をクリックして ON と OFF を切り替えながら、右の矢印でステップを進めます。Up が ON のときだけ Display の数が進み、9 の次に 0 に戻れば、うまく動いています。", ], From 91550725f1e796065905ce2362e060d95d22d200 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 19:17:35 +0900 Subject: [PATCH 04/10] fix(tutorial): move the FlipFlop of stage 8 left, and the adder and Const as asked Co-Authored-By: Claude Opus 5.5 --- src/i18n/en.ts | 2 +- src/i18n/ja.ts | 2 +- src/tutorial/stages.ts | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 5096147..8fac142 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -69,7 +69,7 @@ const stageTexts: Record = { goal: "Writing numbers with 0 to 9, carrying over after 9 as everyday numbers do, is called decimal. Make Count go up by 1 only at the time steps when Up is ON, and go back to 0000 after 1001. 1001 is 9, 8 plus 1. At a time step when Count is 1001 and Up is ON, make Carry turn ON: it tells the digit above to go up. Check turns Up ON for time steps 1 to 9, OFF for 10 and 11, and ON again from 12.", steps: [ 'The Const, Broadcast and And on the left send 0001 to B of "Adding four digits" when Up is ON, and 0000 when it is OFF. A Broadcast spreads a one-digit value over several digits: 1111 for ON, 0000 for OFF. An And given values of several digits makes each digit 1 only where both are 1.', - "Make Carry. From 0000 to 1001, only 1001 has 1 in both the eights and the ones digit. Join the top pin (eights) and the bottom pin (ones) on the right of the Decompose below the FlipFlop with an And, join its output and Up with another And, and connect that to Carry.", + "Make Carry. From 0000 to 1001, only 1001 has 1 in both the eights and the ones digit. Join the top pin (eights) and the bottom pin (ones) on the right of the Decompose at the bottom with an And, join its output and Up with another And, and connect that to Carry.", "Place a Broadcast and click the pin on its right. The box that appears is the bit width, the number of bits of the output. Change its 1 to 4 and press Apply, and the output has four digits. Do this before connecting it.", "Go back to 0000 when Carry is ON. S is not connected to the FlipFlop yet. Connect the output of the And that goes to Carry to a Not as well to turn it over, spread it to four digits with that Broadcast, join it and S with an And, and connect the And to the input of the FlipFlop.", "While playing, click Up to switch it ON and OFF, and go through the time steps with the right arrow. The circuit works when the number on the Display goes up only while Up is ON, and goes back to 0 after 9.", diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index 1e36aa6..2f4b4ca 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -194,7 +194,7 @@ export const ja: Messages = { goal: "ふだんの数のように、0 から 9 までを使い、9 の次で桁が上がる書き方を10進数といいます。Up が ON のステップだけ Count が 1 増え、1001 の次は 0000 に戻るようにしましょう。1001 は、8 と 1 を足した 9 です。Count が 1001 で Up が ON のステップでは、Carry が ON になるようにします。Carry は、上の桁に桁上がりを知らせる合図です。「確かめる」を押すと、Up を 1〜9 ステップ目は ON、10・11 ステップ目は OFF、12 ステップ目からはまた ON にして調べます。", steps: [ "左の Const・Broadcast・And は、Up が ON のときは 0001 を、OFF のときは 0000 を「4桁の足し算」の B に送っています。Broadcast は、1桁の値を、同じ値が並んだ何桁もの値に広げます(ON なら 1111、OFF なら 0000)。And に何桁もの値をつなぐと、桁ごとに、両方が 1 の桁だけ 1 になります。", - "Carry を作ります。0000 から 1001 のうち、8の位と1の位がどちらも 1 なのは 1001 だけです。FlipFlop の下の Decompose の右側の、一番上(8の位)と一番下(1の位)のピンを And でまとめ、その出力と Up をもう1つの And でまとめて、Carry につなぎます。", + "Carry を作ります。0000 から 1001 のうち、8の位と1の位がどちらも 1 なのは 1001 だけです。一番下の Decompose の右側の、一番上(8の位)と一番下(1の位)のピンを And でまとめ、その出力と Up をもう1つの And でまとめて、Carry につなぎます。", "Broadcast を置き、右側のピンをクリックします。出てきた欄はビット幅、つまり出力のビット数です。1 を 4 に書きかえて「適用」を押すと、出力が4桁になります。線をつなぐ前にしておきます。", "Carry が ON のときに 0000 に戻す部分を作ります。S はまだ FlipFlop につながっていません。Carry につないだ And の出力を Not にもつないで反対にし、その Broadcast で4桁に広げ、S と And でまとめて、FlipFlop の入力につなぎます。", "再生中は、Up をクリックして ON と OFF を切り替えながら、右の矢印でステップを進めます。Up が ON のときだけ Display の数が進み、9 の次に 0 に戻れば、うまく動いています。", diff --git a/src/tutorial/stages.ts b/src/tutorial/stages.ts index 2153780..ff1565c 100644 --- a/src/tutorial/stages.ts +++ b/src/tutorial/stages.ts @@ -444,19 +444,19 @@ const decimalDigitStage = defineStage("decimal-digit", { layOut(circuit, { decorate }) { // The adder sits well below the FlipFlop, so that the wire from Count to A // crosses over and does not look like S already going into the FlipFlop - const memory = circuit.place(flipflop.component.id, { x: 200, y: -100 }); + const memory = circuit.place(flipflop.component.id, { x: 80, y: -100 }); const adder = circuit.place(fourBitAdderStage.componentId, { - x: -60, + x: 0, y: 120, }); const one = circuit.place( const_.component.id, - { x: -350, y: -300 }, + { x: -400, y: -300 }, { mode: "binary", data: bitsOf(1, digitCount) }, ); const spreadUp = circuit.place(broadcast.component.id, { x: -380, y: 100 }); const step = circuit.place(and.component.id, { x: -220, y: 40 }); - const digits = circuit.place(decompose.component.id, { x: 200, y: 170 }); + const digits = circuit.place(decompose.component.id, { x: 80, y: 300 }); circuit.setBitWidth(spreadUp, broadcast.outputPin.Out, digitCount); circuit.split( digits, @@ -487,14 +487,14 @@ const decimalDigitStage = defineStage("decimal-digit", { circuit.connect(count, placeNumeral(circuit, { x: 380, y: -330 })); } return () => { - const nineAt = circuit.place(and.component.id, { x: 340, y: 230 }); + const nineAt = circuit.place(and.component.id, { x: 260, y: 300 }); const carries = circuit.place(and.component.id, { x: 440, y: 130 }); const stays = circuit.place(not.component.id, { x: 340, y: 30 }); const spreadStays = circuit.place(broadcast.component.id, { x: 340, y: -30, }); - const kept = circuit.place(and.component.id, { x: 60, y: -60 }); + const kept = circuit.place(and.component.id, { x: -100, y: -60 }); circuit.setBitWidth(spreadStays, broadcast.outputPin.Out, digitCount); const digit = (index: number) => circuit.pinOf(digits, decompose.outputPin.Out, index); From 9521c8fb3060c384501072bbc51c631ac971dfd3 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 19:18:23 +0900 Subject: [PATCH 05/10] fix(tutorial): put the Decompose of stage 8 back where it was Co-Authored-By: Claude Opus 5.5 --- src/tutorial/stages.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tutorial/stages.ts b/src/tutorial/stages.ts index ff1565c..45b99ee 100644 --- a/src/tutorial/stages.ts +++ b/src/tutorial/stages.ts @@ -456,7 +456,7 @@ const decimalDigitStage = defineStage("decimal-digit", { ); const spreadUp = circuit.place(broadcast.component.id, { x: -380, y: 100 }); const step = circuit.place(and.component.id, { x: -220, y: 40 }); - const digits = circuit.place(decompose.component.id, { x: 80, y: 300 }); + const digits = circuit.place(decompose.component.id, { x: 200, y: 170 }); circuit.setBitWidth(spreadUp, broadcast.outputPin.Out, digitCount); circuit.split( digits, @@ -487,7 +487,7 @@ const decimalDigitStage = defineStage("decimal-digit", { circuit.connect(count, placeNumeral(circuit, { x: 380, y: -330 })); } return () => { - const nineAt = circuit.place(and.component.id, { x: 260, y: 300 }); + const nineAt = circuit.place(and.component.id, { x: 340, y: 230 }); const carries = circuit.place(and.component.id, { x: 440, y: 130 }); const stays = circuit.place(not.component.id, { x: 340, y: 30 }); const spreadStays = circuit.place(broadcast.component.id, { From c1553f69ed195e33365c747d6439c5698beee0b0 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 19:23:19 +0900 Subject: [PATCH 06/10] fix(tutorial): keep the wires stage 8 starts with clear of its nodes The wire from the FlipFlop back to the adder ran over both of them and the adder's name, and the wire from the Const to the And grazed the Const. The FlipFlop now sits left of the adder, so every wire placed runs left to right, and the Decompose sits below on the left, where its wire passes clear of the adder. A test now checks, for every stage, that no wire it starts with runs over a node or the name above it. The path of a wire moves out of the renderer, so that the test follows the same curve the editor draws. Co-Authored-By: Claude Opus 5.5 --- .../edit/Editor/renderer/Connection/index.tsx | 30 ++------- .../edit/Editor/renderer/Connection/path.ts | 60 ++++++++++++++++++ src/tutorial/stages.test.ts | 61 +++++++++++++++++++ src/tutorial/stages.ts | 26 ++++---- 4 files changed, 140 insertions(+), 37 deletions(-) create mode 100644 src/pages/edit/Editor/renderer/Connection/path.ts diff --git a/src/pages/edit/Editor/renderer/Connection/index.tsx b/src/pages/edit/Editor/renderer/Connection/index.tsx index 094150d..0574ad6 100644 --- a/src/pages/edit/Editor/renderer/Connection/index.tsx +++ b/src/pages/edit/Editor/renderer/Connection/index.tsx @@ -1,7 +1,5 @@ import nullthrows from "nullthrows"; import { useState } from "react"; -import type { Vector2 } from "../../../../../common/vector2"; -import type { CCComponentPinType } from "../../../../../store/componentPin"; import type { CCConnectionId } from "../../../../../store/connection"; import { useStore } from "../../../../../store/react"; import { @@ -12,12 +10,13 @@ import { theme } from "../../../../../style"; import { useComponentEditorStore } from "../../store"; import { stringifySimulationValue } from "../../store/slices/core/index"; import { getCCComponentEditorRendererNodeGeometry } from "../Node/geometry"; +import { + type CCComponentEditorRendererConnectionEndpoint, + connectionPathData, +} from "./path"; import styles from "./style.module.css"; -export type CCComponentEditorRendererConnectionEndpoint = { - direction: CCComponentPinType; - position: Vector2; -}; +export type { CCComponentEditorRendererConnectionEndpoint }; export type CCComponentEditorRendererConnectionCoreProps = { from: CCComponentEditorRendererConnectionEndpoint; @@ -29,13 +28,8 @@ export type CCComponentEditorRendererConnectionCoreProps = { onMouseLeave?: React.MouseEventHandler; }; -const straightGap = 10; const HIT_AREA_STROKE_WIDTH = 12; const VALUE_LABEL_SIZE = { x: 200, y: 24 }; -const polarity: Record = { - input: -1, - output: 1, -}; export function CCComponentEditorRendererConnectionCore({ from, to, @@ -46,19 +40,7 @@ export function CCComponentEditorRendererConnectionCore({ }: CCComponentEditorRendererConnectionCoreProps) { const componentEditorState = useComponentEditorStore()(); - const d = [ - `M ${from.position.x} ${from.position.y}`, - `h ${straightGap * polarity[from.direction]}`, - `C ${[ - from.position.x + 4 * straightGap * polarity[from.direction], - from.position.y, - to.position.x + 4 * straightGap * polarity[to.direction], - to.position.y, - to.position.x + straightGap * polarity[to.direction], - to.position.y, - ].join(" ")}`, - `h ${straightGap * polarity[from.direction]}`, - ].join(" "); + const d = connectionPathData(from, to); return ( <> diff --git a/src/pages/edit/Editor/renderer/Connection/path.ts b/src/pages/edit/Editor/renderer/Connection/path.ts new file mode 100644 index 0000000..b50f1f1 --- /dev/null +++ b/src/pages/edit/Editor/renderer/Connection/path.ts @@ -0,0 +1,60 @@ +import type { Vector2 } from "../../../../../common/vector2"; +import type { CCComponentPinType } from "../../../../../store/componentPin"; + +export type CCComponentEditorRendererConnectionEndpoint = { + direction: CCComponentPinType; + position: Vector2; +}; + +const straightGap = 10; +const polarity: Record = { + input: -1, + output: 1, +}; + +/** A wire leaves `from` straight, bends along a cubic curve and enters `to` straight */ +export function connectionCurve( + from: CCComponentEditorRendererConnectionEndpoint, + to: CCComponentEditorRendererConnectionEndpoint, +): [Vector2, Vector2, Vector2, Vector2] { + const fromSide = straightGap * polarity[from.direction]; + const toSide = straightGap * polarity[to.direction]; + return [ + { x: from.position.x + fromSide, y: from.position.y }, + { x: from.position.x + 4 * fromSide, y: from.position.y }, + { x: to.position.x + 4 * toSide, y: to.position.y }, + { x: to.position.x + toSide, y: to.position.y }, + ]; +} + +export function connectionPathData( + from: CCComponentEditorRendererConnectionEndpoint, + to: CCComponentEditorRendererConnectionEndpoint, +): string { + const [start, control1, control2, end] = connectionCurve(from, to); + return [ + `M ${from.position.x} ${from.position.y}`, + `L ${start.x} ${start.y}`, + `C ${control1.x} ${control1.y} ${control2.x} ${control2.y} ${end.x} ${end.y}`, + `L ${to.position.x} ${to.position.y}`, + ].join(" "); +} + +/** Points along the curve of a wire, from `from` to `to` */ +export function pointsOnConnection( + from: CCComponentEditorRendererConnectionEndpoint, + to: CCComponentEditorRendererConnectionEndpoint, + count: number, +): Vector2[] { + const [p0, p1, p2, p3] = connectionCurve(from, to); + return Array.from({ length: count + 1 }, (_, index) => { + const t = index / count; + const u = 1 - t; + const at = (key: "x" | "y") => + u ** 3 * p0[key] + + 3 * u ** 2 * t * p1[key] + + 3 * u * t ** 2 * p2[key] + + t ** 3 * p3[key]; + return { x: at("x"), y: at("y") }; + }); +} diff --git a/src/tutorial/stages.test.ts b/src/tutorial/stages.test.ts index fc0229b..12619ee 100644 --- a/src/tutorial/stages.test.ts +++ b/src/tutorial/stages.test.ts @@ -1,5 +1,6 @@ import nullthrows from "nullthrows"; import { describe, expect, it } from "vitest"; +import { pointsOnConnection } from "../pages/edit/Editor/renderer/Connection/path"; import { getCCComponentEditorRendererNodeGeometry } from "../pages/edit/Editor/renderer/Node/geometry"; import type { CCComponentId } from "../store/component"; import { @@ -12,6 +13,8 @@ import { seven_segment, xor, } from "../store/intrinsics/definitions"; +import type { CCNodeId } from "../store/node"; +import type { CCNodePinId } from "../store/nodePin"; import { createTestStore, registerTestComponent, @@ -116,6 +119,64 @@ describe("the layout of every stage", () => { ); }); +describe("the wires every stage starts with", () => { + // A node's name is written above it + const titleHeight = 17; + const clearance = 6; + + it.each(tutorialStages.map((s) => [s.id, s] as const))( + "%s runs no wire over a node or its name", + (_, laidOut) => { + const store = createTestStore(); + setUpTutorialStage(store, laidOut, titleOf); + const nodes = store.nodes.getManyByParentComponentId(laidOut.componentId); + const nameOf = (nodeId: CCNodeId) => + nullthrows( + store.components.get(nullthrows(store.nodes.get(nodeId)).componentId), + ).name; + const endpointOf = (nodePinId: CCNodePinId) => { + const nodePin = nullthrows(store.nodePins.get(nodePinId)); + return { + nodeId: nodePin.nodeId, + direction: nullthrows(store.componentPins.get(nodePin.componentPinId)) + .type, + position: nullthrows( + getCCComponentEditorRendererNodeGeometry( + store, + nodePin.nodeId, + ).nodePinPositionById.get(nodePinId), + ), + }; + }; + const crossings = store.connections + .getManyByParentComponentId(laidOut.componentId) + .flatMap((connection) => { + const from = endpointOf(connection.from); + const to = endpointOf(connection.to); + const points = pointsOnConnection(from, to, 100); + return nodes + .filter((node) => { + const { position, size } = + getCCComponentEditorRendererNodeGeometry(store, node.id).rect; + return points.some( + (point) => + point.x > position.x - clearance && + point.x < position.x + size.x + clearance && + point.y > position.y - titleHeight - clearance && + point.y < position.y + size.y + clearance, + ); + }) + .map( + (node) => + `${nameOf(from.nodeId)} to ${nameOf(to.nodeId)} over ${nameOf(node.id)}`, + ); + }); + + expect(crossings).toEqual([]); + }, + ); +}); + describe("setUpTutorialStage", () => { it("hands over the parts of earlier stages, built and named after them", () => { const store = createTestStore(); diff --git a/src/tutorial/stages.ts b/src/tutorial/stages.ts index 45b99ee..49a40f5 100644 --- a/src/tutorial/stages.ts +++ b/src/tutorial/stages.ts @@ -442,21 +442,21 @@ const decimalDigitStage = defineStage("decimal-digit", { [1, 2, 10, 11, 12, 13], ), layOut(circuit, { decorate }) { - // The adder sits well below the FlipFlop, so that the wire from Count to A - // crosses over and does not look like S already going into the FlipFlop - const memory = circuit.place(flipflop.component.id, { x: 80, y: -100 }); + // Every wire placed runs left to right, so none crosses a node; only the wire + // from S back to the FlipFlop, which the player draws, runs back + const memory = circuit.place(flipflop.component.id, { x: -150, y: -150 }); const adder = circuit.place(fourBitAdderStage.componentId, { - x: 0, - y: 120, + x: 100, + y: 0, }); const one = circuit.place( const_.component.id, { x: -400, y: -300 }, { mode: "binary", data: bitsOf(1, digitCount) }, ); - const spreadUp = circuit.place(broadcast.component.id, { x: -380, y: 100 }); - const step = circuit.place(and.component.id, { x: -220, y: 40 }); - const digits = circuit.place(decompose.component.id, { x: 200, y: 170 }); + const spreadUp = circuit.place(broadcast.component.id, { x: -400, y: 120 }); + const step = circuit.place(and.component.id, { x: -150, y: 120 }); + const digits = circuit.place(decompose.component.id, { x: 0, y: 250 }); circuit.setBitWidth(spreadUp, broadcast.outputPin.Out, digitCount); circuit.split( digits, @@ -487,14 +487,14 @@ const decimalDigitStage = defineStage("decimal-digit", { circuit.connect(count, placeNumeral(circuit, { x: 380, y: -330 })); } return () => { - const nineAt = circuit.place(and.component.id, { x: 340, y: 230 }); - const carries = circuit.place(and.component.id, { x: 440, y: 130 }); - const stays = circuit.place(not.component.id, { x: 340, y: 30 }); + const nineAt = circuit.place(and.component.id, { x: 180, y: 290 }); + const carries = circuit.place(and.component.id, { x: 330, y: 200 }); + const stays = circuit.place(not.component.id, { x: 380, y: 40 }); const spreadStays = circuit.place(broadcast.component.id, { - x: 340, + x: 380, y: -30, }); - const kept = circuit.place(and.component.id, { x: -100, y: -60 }); + const kept = circuit.place(and.component.id, { x: -320, y: -150 }); circuit.setBitWidth(spreadStays, broadcast.outputPin.Out, digitCount); const digit = (index: number) => circuit.pinOf(digits, decompose.outputPin.Out, index); From f9741cd465a76d8b142c370954f6dbb6db79a611 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 19:30:46 +0900 Subject: [PATCH 07/10] test(tutorial): count node names in the layout checks, and share their sizes with the editor The overlap check now covers the name above each node, which moves an And of the stage 8 solution clear of the Const. The checks take the height of a name and the straight part of a wire from the editor's own constants, and the path of a wire gets a test of its own. Co-Authored-By: Claude Opus 5.5 --- .../Editor/renderer/Connection/path.test.ts | 23 ++++++++++++++ .../edit/Editor/renderer/Connection/path.ts | 7 +++-- .../Node/components/Default/geometry.ts | 11 +++++++ .../Node/components/Default/index.tsx | 7 ++--- src/tutorial/stages.test.ts | 30 ++++++++++++------- src/tutorial/stages.ts | 5 ++-- 6 files changed, 63 insertions(+), 20 deletions(-) create mode 100644 src/pages/edit/Editor/renderer/Connection/path.test.ts diff --git a/src/pages/edit/Editor/renderer/Connection/path.test.ts b/src/pages/edit/Editor/renderer/Connection/path.test.ts new file mode 100644 index 0000000..6476341 --- /dev/null +++ b/src/pages/edit/Editor/renderer/Connection/path.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from "vitest"; +import { connectionPathData, pointsOnConnection } from "./path"; + +const from = { direction: "output" as const, position: { x: 0, y: 0 } }; +const to = { direction: "input" as const, position: { x: 100, y: 50 } }; + +describe("connectionPathData", () => { + it("runs straight out of the output, bends, and runs straight into the input", () => { + expect(connectionPathData(from, to)).toBe( + "M 0 0 L 10 0 C 40 0 60 50 90 50 L 100 50", + ); + }); +}); + +describe("pointsOnConnection", () => { + it("follows the curve from where it bends out to where it bends in", () => { + const points = pointsOnConnection(from, to, 4); + + expect(points[0]).toEqual({ x: 10, y: 0 }); + expect(points[2]).toEqual({ x: 50, y: 25 }); + expect(points[4]).toEqual({ x: 90, y: 50 }); + }); +}); diff --git a/src/pages/edit/Editor/renderer/Connection/path.ts b/src/pages/edit/Editor/renderer/Connection/path.ts index b50f1f1..ff9a5f7 100644 --- a/src/pages/edit/Editor/renderer/Connection/path.ts +++ b/src/pages/edit/Editor/renderer/Connection/path.ts @@ -6,7 +6,8 @@ export type CCComponentEditorRendererConnectionEndpoint = { position: Vector2; }; -const straightGap = 10; +/** How far a wire runs straight out of a pin before it bends */ +export const connectionStraightGap = 10; const polarity: Record = { input: -1, output: 1, @@ -17,8 +18,8 @@ export function connectionCurve( from: CCComponentEditorRendererConnectionEndpoint, to: CCComponentEditorRendererConnectionEndpoint, ): [Vector2, Vector2, Vector2, Vector2] { - const fromSide = straightGap * polarity[from.direction]; - const toSide = straightGap * polarity[to.direction]; + const fromSide = connectionStraightGap * polarity[from.direction]; + const toSide = connectionStraightGap * polarity[to.direction]; return [ { x: from.position.x + fromSide, y: from.position.y }, { x: from.position.x + 4 * fromSide, y: from.position.y }, diff --git a/src/pages/edit/Editor/renderer/Node/components/Default/geometry.ts b/src/pages/edit/Editor/renderer/Node/components/Default/geometry.ts index 4c40bed..55c27fd 100644 --- a/src/pages/edit/Editor/renderer/Node/components/Default/geometry.ts +++ b/src/pages/edit/Editor/renderer/Node/components/Default/geometry.ts @@ -5,6 +5,17 @@ import type { CCComponentEditorRendererNodeLayoutSource, } from "../../types"; +/** The name of a node is written above its top left corner */ +export const CC_COMPONENT_EDITOR_RENDERER_NODE_TITLE = { + baselineY: -5, + fontSize: 12, +}; + +/** How far above a node its name reaches */ +export const nodeTitleHeight = + CC_COMPONENT_EDITOR_RENDERER_NODE_TITLE.fontSize - + CC_COMPONENT_EDITOR_RENDERER_NODE_TITLE.baselineY; + const width = 100; const gapY = 20; const paddingY = 15; diff --git a/src/pages/edit/Editor/renderer/Node/components/Default/index.tsx b/src/pages/edit/Editor/renderer/Node/components/Default/index.tsx index 2729fbb..79f3605 100644 --- a/src/pages/edit/Editor/renderer/Node/components/Default/index.tsx +++ b/src/pages/edit/Editor/renderer/Node/components/Default/index.tsx @@ -2,10 +2,9 @@ import type { Ref } from "react"; import styles from "../../style.module.css"; import type { CCComponentEditorRendererNodeRendererProps } from "../../types"; -export const CC_COMPONENT_EDITOR_RENDERER_NODE_TITLE = { - baselineY: -5, - fontSize: 12, -}; +import { CC_COMPONENT_EDITOR_RENDERER_NODE_TITLE } from "./geometry"; + +export { CC_COMPONENT_EDITOR_RENDERER_NODE_TITLE }; export function CCComponentEditorRendererNodeDefaultRenderer({ title, diff --git a/src/tutorial/stages.test.ts b/src/tutorial/stages.test.ts index 12619ee..42d5920 100644 --- a/src/tutorial/stages.test.ts +++ b/src/tutorial/stages.test.ts @@ -1,6 +1,10 @@ import nullthrows from "nullthrows"; import { describe, expect, it } from "vitest"; -import { pointsOnConnection } from "../pages/edit/Editor/renderer/Connection/path"; +import { + connectionStraightGap, + pointsOnConnection, +} from "../pages/edit/Editor/renderer/Connection/path"; +import { nodeTitleHeight } from "../pages/edit/Editor/renderer/Node/components/Default/geometry"; import { getCCComponentEditorRendererNodeGeometry } from "../pages/edit/Editor/renderer/Node/geometry"; import type { CCComponentId } from "../store/component"; import { @@ -91,16 +95,23 @@ describe("tutorialStages", () => { describe("the layout of every stage", () => { it.each(tutorialStages.map((s) => [s.id, s] as const))( - "%s places no node over another, also once solved", + "%s places no node or its name over another, also once solved", (_, laidOut) => { const store = createTestStore(); setUpTutorialStage(store, laidOut, titleOf)(); const rects = store.nodes .getManyByParentComponentId(laidOut.componentId) - .map((node) => ({ - name: nullthrows(store.components.get(node.componentId)).name, - ...getCCComponentEditorRendererNodeGeometry(store, node.id).rect, - })); + .map((node) => { + const { position, size } = getCCComponentEditorRendererNodeGeometry( + store, + node.id, + ).rect; + return { + name: nullthrows(store.components.get(node.componentId)).name, + position: { x: position.x, y: position.y - nodeTitleHeight }, + size: { x: size.x, y: size.y + nodeTitleHeight }, + }; + }); const overlaps = rects.flatMap((a, i) => rects .slice(i + 1) @@ -120,9 +131,8 @@ describe("the layout of every stage", () => { }); describe("the wires every stage starts with", () => { - // A node's name is written above it - const titleHeight = 17; - const clearance = 6; + // Below the straight part of a wire, which starts that far from its own node + const clearance = connectionStraightGap - 4; it.each(tutorialStages.map((s) => [s.id, s] as const))( "%s runs no wire over a node or its name", @@ -162,7 +172,7 @@ describe("the wires every stage starts with", () => { (point) => point.x > position.x - clearance && point.x < position.x + size.x + clearance && - point.y > position.y - titleHeight - clearance && + point.y > position.y - nodeTitleHeight - clearance && point.y < position.y + size.y + clearance, ); }) diff --git a/src/tutorial/stages.ts b/src/tutorial/stages.ts index 49a40f5..645ff50 100644 --- a/src/tutorial/stages.ts +++ b/src/tutorial/stages.ts @@ -442,8 +442,7 @@ const decimalDigitStage = defineStage("decimal-digit", { [1, 2, 10, 11, 12, 13], ), layOut(circuit, { decorate }) { - // Every wire placed runs left to right, so none crosses a node; only the wire - // from S back to the FlipFlop, which the player draws, runs back + // Every wire placed here runs left to right, so that none crosses a node const memory = circuit.place(flipflop.component.id, { x: -150, y: -150 }); const adder = circuit.place(fourBitAdderStage.componentId, { x: 100, @@ -494,7 +493,7 @@ const decimalDigitStage = defineStage("decimal-digit", { x: 380, y: -30, }); - const kept = circuit.place(and.component.id, { x: -320, y: -150 }); + const kept = circuit.place(and.component.id, { x: -320, y: -120 }); circuit.setBitWidth(spreadStays, broadcast.outputPin.Out, digitCount); const digit = (index: number) => circuit.pinOf(digits, decompose.outputPin.Out, index); From e7efdf15356a4fabd35246ecc4081fe64a79980b Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 19:31:23 +0900 Subject: [PATCH 08/10] fix(tutorial): write widths in bits once stage 7 has taught the word Stage 8 and the Broadcast summary spoke of digits for the width of a value, and one step mixed bits and digits. They now say bits for widths, and keep digits and places for the positions in a number. Co-Authored-By: Claude Opus 5.5 --- src/i18n/en.ts | 8 ++++---- src/i18n/ja.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 8fac142..0d098bd 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -68,10 +68,10 @@ const stageTexts: Record = { title: "One decimal digit", goal: "Writing numbers with 0 to 9, carrying over after 9 as everyday numbers do, is called decimal. Make Count go up by 1 only at the time steps when Up is ON, and go back to 0000 after 1001. 1001 is 9, 8 plus 1. At a time step when Count is 1001 and Up is ON, make Carry turn ON: it tells the digit above to go up. Check turns Up ON for time steps 1 to 9, OFF for 10 and 11, and ON again from 12.", steps: [ - 'The Const, Broadcast and And on the left send 0001 to B of "Adding four digits" when Up is ON, and 0000 when it is OFF. A Broadcast spreads a one-digit value over several digits: 1111 for ON, 0000 for OFF. An And given values of several digits makes each digit 1 only where both are 1.', + 'The Const, Broadcast and And on the left send 0001 to B of "Adding four digits" when Up is ON, and 0000 when it is OFF. A Broadcast spreads a one-bit value over several bits: 1111 for ON, 0000 for OFF. An And given values of several bits makes each bit 1 only where both are 1.', "Make Carry. From 0000 to 1001, only 1001 has 1 in both the eights and the ones digit. Join the top pin (eights) and the bottom pin (ones) on the right of the Decompose at the bottom with an And, join its output and Up with another And, and connect that to Carry.", - "Place a Broadcast and click the pin on its right. The box that appears is the bit width, the number of bits of the output. Change its 1 to 4 and press Apply, and the output has four digits. Do this before connecting it.", - "Go back to 0000 when Carry is ON. S is not connected to the FlipFlop yet. Connect the output of the And that goes to Carry to a Not as well to turn it over, spread it to four digits with that Broadcast, join it and S with an And, and connect the And to the input of the FlipFlop.", + "Place a Broadcast and click the pin on its right. The box that appears is the bit width, the number of bits of the output. Change its 1 to 4 and press Apply, and the output has four bits. Do this before connecting it.", + "Go back to 0000 when Carry is ON. S is not connected to the FlipFlop yet. Connect the output of the And that goes to Carry to a Not as well to turn it over, spread it to four bits with that Broadcast, join it and S with an And, and connect the And to the input of the FlipFlop.", "While playing, click Up to switch it ON and OFF, and go through the time steps with the right arrow. The circuit works when the number on the Display goes up only while Up is ON, and goes back to 0 after 9.", ], }, @@ -101,7 +101,7 @@ export const en = { FLIPFLOP: "Outputs what it received at the time step before (0 at the first time step)", CONST: "Always outputs the value written in it", - BROADCAST: "Repeats a one-digit value over several digits", + BROADCAST: "Repeats a one-bit value over several bits", }, about: (name: string) => `About ${name}`, ofStage: "Available parts", diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index 2f4b4ca..cea6b41 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -25,7 +25,7 @@ export const ja: Messages = { AGGREGATE: "上のピンを大きい桁として、1つの数にまとめる", FLIPFLOP: "1つ前のステップで受け取った値を出す(最初のステップでは 0)", CONST: "中に書いた値をいつも出す", - BROADCAST: "1桁の値を、同じ値が並んだ何桁もの値に広げる", + BROADCAST: "1ビットの値を、同じ値が並んだ何ビットもの値に広げる", }, about: (name) => `${name} について`, ofStage: "使える部品", @@ -193,10 +193,10 @@ export const ja: Messages = { title: "10進の1桁", goal: "ふだんの数のように、0 から 9 までを使い、9 の次で桁が上がる書き方を10進数といいます。Up が ON のステップだけ Count が 1 増え、1001 の次は 0000 に戻るようにしましょう。1001 は、8 と 1 を足した 9 です。Count が 1001 で Up が ON のステップでは、Carry が ON になるようにします。Carry は、上の桁に桁上がりを知らせる合図です。「確かめる」を押すと、Up を 1〜9 ステップ目は ON、10・11 ステップ目は OFF、12 ステップ目からはまた ON にして調べます。", steps: [ - "左の Const・Broadcast・And は、Up が ON のときは 0001 を、OFF のときは 0000 を「4桁の足し算」の B に送っています。Broadcast は、1桁の値を、同じ値が並んだ何桁もの値に広げます(ON なら 1111、OFF なら 0000)。And に何桁もの値をつなぐと、桁ごとに、両方が 1 の桁だけ 1 になります。", + "左の Const・Broadcast・And は、Up が ON のときは 0001 を、OFF のときは 0000 を「4桁の足し算」の B に送っています。Broadcast は、1ビットの値を、同じ値が並んだ何ビットもの値に広げます(ON なら 1111、OFF なら 0000)。And に何ビットもの値をつなぐと、ビットごとに、両方が 1 のビットだけ 1 になります。", "Carry を作ります。0000 から 1001 のうち、8の位と1の位がどちらも 1 なのは 1001 だけです。一番下の Decompose の右側の、一番上(8の位)と一番下(1の位)のピンを And でまとめ、その出力と Up をもう1つの And でまとめて、Carry につなぎます。", - "Broadcast を置き、右側のピンをクリックします。出てきた欄はビット幅、つまり出力のビット数です。1 を 4 に書きかえて「適用」を押すと、出力が4桁になります。線をつなぐ前にしておきます。", - "Carry が ON のときに 0000 に戻す部分を作ります。S はまだ FlipFlop につながっていません。Carry につないだ And の出力を Not にもつないで反対にし、その Broadcast で4桁に広げ、S と And でまとめて、FlipFlop の入力につなぎます。", + "Broadcast を置き、右側のピンをクリックします。出てきた欄はビット幅、つまり出力のビット数です。1 を 4 に書きかえて「適用」を押すと、出力が4ビットになります。線をつなぐ前にしておきます。", + "Carry が ON のときに 0000 に戻す部分を作ります。S はまだ FlipFlop につながっていません。Carry につないだ And の出力を Not にもつないで反対にし、その Broadcast で4ビットに広げ、S と And でまとめて、FlipFlop の入力につなぎます。", "再生中は、Up をクリックして ON と OFF を切り替えながら、右の矢印でステップを進めます。Up が ON のときだけ Display の数が進み、9 の次に 0 に戻れば、うまく動いています。", ], }, From d6ed1e8e676ac1610da98c24f60ef1df61a044a4 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 19:34:56 +0900 Subject: [PATCH 09/10] fix(tutorial): teach the word bit with binary in stage 4, and write widths in bits Part summaries and the message on a pin of the wrong width show the same text in every stage, so the word bit cannot wait for stage 7. Stage 4 now says that a digit of a binary number is called a bit, and Decompose, Aggregate, the width message and the Const step write widths in bits. Digits and places stay for the positions in a number and for how many digits a number has. Co-Authored-By: Claude Opus 5.5 --- src/i18n/en.ts | 14 ++++++-------- src/i18n/ja.ts | 10 +++++----- src/i18n/messages.test.ts | 8 ++++---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 0d098bd..d04c8ea 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -6,7 +6,7 @@ const listOf = (names: readonly string[]) => names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`; -const digits = (count: number) => (count === 1 ? "1 digit" : `${count} digits`); +const bitCount = (count: number) => (count === 1 ? "1 bit" : `${count} bits`); const themOf = (names: readonly string[]) => names.length === 1 ? "it" : "them"; @@ -36,7 +36,7 @@ const stageTexts: Record = { }, "half-adder": { title: "Adding one digit", - goal: "From here on, think of ON as 1 and OFF as 0, and the tables write them that way too. Then A + B is 0, 1 or 2. Binary writes numbers with only 0 and 1: just as 9 + 1 carries over and becomes 10 in everyday numbers, 1 + 1 carries over and becomes 10 in binary. So 0, 1 and 2 are 00, 01 and 10 in two digits. Output the left digit (the twos digit) to C and the right digit (the ones digit) to S. C is called the carry and S the sum, and this circuit is called a half adder.", + goal: "From here on, think of ON as 1 and OFF as 0, and the tables write them that way too. Then A + B is 0, 1 or 2. Binary writes numbers with only 0 and 1: just as 9 + 1 carries over and becomes 10 in everyday numbers, 1 + 1 carries over and becomes 10 in binary. So 0, 1 and 2 are 00, 01 and 10 in two digits. A digit of a binary number is called a bit. Output the left digit (the twos digit) to C and the right digit (the ones digit) to S. C is called the carry and S the sum, and this circuit is called a half adder.", steps: [], }, "full-adder": { @@ -59,7 +59,7 @@ const stageTexts: Record = { goal: "After pressing the play button, a number with an arrow button on each side appears at the bottom. The number is called the time step, and the right arrow goes to the next one. The circuit runs one time step at a time. Make Count go up by 1 at each time step, and go back to 0000 after 1111. 0000 to 1111 are 0 to F in hexadecimal.", steps: [ "Place a FlipFlop. A FlipFlop outputs what it received at the time step before, and 0 at the first time step. Connect its output to Count and to the 7seg at the top right.", - 'Place a Const. A Const always outputs the value written in it. Change 00000000 in its box to 0001 and press Apply (four digits, to match the B it connects to). The "4 bits" below the box is the number of digits: a digit of a binary number is called a bit.', + 'Place a Const. A Const always outputs the value written in it. Change 00000000 in its box to 0001 and press Apply (four bits, to match the B it connects to). The "4 bits" below the box is the number of bits of the value.', 'Place "Adding four digits". Connect the output of the FlipFlop to its A, the Const to its B, and its S to the input of the FlipFlop. Then the number the FlipFlop outputs plus 1 comes out of the FlipFlop at the next time step. C is not used.', 'Press the play button and go through the time steps with the right arrow. Press "Auto" to go on by itself, one time step a second. The circuit works when the Display at the top right shows 0 to F in turn.', ], @@ -94,10 +94,8 @@ export const en = { XOR: "ON when exactly one input is ON", TRUE: "Always ON", FALSE: "Always OFF", - DECOMPOSE: - "Splits a number of several digits, from the highest digit down", - AGGREGATE: - "Joins values into one number, the upper pins as the higher digits", + DECOMPOSE: "Splits a value of several bits, from the highest bit down", + AGGREGATE: "Joins values into one, the upper pins as the higher bits", FLIPFLOP: "Outputs what it received at the time step before (0 at the first time step)", CONST: "Always outputs the value written in it", @@ -198,7 +196,7 @@ export const en = { missingPin: (pinType: "input" | "output", pinName: string) => `There is no ${pinType} pin named ${pinName}. "Reset this stage" brings back how the stage started.`, wrongBitWidth: (pinName: string, expected: number, actual: number) => - `${pinName} should have ${digits(expected)}, but it has ${digits(actual)}. Check what it is connected to.`, + `${pinName} should have ${bitCount(expected)}, but it has ${bitCount(actual)}. Check what it is connected to.`, wrongOutput: ( inputs: readonly { name: string; value: string }[], pinName: string, diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index cea6b41..4787676 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -21,8 +21,8 @@ export const ja: Messages = { XOR: "片方だけが ON のとき ON", TRUE: "いつも ON", FALSE: "いつも OFF", - DECOMPOSE: "何桁もある数を、上の桁から順に分ける", - AGGREGATE: "上のピンを大きい桁として、1つの数にまとめる", + DECOMPOSE: "何ビットもある値を、上のビットから順に分ける", + AGGREGATE: "上のピンを上のビットとして、値を1つにまとめる", FLIPFLOP: "1つ前のステップで受け取った値を出す(最初のステップでは 0)", CONST: "中に書いた値をいつも出す", BROADCAST: "1ビットの値を、同じ値が並んだ何ビットもの値に広げる", @@ -121,7 +121,7 @@ export const ja: Messages = { missingPin: (pinType, pinName) => `${pinName} という名前の${pinType === "input" ? "入力" : "出力"}ピンが見つかりません。「この課題をやり直す」で最初の状態に戻せます。`, wrongBitWidth: (pinName, expected, actual) => - `${pinName} は ${expected}桁のはずですが、${actual}桁になっています。つないだ先を確かめてください。`, + `${pinName} は ${expected}ビットのはずですが、${actual}ビットになっています。つないだ先を確かめてください。`, wrongOutput: (inputs, pinName, expected, actual) => `${inputs.map(({ name, value }) => `${name} が ${value}`).join("、")} のとき、${pinName} は ${expected} になるはずが、${actual === null ? "値がありませんでした" : `${actual} でした`}。`, wrongOutputAtStep: (stepNumber, inputs, pinName, expected, actual) => @@ -161,7 +161,7 @@ export const ja: Messages = { }, "half-adder": { title: "1桁の足し算", - goal: "ここからは ON を 1、OFF を 0 と考え、表もそう書きます。すると、A+B は 0、1、2 のどれかです。2進数では、0 と 1 だけで数を書きます。ふだんの数で 9+1 が繰り上がって 10 になるように、2進数では 1+1 が繰り上がって 10 になります。そのため、0、1、2 は2桁で 00、01、10 です。左の桁(2の位)を C に、右の桁(1の位)を S に出しましょう。C を「桁上がり」、S を「和」といい、この回路を「半加算器」といいます。", + goal: "ここからは ON を 1、OFF を 0 と考え、表もそう書きます。すると、A+B は 0、1、2 のどれかです。2進数では、0 と 1 だけで数を書きます。ふだんの数で 9+1 が繰り上がって 10 になるように、2進数では 1+1 が繰り上がって 10 になります。そのため、0、1、2 は2桁で 00、01、10 です。2進数の1桁を「ビット」といいます。左の桁(2の位)を C に、右の桁(1の位)を S に出しましょう。C を「桁上がり」、S を「和」といい、この回路を「半加算器」といいます。", steps: [], }, "full-adder": { @@ -184,7 +184,7 @@ export const ja: Messages = { goal: "再生ボタンを押すと、下に数字と、その左右に矢印のボタンが出ます。この数字を「ステップ」といい、右の矢印を押すと次のステップに進みます。回路はステップごとに動きます。Count が 1 ステップごとに 1 ずつ増え、1111 の次は 0000 に戻るようにしましょう。0000 から 1111 は、16進数の 0 から F です。", steps: [ "FlipFlop を置きます。FlipFlop は、1つ前のステップで受け取った値を出します。最初のステップでは 0 を出します。FlipFlop の出力を、Count と、右上の 7seg につなぎます。", - "Const を置きます。Const は、中に書いた値をいつも出します。欄の 00000000 を 0001 に書きかえて、「適用」を押します(つなぐ先の B に合わせて、4桁で書きます)。欄の下の「4 ビット」は、書いた値の桁の数です。2進数の1桁を「ビット」といいます。", + "Const を置きます。Const は、中に書いた値をいつも出します。欄の 00000000 を 0001 に書きかえて、「適用」を押します(つなぐ先の B に合わせて、4ビットで書きます)。欄の下の「4 ビット」は、書いた値のビット数です。", "「4桁の足し算」を置き、FlipFlop の出力を A に、Const を B に、S を FlipFlop の入力につなぎます。こうすると、FlipFlop が出している数に 1 を足した数が、次のステップで FlipFlop から出てきます。C は使いません。", "再生ボタンを押し、右の矢印でステップを進めます。「自動」を押すと、1秒に1ステップずつひとりでに進みます。右上の Display に 0 から F が順に出れば、うまく動いています。", ], diff --git a/src/i18n/messages.test.ts b/src/i18n/messages.test.ts index 562e9e3..058d914 100644 --- a/src/i18n/messages.test.ts +++ b/src/i18n/messages.test.ts @@ -160,15 +160,15 @@ describe("the message on a wrong output at a step", () => { }); describe("the message on a pin of the wrong width", () => { - it("counts digits in both languages", () => { + it("counts bits in both languages", () => { expect(messagesByLanguage.en.tutorial.wrongBitWidth("A", 4, 1)).toBe( - "A should have 4 digits, but it has 1 digit. Check what it is connected to.", + "A should have 4 bits, but it has 1 bit. Check what it is connected to.", ); expect(messagesByLanguage.en.tutorial.wrongBitWidth("C", 1, 4)).toBe( - "C should have 1 digit, but it has 4 digits. Check what it is connected to.", + "C should have 1 bit, but it has 4 bits. Check what it is connected to.", ); expect(messagesByLanguage.ja.tutorial.wrongBitWidth("A", 4, 1)).toBe( - "A は 4桁のはずですが、1桁になっています。つないだ先を確かめてください。", + "A は 4ビットのはずですが、1ビットになっています。つないだ先を確かめてください。", ); }); }); From ab986de2303d46c027a88b557c723eeb1f9cdfa7 Mon Sep 17 00:00:00 2001 From: Rn86222 Date: Fri, 20 Nov 2026 19:38:04 +0900 Subject: [PATCH 10/10] fix(tutorial): call positions digits in the Decompose and Aggregate summaries Co-Authored-By: Claude Opus 5.5 --- src/i18n/en.ts | 4 ++-- src/i18n/ja.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/i18n/en.ts b/src/i18n/en.ts index d04c8ea..0b2f91a 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -94,8 +94,8 @@ export const en = { XOR: "ON when exactly one input is ON", TRUE: "Always ON", FALSE: "Always OFF", - DECOMPOSE: "Splits a value of several bits, from the highest bit down", - AGGREGATE: "Joins values into one, the upper pins as the higher bits", + DECOMPOSE: "Splits a value of several bits, from the highest digit down", + AGGREGATE: "Joins values into one, the upper pins as the higher digits", FLIPFLOP: "Outputs what it received at the time step before (0 at the first time step)", CONST: "Always outputs the value written in it", diff --git a/src/i18n/ja.ts b/src/i18n/ja.ts index 4787676..a657f16 100644 --- a/src/i18n/ja.ts +++ b/src/i18n/ja.ts @@ -21,8 +21,8 @@ export const ja: Messages = { XOR: "片方だけが ON のとき ON", TRUE: "いつも ON", FALSE: "いつも OFF", - DECOMPOSE: "何ビットもある値を、上のビットから順に分ける", - AGGREGATE: "上のピンを上のビットとして、値を1つにまとめる", + DECOMPOSE: "何ビットもある値を、上の桁から順に分ける", + AGGREGATE: "上のピンを上の桁として、値を1つにまとめる", FLIPFLOP: "1つ前のステップで受け取った値を出す(最初のステップでは 0)", CONST: "中に書いた値をいつも出す", BROADCAST: "1ビットの値を、同じ値が並んだ何ビットもの値に広げる",