Side project · Crusader Kings III · 2026
AI Build Cities
Crusader Kings III is a grand-strategy game whose world is run by thousands of AI rulers. In the base game those rulers build almost nothing but castles. This mod gives them a believable building strategy and has become one of the most popular CK3 mods of the year.
- Subscribers
- 14,400+ · 37,500+ unique visitors
- Ratings
- 178, overwhelmingly positive
- Workshop popularity
- #14 past year · #10 past six months (Sep 2026; released Apr 2026)
- Links
- Steam Workshop ↗
The problem
In the base game, an AI ruler only builds a city once every slot of its personal domain is filled, and only theocracies build temples. As a result, castles end up everywhere: fertile river valleys look like mountain passes, and the map loses the economic geography that makes the setting feel real.
The approach: weighted, context-aware decisions
I replaced that rule with a weighted decision model. For every empty holding slot, the AI scores castle, city and temple from the context it is in, then chooses probabilistically. Where it applies, the logic also respects the liege's building directives from the base game.
| Holding | More likely with… | Less likely with… |
|---|---|---|
| Castle | mountains, hills, choke points (rivers, straits, coast); Castle Keepers culture; bellicose or stoic ethos; warrior dynasty legacy | semi-fertile land (terraced hills, wetlands); pacifist cultures; theocracies; republics that already have one; admin realms (slightly); counties that already have two |
| City | farmland, floodplains, oases, wetlands; rivers and coasts; republics and admin realms; City Keepers, Parochialism or Republican Legacy traditions; bureaucratic or egalitarian ethos; metropolitan dynasty legacy | theocracies (unlikely until they have one) |
| Temple | theocracies; forests (logging-camp synergy); Fervent Temple Builders, Monastic Communities, Religious Patronage; spiritual ethos | counties that already have a temple |
Tuning for plausible, not random
My first design weighted each ruler's personality and education heavily. In testing, that made the outcomes too random to feel intentional. I shifted the weight to terrain, culture and dynasty legacy, which are stable factors, and kept personality as a smaller modifier. The result is a map where you can read the history: a county full of castles in farmland usually had a long-ruling warmonger.
It also has a useful side effect. Fewer castles means fewer landed barons and more mayors, who have no court or family to simulate, so the change can slightly reduce the game's late-game performance load.
Why it's on an engineering portfolio
It's a small, real example of designing agent behaviour: turning a vague goal (“build like a medieval ruler would”) into interpretable, weighted rules, balancing determinism against randomness, and verifying emergent behaviour at scale. The same questions come up in robot decision-making and in game AI. It's also software that more than 14,000 players have chosen to run.