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
|
|
|
// Submit a solution. The server runs the puzzle's checks on it and counts
|
|
|
|
|
// its transistors itself, so a score can't be made up. Each player keeps
|
|
|
|
|
// their best: fewer transistors, then shorter delay.
|
|
|
|
|
import { toProject } from '../../../../app/lib/logic/project'
|
|
|
|
|
import { scoreSolution } from '../../../../app/lib/logic/puzzles'
|
|
|
|
|
|
|
|
|
|
export default defineEventHandler(async event => {
|
|
|
|
|
rateLimit(event, 'score', 60, 10 * 60_000)
|
|
|
|
|
const id = getRouterParam(event, 'id')
|
|
|
|
|
const spec = await findPuzzle(id)
|
|
|
|
|
if (!spec || !id) throw createError({ statusCode: 404, message: 'Puzzle not found' })
|
|
|
|
|
const raw = await readRawBody(event, 'utf8')
|
|
|
|
|
if (!raw) throw createError({ statusCode: 400, message: 'Empty request' })
|
|
|
|
|
if (raw.length > 2_000_000) throw createError({ statusCode: 413, message: 'Solution too large' })
|
|
|
|
|
let body: { player?: unknown; defId?: unknown; components?: unknown }
|
|
|
|
|
try {
|
|
|
|
|
body = JSON.parse(raw)
|
|
|
|
|
} catch {
|
|
|
|
|
throw createError({ statusCode: 400, message: 'Not valid JSON' })
|
|
|
|
|
}
|
|
|
|
|
if (!isPlayer(body.player) || typeof body.defId !== 'string') throw createError({ statusCode: 400, message: 'Missing player or circuit' })
|
|
|
|
|
let components
|
|
|
|
|
try {
|
|
|
|
|
components = toProject({ components: body.components, name: 'solution' }).components
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw createError({ statusCode: 400, message: (e as Error).message })
|
|
|
|
|
}
|
|
|
|
|
const score = scoreSolution(components, body.defId, spec)
|
A main menu: free play, campaign, challenges and leaderboard over a circuit that builds itself
Logigate opens on a title screen. Continue, Free play (your own projects),
Campaign (progress and what is next), Challenges (every challenge and the
puzzle of the week in one Challenges project), Leaderboard (the best ten of
this and earlier weeks, your place, your records), Settings. Arrow keys,
Enter and Esc work through it; links still open straight into the editor.
Players can name themselves on the leaderboards. The logo in the editor
leads back to the menu.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 10:22:35 +00:00
|
|
|
if (!score.pass) return { score, summary: summarize(await board(id), body.player, await playerNames()) }
|
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
|
|
|
const player = body.player
|
|
|
|
|
const summary = await locked(id, async () => {
|
|
|
|
|
const scores = await board(id)
|
|
|
|
|
const old = scores[player]
|
|
|
|
|
const better = !old || score.transistors < old.t || (score.transistors === old.t && (score.delay ?? Infinity) < (old.d ?? Infinity))
|
|
|
|
|
if (better) {
|
|
|
|
|
scores[player] = { t: score.transistors, d: score.delay, at: Date.now() }
|
|
|
|
|
await puzzleStorage().setItem(`scores:${id}`, scores)
|
|
|
|
|
}
|
A main menu: free play, campaign, challenges and leaderboard over a circuit that builds itself
Logigate opens on a title screen. Continue, Free play (your own projects),
Campaign (progress and what is next), Challenges (every challenge and the
puzzle of the week in one Challenges project), Leaderboard (the best ten of
this and earlier weeks, your place, your records), Settings. Arrow keys,
Enter and Esc work through it; links still open straight into the editor.
Players can name themselves on the leaderboards. The logo in the editor
leads back to the menu.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 10:22:35 +00:00
|
|
|
return summarize(scores, player, await playerNames())
|
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
|
|
|
})
|
|
|
|
|
return { score, summary }
|
|
|
|
|
})
|