← Portfolio
Live in your browser

The differential oracle

The hard part of testing game logic isn't writing tests — it's knowing whether your tests would notice if the logic broke. This is the answer I use: write the logic twice, independently, and make the two halves agree. Neither knows the rules; each only knows it must match the other. A second net — an invariant checker — judges the result directly. Everything below is this repo's real Python, running in your browser.

Booting…
// Part 1

Break it yourself

Click cells to change colours (0 = empty). Match-3 rules: a run of 3+ clears; a run of 4+ also earns one special gem. Both nets re-run on every click.

click a cell to cycle its colour
Tick that box to swap in the deliberately-wrong implementation — it awards a special for runs of 3+ when the rule is 4+. Watch both nets light up independently. A safety net that can't catch a known bug isn't a safety net.
// Part 2 — the claim, runnable

Thousands of random boards

My portfolio says the oracle runs both implementations over thousands of random boards and they never disagree. Don't take my word for it — run it here, then run it again against the buggy implementation and watch the disagreements pile up.

Why two different nets? They fail differently. The differential oracle catches anything where the implementations diverge — including bugs nobody thought to write a rule for — but it's blind to a mistake made identically in both. The invariant checker can't be fooled that way, because it never consults an implementation at all; it only knows the rules. Neither is sufficient. Together they cover each other's blind spot.