A right panel in tabs, Pins list, bulk editing, transistor breakdown, Settings dialog
- Right panel tabs: Selection, Circuit, Pins, Test. Display and sound
preferences move to a Settings dialog (gear in the top bar).
- Pins tab: every input and output in pin order with live values; rename in
place (Enter goes to the next), number a whole side from a pattern, flag
duplicate names, centre the canvas on a part.
- Several selected parts: narrow by type, swap all, rename all from a
pattern, set switches to 0/1 or flip, shared colour/frequency/size, align
and spread.
- Transistors on every part (NAND 4, switches and lamps 0), NAND 4T in the
palette, and a per-part breakdown of the circuit. Test: the count equals
4 x the gates the simulator builds, for every example and wide gate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 07:29:55 +00:00
|
|
|
<script setup lang="ts">
|
R Panels: This and Pins on the left, the selection on the right
The left panel is about the circuit you are in: This (challenge and
Check on top, problems, name, statistics, truth table, as a component,
transistors, tools) and Pins. The selection gets its own panel on the
right, there only while something is selected, with its settings and
actions such as making a component out of it. The bars follow the
canvas width and drop labels when it gets narrow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:38:17 +00:00
|
|
|
// The challenge or puzzle being built (part "task", at the top of This) and the
|
|
|
|
|
// truth table of the open circuit (part "table", folded further down).
|
A right panel in tabs, Pins list, bulk editing, transistor breakdown, Settings dialog
- Right panel tabs: Selection, Circuit, Pins, Test. Display and sound
preferences move to a Settings dialog (gear in the top bar).
- Pins tab: every input and output in pin order with live values; rename in
place (Enter goes to the next), number a whole side from a pattern, flag
duplicate names, centre the canvas on a part.
- Several selected parts: narrow by type, swap all, rename all from a
pattern, set switches to 0/1 or flip, shared colour/frequency/size, align
and spread.
- Transistors on every part (NAND 4, switches and lamps 0), NAND 4T in the
palette, and a per-part breakdown of the circuit. Test: the count equals
4 x the gates the simulator builds, for every example and wide gate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 07:29:55 +00:00
|
|
|
import type { ChallengeCheck } from '~/composables/useEditor'
|
|
|
|
|
import { tableMarkdown, type TruthTable } from '~/lib/logic/analyze'
|
|
|
|
|
import { apiId, isTable } from '~/lib/logic/puzzles'
|
|
|
|
|
|
R Panels: This and Pins on the left, the selection on the right
The left panel is about the circuit you are in: This (challenge and
Check on top, problems, name, statistics, truth table, as a component,
transistors, tools) and Pins. The selection gets its own panel on the
right, there only while something is selected, with its settings and
actions such as making a component out of it. The bars follow the
canvas width and drop labels when it gets narrow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:38:17 +00:00
|
|
|
const props = defineProps<{ part: 'task' | 'table' }>()
|
A right panel in tabs, Pins list, bulk editing, transistor breakdown, Settings dialog
- Right panel tabs: Selection, Circuit, Pins, Test. Display and sound
preferences move to a Settings dialog (gear in the top bar).
- Pins tab: every input and output in pin order with live values; rename in
place (Enter goes to the next), number a whole side from a pattern, flag
duplicate names, centre the canvas on a part.
- Several selected parts: narrow by type, swap all, rename all from a
pattern, set switches to 0/1 or flip, shared colour/frequency/size, align
and spread.
- Transistors on every part (NAND 4, switches and lamps 0), NAND 4T in the
palette, and a per-part breakdown of the circuit. Test: the count equals
4 x the gates the simulator builds, for every example and wide gate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 07:29:55 +00:00
|
|
|
const ed = useEditor()
|
|
|
|
|
const def = ed.def
|
|
|
|
|
|
|
|
|
|
// The challenge or puzzle this circuit is for.
|
|
|
|
|
const challenge = computed(() => {
|
|
|
|
|
const t = ed.task.value
|
|
|
|
|
const c = t?.challenge ?? t?.puzzle
|
|
|
|
|
return t && c ? { id: t.id, name: c.name, goal: c.goal, inputs: c.inputs, outputs: c.outputs, puzzle: t.puzzle } : undefined
|
|
|
|
|
})
|
|
|
|
|
const solved = computed(() => !!challenge.value && ed.project.value.solved.includes(challenge.value.id))
|
|
|
|
|
const board = computed(() => (challenge.value?.puzzle ? ed.boards[challenge.value.id] : undefined))
|
|
|
|
|
// What the puzzle asks for, as a table to read.
|
|
|
|
|
const target = computed<TruthTable | null>(() => {
|
|
|
|
|
const p = challenge.value?.puzzle
|
|
|
|
|
if (!p) return null
|
|
|
|
|
return { inputs: p.inputs, outputs: p.outputs, rows: p.steps.map(s => ({ ins: p.inputs.map(l => s.set[l] ?? 0), outs: p.outputs.map(l => s.expect[l] ?? 0), settled: true })) }
|
|
|
|
|
})
|
|
|
|
|
watch(
|
|
|
|
|
() => challenge.value?.puzzle,
|
|
|
|
|
p => {
|
|
|
|
|
if (p && !ed.boards[p.id]) void ed.loadBoard(p)
|
|
|
|
|
},
|
|
|
|
|
{ immediate: true },
|
|
|
|
|
)
|
|
|
|
|
const showTarget = ref(true)
|
|
|
|
|
const puzzleLink = computed(() => (challenge.value?.puzzle ? `${location.origin}/puzzle/${apiId(challenge.value.puzzle.id)}` : ''))
|
|
|
|
|
|
|
|
|
|
const table = ref<TruthTable | { error: string } | null>(null)
|
R Panels: This and Pins on the left, the selection on the right
The left panel is about the circuit you are in: This (challenge and
Check on top, problems, name, statistics, truth table, as a component,
transistors, tools) and Pins. The selection gets its own panel on the
right, there only while something is selected, with its settings and
actions such as making a component out of it. The bars follow the
canvas width and drop labels when it gets narrow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:38:17 +00:00
|
|
|
watch([() => ed.sim.value, () => def.value.id], () => (table.value = props.part === 'table' ? ed.table() : null), { immediate: true })
|
A right panel in tabs, Pins list, bulk editing, transistor breakdown, Settings dialog
- Right panel tabs: Selection, Circuit, Pins, Test. Display and sound
preferences move to a Settings dialog (gear in the top bar).
- Pins tab: every input and output in pin order with live values; rename in
place (Enter goes to the next), number a whole side from a pattern, flag
duplicate names, centre the canvas on a part.
- Several selected parts: narrow by type, swap all, rename all from a
pattern, set switches to 0/1 or flip, shared colour/frequency/size, align
and spread.
- Transistors on every part (NAND 4, switches and lamps 0), NAND 4T in the
palette, and a per-part breakdown of the circuit. Test: the count equals
4 x the gates the simulator builds, for every example and wide gate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 07:29:55 +00:00
|
|
|
|
|
|
|
|
const check = ref<ChallengeCheck | null>(null)
|
|
|
|
|
const bestHere = computed(() => (challenge.value ? ed.project.value.best?.[challenge.value.id] : undefined))
|
|
|
|
|
watch(() => def.value.id, () => (check.value = null))
|
|
|
|
|
watch(() => ed.sim.value, () => (check.value = null))
|
|
|
|
|
function runCheck() {
|
|
|
|
|
check.value = ed.checkChallenge()
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
R Panels: This and Pins on the left, the selection on the right
The left panel is about the circuit you are in: This (challenge and
Check on top, problems, name, statistics, truth table, as a component,
transistors, tools) and Pins. The selection gets its own panel on the
right, there only while something is selected, with its settings and
actions such as making a component out of it. The bars follow the
canvas width and drop labels when it gets narrow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:38:17 +00:00
|
|
|
<section v-if="props.part === 'task' && challenge" class="challenge" :class="{ solved }">
|
A right panel in tabs, Pins list, bulk editing, transistor breakdown, Settings dialog
- Right panel tabs: Selection, Circuit, Pins, Test. Display and sound
preferences move to a Settings dialog (gear in the top bar).
- Pins tab: every input and output in pin order with live values; rename in
place (Enter goes to the next), number a whole side from a pattern, flag
duplicate names, centre the canvas on a part.
- Several selected parts: narrow by type, swap all, rename all from a
pattern, set switches to 0/1 or flip, shared colour/frequency/size, align
and spread.
- Transistors on every part (NAND 4, switches and lamps 0), NAND 4T in the
palette, and a per-part breakdown of the circuit. Test: the count equals
4 x the gates the simulator builds, for every example and wide gate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 07:29:55 +00:00
|
|
|
<h3>
|
|
|
|
|
<Icon :name="solved ? 'lucide:badge-check' : 'lucide:flag'" class="size-4" />
|
|
|
|
|
{{ challenge.puzzle ? 'Puzzle' : 'Challenge' }}: {{ challenge.name }}
|
|
|
|
|
</h3>
|
|
|
|
|
<p>{{ challenge.goal }}</p>
|
|
|
|
|
<p class="pins">Pins: {{ challenge.inputs.join(', ') }} → {{ challenge.outputs.join(', ') }}</p>
|
|
|
|
|
<template v-if="target">
|
|
|
|
|
<button class="section-toggle mt-2" @click="showTarget = !showTarget">
|
|
|
|
|
<Icon :name="showTarget ? 'lucide:chevron-down' : 'lucide:chevron-right'" class="size-4" />
|
|
|
|
|
{{ isTable(challenge.puzzle!) ? 'Target truth table' : `Target: ${target.rows.length} steps from power-on` }}
|
|
|
|
|
</button>
|
|
|
|
|
<div v-if="showTarget" class="target-table">
|
|
|
|
|
<EditorTruthTable :table="target" />
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<button class="btn btn-primary w-full" @click="runCheck"><Icon name="lucide:play" class="size-4" /> Check</button>
|
|
|
|
|
<p v-if="check" class="result" :class="check.pass ? 'pass' : 'fail'">
|
|
|
|
|
<Icon :name="check.pass ? 'lucide:circle-check' : 'lucide:circle-x'" class="size-4 shrink-0" />
|
|
|
|
|
{{ check.message }}
|
|
|
|
|
</p>
|
|
|
|
|
<p class="score">
|
|
|
|
|
<Icon name="lucide:cpu" class="size-4 shrink-0" />
|
|
|
|
|
<span>
|
|
|
|
|
{{ ed.transistors(def.id).toLocaleString() }} transistors now<template v-if="bestHere !== undefined">, best <strong>{{ bestHere.toLocaleString() }}</strong></template>
|
|
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p v-if="check?.pass && check.record !== undefined" class="result pass">
|
|
|
|
|
<Icon name="lucide:trophy" class="size-4 shrink-0" /> New record! {{ check.record - check.transistors }} fewer than before ({{ check.record }}).
|
|
|
|
|
</p>
|
|
|
|
|
<p v-else-if="check?.pass && check.best === check.transistors" class="hint">Fewer transistors is better: 4 per NAND gate. Can you make it smaller?</p>
|
|
|
|
|
<div v-if="check?.pass && (check.unlocked?.length || check.nextUp?.length)" class="unlock">
|
|
|
|
|
<Icon name="lucide:sparkles" class="size-4 shrink-0" />
|
|
|
|
|
<div>
|
|
|
|
|
<p v-if="check.unlocked?.length"><strong>Unlocked:</strong> {{ check.unlocked.join(', ') }}</p>
|
|
|
|
|
<p v-if="check.nextUp?.length"><strong>New challenges:</strong> {{ check.nextUp.join(', ') }}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<template v-if="challenge.puzzle">
|
|
|
|
|
<p v-if="challenge.puzzle.author !== undefined" class="hint mt-2">The author's solution uses {{ challenge.puzzle.author.toLocaleString() }} transistors.</p>
|
|
|
|
|
<EditorScoreChart v-if="board?.players" :summary="board" :mine="bestHere" />
|
|
|
|
|
<p v-else class="hint mt-2">No one has solved it yet. Be the first.</p>
|
|
|
|
|
<button class="btn btn-ghost mt-2 w-full" title="Copy the link to this puzzle" @click="ed.copyText(puzzleLink, 'Puzzle link copied')">
|
|
|
|
|
<Icon name="lucide:link" class="size-4" /> Copy puzzle link
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
</section>
|
|
|
|
|
|
R Panels: This and Pins on the left, the selection on the right
The left panel is about the circuit you are in: This (challenge and
Check on top, problems, name, statistics, truth table, as a component,
transistors, tools) and Pins. The selection gets its own panel on the
right, there only while something is selected, with its settings and
actions such as making a component out of it. The bars follow the
canvas width and drop labels when it gets narrow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:38:17 +00:00
|
|
|
<div v-if="props.part === 'table'" class="table-pane">
|
|
|
|
|
<div class="flex items-center justify-end gap-1">
|
A right panel in tabs, Pins list, bulk editing, transistor breakdown, Settings dialog
- Right panel tabs: Selection, Circuit, Pins, Test. Display and sound
preferences move to a Settings dialog (gear in the top bar).
- Pins tab: every input and output in pin order with live values; rename in
place (Enter goes to the next), number a whole side from a pattern, flag
duplicate names, centre the canvas on a part.
- Several selected parts: narrow by type, swap all, rename all from a
pattern, set switches to 0/1 or flip, shared colour/frequency/size, align
and spread.
- Transistors on every part (NAND 4, switches and lamps 0), NAND 4T in the
palette, and a per-part breakdown of the circuit. Test: the count equals
4 x the gates the simulator builds, for every example and wide gate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 07:29:55 +00:00
|
|
|
<template v-if="table && !('error' in table)">
|
|
|
|
|
<button class="icon-btn" title="Download as CSV" @click="ed.exportTable(table)"><Icon name="lucide:download" class="size-3.5" /></button>
|
|
|
|
|
<button class="icon-btn" title="Copy as a Markdown table" @click="ed.copyText(tableMarkdown(table), 'Truth table copied')">
|
|
|
|
|
<Icon name="lucide:clipboard-copy" class="size-3.5" />
|
|
|
|
|
</button>
|
|
|
|
|
</template>
|
|
|
|
|
<button class="icon-btn" title="Full screen" @click="ed.dialog.value = 'table'"><Icon name="lucide:maximize-2" class="size-3.5" /></button>
|
|
|
|
|
</div>
|
|
|
|
|
<template v-if="table">
|
|
|
|
|
<p v-if="'error' in table" class="hint">{{ table.error }}</p>
|
|
|
|
|
<template v-else>
|
|
|
|
|
<p v-if="ed.circuitStats.value.sequential" class="hint">This circuit stores state, so the table depends on the order the rows are tried in.</p>
|
|
|
|
|
<EditorTruthTable :table="table" />
|
|
|
|
|
</template>
|
|
|
|
|
</template>
|
R Panels: This and Pins on the left, the selection on the right
The left panel is about the circuit you are in: This (challenge and
Check on top, problems, name, statistics, truth table, as a component,
transistors, tools) and Pins. The selection gets its own panel on the
right, there only while something is selected, with its settings and
actions such as making a component out of it. The bars follow the
canvas width and drop labels when it gets narrow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:38:17 +00:00
|
|
|
</div>
|
A right panel in tabs, Pins list, bulk editing, transistor breakdown, Settings dialog
- Right panel tabs: Selection, Circuit, Pins, Test. Display and sound
preferences move to a Settings dialog (gear in the top bar).
- Pins tab: every input and output in pin order with live values; rename in
place (Enter goes to the next), number a whole side from a pattern, flag
duplicate names, centre the canvas on a part.
- Several selected parts: narrow by type, swap all, rename all from a
pattern, set switches to 0/1 or flip, shared colour/frequency/size, align
and spread.
- Transistors on every part (NAND 4, switches and lamps 0), NAND 4T in the
palette, and a per-part breakdown of the circuit. Test: the count equals
4 x the gates the simulator builds, for every example and wide gate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 07:29:55 +00:00
|
|
|
</template>
|