← Blog

How We Built the Jelmata AI

How We Built the Jelmata AI

1

Why not minimax?

The obvious first idea for a two-player board game is minimax with alpha-beta pruning — search a few moves ahead, score each leaf, back up the best. That works great for chess and checkers. It doesn't work nearly as well for Jelmata.

Jelmata's score is the product of your connected component sizes, which makes every placement a non-local decision. One cell can merge two groups and drop your score. The branching factor is wide — on an empty 6×6 board, every legal square is a candidate. Combine that with the fact that the game has to run smoothly on a five-year-old Android phone with no GPU, and deep search stops being the right tool.

So instead of searching, Jelmata's AI evaluates. It looks at every legal move, scores each one directly, and picks the winner. No tree, no lookahead, no recursion. One pass and it's done, in well under a millisecond on any phone.

2

Four difficulties, four personalities

The four in-game difficulty levels aren't the same AI with a knob turned up. They're genuinely different approaches, each picked for what it does well.

  • EasyRandom, by design

    Easy plays a uniformly random legal move. No features, no weights, no preferences — every open square is equally likely. The point isn't to be a good opponent; it's to be the opponent you beat on your first try, so you can start developing your own strategy without getting crushed.

  • MediumLoose on purpose

    Medium looks at the same things Hard does, but makes its mind up loosely. It often picks the second- or third-best move, so a player who's just found their footing against Easy has a fair shot at winning.

  • HardA sharp, beatable strategy

    Hard plays a single clear strategy: never grow a group above 3. Because Jelmata's score is a product of component sizes, merging two groups of 3 into one group of 6 actually cuts your score — and Hard refuses to do that to itself. Greedy and deterministic: same move every time for a given board, with a clear counter-strategy that skilled players can discover.

  • EliteThe apex opponent

    Elite is a small neural network that lives inside the app bundle. It was trained to imitate a much stronger search-based teacher, and it inherits most of that strength in a package small enough to ship. On web builds, where native neural-network runtimes aren't available, Elite quietly falls back to a hand-tuned scorer that's still sharp enough to challenge serious players.

3

Making a millisecond feel like a thought

Here's an uncomfortable truth about fast AIs: Jelmata picks its move in well under a millisecond. If we played it immediately, every turn would feel like the opponent is slapping the board, which is both unpleasant and makes the AI feel dumber than it is.

The fix is a small timing layer. When one move is clearly best, the AI plays quickly — as if it's seen something obvious. When several moves look roughly equal, it takes a little longer to “decide.” The AI isn't actually thinking harder in the close cases — the work is always the same — but the pacing tells a story that matches the position. Players report Elite considers hard moves and pounces on easy ones. Both things are true of the pacing, not the model. It turns out that detail changes how strong the AI feels by more than you'd think.

4

What we deliberately left out

There's a lot of classical game-AI machinery we chose not to build:

  • No opening book

    Jelmata's first few moves are symmetric enough that a book would only save a few microseconds and would just be another thing to maintain.

  • No endgame tablebase

    The state space is too large to enumerate and too small to matter — the evaluator is already nearly perfect when only a handful of empty squares remain.

  • No lookahead

    Not even a single-ply response. Every evaluation is purely static. This is the biggest surprise for people who assume game AI has to search.

  • No online learning

    The app never updates weights from your games. Everything ships as a frozen artifact, which makes behavior reproducible and keeps your data on your device.

Try to beat it

The best way to understand any game AI is to play against it. Start on Medium for a loose opponent, then climb to Hard and try to find the counter to its “never-merge” strategy — Hard plays the same game every time, so once you find the line that beats it, you own the tier. Then try Elite on your phone and see how much better a small neural network plays when it's learned from a much stronger teacher.