Lab / Catan AI
Catan AI
Play the four-player board game Catan against three of my computer players. My C++ engine for the game and its built-in players are compiled to WebAssembly and run only in this browser tab. You always take the first seat: you place first and you move first.
Your opponents
You always take the first seat, shown as You: you place first and move first. Seats 1 to 3 are the engine’s own players; choose each one. A change applies from the next new game.
The hand-written rules: best production spots, cities before settlements before roads, trades towards the cheapest goal.
Every legal move and the best two follow-ups in the same turn, on 8 re-deals of the hidden cards, scored by the hand-written position value.
800 simulations a decision, each re-dealing the hidden cards and ending in two turns of heuristic play, scored by the hand-written position value.
Choose your opponents, then press New game.
The board appears here when a game starts.
Your move
Press New game to deal a board. Your moves appear here.
Controls
- Keyboard
- Every move you can make is in the panel headed Your move: a button, or a list with a button under it. Tab moves through them.
- For a place on the board, choose it in the list, most productive first (the arrow keys, or the first letter of a tile, move through it; the board marks your choice), then press the button under the list.
- Pace and Skip to my turn sit above the board. Escape clears a choice made on the board.
- Pointer and touch
- Dashed outlines on the board are the places you can build on, or move the robber to. Click or tap one, then press Confirm under the board.
- The panel can make every move too, including the ones the board cannot show, such as trades.
How it works
The engine is the C++20 rules engine of my CatanAIPlayground study, with its four built-in computer players: random, heuristic, lookahead and tree search. Here it is compiled to WebAssembly and runs only in this browser tab, in a background worker (or on the page’s main thread where a worker cannot start). It loads only when you start a game, and nothing is sent anywhere. Each game is dealt from a seed drawn with crypto.getRandomValues.
Your opponents are the engine’s hand-written and search players, not the learned agents from the case study: those agents’ trained networks are not part of the browser module. The heuristic player follows hand-written rules. The lookahead player tries every legal move and the best two follow-ups in the same turn. The tree search player runs 800 simulations a decision. Neither search player sees the hidden cards: both re-deal them at random before they search.
How strong they were measured to be, in the project’s report: one seat against three heuristic bots on 416 shared deals, where the heuristic bot itself scores 25.7% [21.6, 30.0], the tree search bot won 36.3% [31.7, 41.1] and the lookahead bot 35.1% [30.8, 39.7]. In a tournament of every table of four among nine entries, the tree search bot won 56.8%, the lookahead bot 46.2% and the heuristic bot 30.9%. The report notes that the search bots’ strength rests on the heuristic bot’s opening and its hand-written position value. Two caveats: those games were measured with the seats rotated, while here you always move first, which is an advantage; and they were played against the project’s own bots, never against people, so there is no human benchmark.
The engine plays the full base game for four players, with these differences from the published game. Trading between players is structured: the player to move offers a 1-for-1, 2-for-1 or 1-for-2 swap of two resources, the others answer in turn, the first to accept trades, and there are at most three offers a turn. A game is a draw after 500 turns. Discards are made one card at a time, which comes to the same.
The computer seats move one decision at a time, each shown on the board and in the log before the next, at the pace you choose (a step stays 0.8 s at Normal, longer for a roll or the robber). Every answer to an offer is held for the same time: the pace’s own hold (0.8 s at Faster, 1.4 s at Normal, 2.2 s at Slower), or longer when an earlier decision in the game, other than an answer, was slow on your device (one and a half times the slowest of them, plus 0.2 s), so the time an answer takes does not tell you which seats could pay. Skip to my turn shows nothing until it is your turn, then everything at once: it drops the other moves’ delays but still holds every answer, for a shorter time as nothing is on screen (0.3 s, or longer when earlier decisions were slow, and the same for every answer), so it too takes the same time whichever seats could pay. On a device so slow that one answer outlasts that hold, it would appear late. Nothing on the page animates: pieces simply appear.
The other seats’ cards are hidden by the module’s view and by this page: you see how many each seat holds, never which, until the game ends and everything is shown. They are not hidden from someone inspecting the browser’s memory, since the whole game runs in this tab; nothing is at stake.
The source is not public yet: the repository, CatanAIPlayground, is private, so there is no link to it. The module was built from commit c2428ba with Emscripten 6.0.13: about 50 KB of JavaScript and 107 KB of WebAssembly. This project is not affiliated with the game’s publisher.