Examples
Sudoku
Constraint satisfaction, powered by Directive. The game rules ARE the constraints.
Play it
Use arrow keys to navigate, 1–9 to input, Backspace to clear, N for notes, H for hint. Ctrl+Z / Ctrl+Shift+Z for undo/redo.
How it works
Sudoku is literally a constraint satisfaction problem: no duplicates in rows, columns, or 3×3 boxes. The game rules map 1:1 to Directive’s constraint–resolver flow.
- Facts – Grid state, solution, givens, timer, selection, notes, difficulty
- Derivations – Conflicts, progress, timer display, same-number highlighting, candidates (auto-tracked, no manual deps)
- Events –
selectCell,inputNumber,toggleNote,requestHint,tick,newGame - Constraints –
timerExpired(priority 200),detectConflict(100),puzzleSolved(90),hintAvailable(70) – evaluated by priority after every fact change - Resolvers – Handle game won/lost, increment error count, reveal hints
- Effects – Timer warnings at 60s and 30s, game result logging
The constraint cascade is the key insight: when a player types “5”, the grid fact updates, derivations recompute (conflicts, progress, isSolved), then constraints evaluate by priority – detecting conflicts, checking for a win, or firing a hint.
Summary
What: A fully playable Sudoku puzzle with multiple difficulties, notes, hints, undo/redo, and a countdown timer.
How: The game is a single Directive module with 14 facts tracking grid/selection/timer state. Derivations auto-compute conflicts, progress, and candidates. Four prioritized constraints cascade on every input to detect conflicts, check for a win, expire the timer, or reveal hints. Resolvers handle the outcomes. Effects fire timer warnings.
Why it works: Sudoku is a constraint satisfaction problem – Directive’s constraint–resolver flow maps 1:1 to the game rules. No imperative state machine needed; declare what must be true and Directive handles the rest.
Source code
// Source file "sudoku.ts" not found

