Skip to content
ranbao_deng://
← ~/projects

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.

Main factors that raise or lower each holding type's score
HoldingMore likely with…Less likely with…
Castlemountains, hills, choke points (rivers, straits, coast); Castle Keepers culture; bellicose or stoic ethos; warrior dynasty legacysemi-fertile land (terraced hills, wetlands); pacifist cultures; theocracies; republics that already have one; admin realms (slightly); counties that already have two
Cityfarmland, floodplains, oases, wetlands; rivers and coasts; republics and admin realms; City Keepers, Parochialism or Republican Legacy traditions; bureaucratic or egalitarian ethos; metropolitan dynasty legacytheocracies (unlikely until they have one)
Templetheocracies; forests (logging-camp synergy); Fervent Temple Builders, Monastic Communities, Religious Patronage; spiritual ethoscounties 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.