Skip to main content

Examples

Checkers

Constraint-driven game logic with multi-module composition, AI integration, and time-travel debugging.

Play it

Loading example…

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.

  1. Facts – Board state, current player, selection, game mode
  2. Derivations – Valid moves, highlight squares, score (auto-tracked, no manual deps)
  3. Events clickSquare sets selection and target
  4. Constraints executeMove fires when a valid selection+target exists, kingPiece when on back row, gameOver when no moves remain
  5. Resolvers – Apply the move, handle multi-jump chains, switch turns
  6. 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

Stay in the loop. Sign up for our newsletter.

We care about your data. We'll never share your email.

Powered by Directive. This signup uses a Directive module with facts, derivations, constraints, and resolvers – zero useState, zero useEffect. Read how it works