A campaign with unlocks, synthesised sound, puzzles and the puzzle of the week
- Campaign projects start with NAND only; challenges open along a
dependency chain, each solution becomes a usable part, and basic parts
unlock on the way. Locked parts and challenges say what opens them.
- Sound effects made with Web Audio: place, connect, switches, buttons,
delete, clock ticks (opt-in), solve, fail, unlock, record. Mute and
volume in the top bar and Display settings.
- Publish any circuit as a puzzle link; only its behaviour is shared.
The server re-runs the checks on submitted solutions, counts their
transistors and keeps each player's best; the board shows a histogram
and your place. A generated puzzle of the week for everyone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:54:57 +00:00
|
|
|
// Campaign: a project where parts are earned. It starts with NAND, inputs,
|
|
|
|
|
// outputs and lamps. Each challenge opens once the ones it builds on are
|
|
|
|
|
// solved, and your own solution becomes the part you use from then on.
|
|
|
|
|
// Basic parts like the clock unlock on the way. Sandbox projects have
|
|
|
|
|
// everything from the start.
|
|
|
|
|
|
|
|
|
|
import { CHALLENGES } from './challenges'
|
|
|
|
|
import type { ComponentDef, NodeKind, Project } from './types'
|
|
|
|
|
|
|
|
|
|
/** Display names of the basic parts. */
|
|
|
|
|
export const KIND_NAMES: Partial<Record<NodeKind, string>> = {
|
|
|
|
|
nand: 'NAND gate',
|
|
|
|
|
input: 'Input switch',
|
|
|
|
|
output: 'Output pin',
|
|
|
|
|
lamp: 'Lamp',
|
|
|
|
|
button: 'Push button',
|
|
|
|
|
clock: 'Clock',
|
|
|
|
|
high: 'Constant 1',
|
|
|
|
|
low: 'Ground (0)',
|
|
|
|
|
hex: 'Hex display',
|
|
|
|
|
note: 'Note',
|
|
|
|
|
panel: 'Input panel',
|
2026-10-21 12:38:59 +00:00
|
|
|
outpanel: 'Output panel',
|
A campaign with unlocks, synthesised sound, puzzles and the puzzle of the week
- Campaign projects start with NAND only; challenges open along a
dependency chain, each solution becomes a usable part, and basic parts
unlock on the way. Locked parts and challenges say what opens them.
- Sound effects made with Web Audio: place, connect, switches, buttons,
delete, clock ticks (opt-in), solve, fail, unlock, record. Mute and
volume in the top bar and Display settings.
- Publish any circuit as a puzzle link; only its behaviour is shared.
The server re-runs the checks on submitted solutions, counts their
transistors and keeps each player's best; the board shows a histogram
and your place. A generated puzzle of the week for everyone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:54:57 +00:00
|
|
|
bundle: 'Cable bundle',
|
|
|
|
|
split: 'Cable split',
|
|
|
|
|
pixel: 'Pixel',
|
2026-10-22 16:59:56 +00:00
|
|
|
portin: 'Connector in',
|
|
|
|
|
portout: 'Connector out',
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
tag: 'Send signal',
|
|
|
|
|
ref: 'Use signal',
|
2026-10-28 12:05:57 +00:00
|
|
|
terminal: 'Terminal',
|
|
|
|
|
keyboard: 'Keyboard',
|
2026-10-28 12:12:43 +00:00
|
|
|
bench: 'Test bench',
|
2026-10-28 12:35:04 +00:00
|
|
|
scope: 'Logic analyzer',
|
A campaign with unlocks, synthesised sound, puzzles and the puzzle of the week
- Campaign projects start with NAND only; challenges open along a
dependency chain, each solution becomes a usable part, and basic parts
unlock on the way. Locked parts and challenges say what opens them.
- Sound effects made with Web Audio: place, connect, switches, buttons,
delete, clock ticks (opt-in), solve, fail, unlock, record. Mute and
volume in the top bar and Display settings.
- Publish any circuit as a puzzle link; only its behaviour is shared.
The server re-runs the checks on submitted solutions, counts their
transistors and keeps each player's best; the board shows a histogram
and your place. A generated puzzle of the week for everyone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Challenges each one builds on. */
|
|
|
|
|
export const NEEDS: Record<string, string[]> = {
|
|
|
|
|
not: [],
|
|
|
|
|
and: ['not'],
|
|
|
|
|
or: ['not'],
|
|
|
|
|
nor: ['or'],
|
|
|
|
|
xor: ['and'],
|
|
|
|
|
xnor: ['xor'],
|
|
|
|
|
and3: ['and'],
|
|
|
|
|
mux: ['and', 'or'],
|
|
|
|
|
demux: ['and'],
|
|
|
|
|
dec2: ['and'],
|
|
|
|
|
ha: ['xor'],
|
|
|
|
|
fa: ['ha', 'or'],
|
|
|
|
|
eq2: ['xnor'],
|
|
|
|
|
add2: ['fa'],
|
|
|
|
|
sr: ['not'],
|
|
|
|
|
dlatch: ['sr'],
|
|
|
|
|
dff: ['dlatch'],
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Basic parts that have to be earned, and the challenge that earns each. */
|
|
|
|
|
export const KIND_UNLOCK: Partial<Record<NodeKind, string>> = {
|
|
|
|
|
high: 'not',
|
|
|
|
|
low: 'not',
|
|
|
|
|
panel: 'and',
|
2026-10-21 12:38:59 +00:00
|
|
|
outpanel: 'and',
|
A campaign with unlocks, synthesised sound, puzzles and the puzzle of the week
- Campaign projects start with NAND only; challenges open along a
dependency chain, each solution becomes a usable part, and basic parts
unlock on the way. Locked parts and challenges say what opens them.
- Sound effects made with Web Audio: place, connect, switches, buttons,
delete, clock ticks (opt-in), solve, fail, unlock, record. Mute and
volume in the top bar and Display settings.
- Publish any circuit as a puzzle link; only its behaviour is shared.
The server re-runs the checks on submitted solutions, counts their
transistors and keeps each player's best; the board shows a histogram
and your place. A generated puzzle of the week for everyone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:54:57 +00:00
|
|
|
hex: 'dec2',
|
|
|
|
|
pixel: 'dec2',
|
2026-10-28 12:05:57 +00:00
|
|
|
terminal: 'dec2',
|
|
|
|
|
keyboard: 'dec2',
|
A campaign with unlocks, synthesised sound, puzzles and the puzzle of the week
- Campaign projects start with NAND only; challenges open along a
dependency chain, each solution becomes a usable part, and basic parts
unlock on the way. Locked parts and challenges say what opens them.
- Sound effects made with Web Audio: place, connect, switches, buttons,
delete, clock ticks (opt-in), solve, fail, unlock, record. Mute and
volume in the top bar and Display settings.
- Publish any circuit as a puzzle link; only its behaviour is shared.
The server re-runs the checks on submitted solutions, counts their
transistors and keeps each player's best; the board shows a histogram
and your place. A generated puzzle of the week for everyone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:54:57 +00:00
|
|
|
bundle: 'add2',
|
|
|
|
|
split: 'add2',
|
2026-10-22 16:59:56 +00:00
|
|
|
portin: 'add2',
|
|
|
|
|
portout: 'add2',
|
A campaign with unlocks, synthesised sound, puzzles and the puzzle of the week
- Campaign projects start with NAND only; challenges open along a
dependency chain, each solution becomes a usable part, and basic parts
unlock on the way. Locked parts and challenges say what opens them.
- Sound effects made with Web Audio: place, connect, switches, buttons,
delete, clock ticks (opt-in), solve, fail, unlock, record. Mute and
volume in the top bar and Display settings.
- Publish any circuit as a puzzle link; only its behaviour is shared.
The server re-runs the checks on submitted solutions, counts their
transistors and keeps each player's best; the board shows a histogram
and your place. A generated puzzle of the week for everyone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:54:57 +00:00
|
|
|
button: 'sr',
|
|
|
|
|
clock: 'dlatch',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const isCampaign = (p: Project) => p.mode === 'campaign'
|
|
|
|
|
|
|
|
|
|
const solved = (p: Project, id: string) => p.solved.includes(id)
|
|
|
|
|
|
|
|
|
|
export function kindUnlocked(p: Project, kind: NodeKind): boolean {
|
|
|
|
|
const by = KIND_UNLOCK[kind]
|
|
|
|
|
return !isCampaign(p) || !by || solved(p, by)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A challenge can be started once everything it builds on is solved. */
|
|
|
|
|
export function challengeOpen(p: Project, id: string): boolean {
|
|
|
|
|
return !isCampaign(p) || (NEEDS[id] ?? []).every(n => solved(p, n))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** In a campaign, a challenge's component becomes usable as a part once it is solved. */
|
|
|
|
|
export function defUsable(p: Project, def: ComponentDef): boolean {
|
|
|
|
|
return !isCampaign(p) || !def.challenge || solved(p, def.challenge)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const challengeName = (id: string) => CHALLENGES.find(c => c.id === id)?.name ?? id
|
|
|
|
|
|
|
|
|
|
/** What solving a challenge opens up: further challenges and basic parts. */
|
|
|
|
|
export function unlockedBy(p: Project, id: string): { challenges: string[]; kinds: NodeKind[] } {
|
|
|
|
|
const after = { ...p, solved: [...new Set([...p.solved, id])] }
|
|
|
|
|
const challenges = CHALLENGES.filter(c => !solved(p, c.id) && c.id !== id && !challengeOpen(p, c.id) && challengeOpen(after, c.id)).map(c => c.id)
|
|
|
|
|
const kinds = (Object.keys(KIND_UNLOCK) as NodeKind[]).filter(k => KIND_UNLOCK[k] === id && !solved(p, id))
|
|
|
|
|
return { challenges, kinds }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Share of the campaign done, 0 to 1. */
|
|
|
|
|
export function campaignProgress(p: Project): number {
|
|
|
|
|
return CHALLENGES.filter(c => solved(p, c.id)).length / CHALLENGES.length
|
|
|
|
|
}
|