Examples
Checkers
Constraint-driven game logic with multi-module composition, AI integration, and time-travel debugging.
Play it
2-player and vs Computer modes work in the embed. The vs Claude mode requires an API key and dev server proxy.
How it works
The game is built as a multi-module Directive system with two modules: game (board logic) and chat (AI conversation). Pure game rules live in a separate rules.ts file with no Directive dependency.
- Facts – Board state, current player, selection, game mode
- Derivations – Valid moves, highlight squares, score (auto-tracked, no manual deps)
- Events –
clickSquaresets selection and target - Constraints –
executeMovefires when a valid selection+target exists,kingPiecewhen on back row,gameOverwhen no moves remain - Resolvers – Apply the move, handle multi-jump chains, switch turns
- Effects – Log moves and game results
Summary
What: A two-player checkers game with optional AI opponent, multi-jump chains, king promotion, and move validation.
How: Built as a multi-module Directive system. The game module tracks board state, selection, and turns. Derivations compute valid moves and highlights. Constraints fire when a valid move is selected, a piece reaches the back row, or no moves remain. Pure game rules live in rules.ts with no Directive dependency.
Why it works: Checkers has complex cascading logic (move → capture → multi-jump → king → game over). Directive’s constraint priorities handle the cascade automatically – the executeMove constraint fires first, then kingPiece, then gameOver, each reacting to the state the previous one left behind.
Source code
// Source file "game.ts" not found

