← All projects

Crib

Cribbage hand analyzer

Why I built it

Everyone who has played cribbage has wondered, "Did I make the right call on which cards to throw in the crib?" I wanted a tool that shows every stat for every possible combination, so I could measure my instincts with numbers and see whether they hold up.

What it does

Score Six is the part that matters. Enter the six cards you were dealt, and it ranks all 15 ways to keep four and discard two by average score. Score Four is the simpler building block: for a single four-card hand, it breaks down how the hand scores across every possible cut, with the average, min, median, max, most likely score, standard deviation, and which cuts give each score. Score Six runs that same breakdown on every option. The cards you pick are kept in the URL, so any hand can be linked directly.

Behind it is a Go cribbage engine with pluggable AI strategies for discarding and pegging. A simulator plays every combination of strategies against each other over thousands of games and ranks them by win rate and points, and a local web game lets me play against the best one so far. Those run locally for now and aren't part of the live site.

How it's built

Code
The analyzer is plain HTML and JavaScript with no build step, and scores every hand in the browser. The engine, strategies and simulator are Go, with the simulator running each matchup in its own goroutine. The best discard strategy leans on precomputed stats for all 270,725 four-card hands and the average crib value of every two-card discard.
Testing
The site's JavaScript scoring re-implements the Go scoring, so a parity check compares the two on every four-card hand plus thousands of discards, and fails on any difference.
Hosting
GitHub Pages, at mattlove.dev/crib. There's no server or database behind the analyzer.
Deploying
GitHub Actions runs go vet and the parity check on every push to main that touches the site or the scoring code, and only publishes the site if both pass.