I've been working on Dwarf Guild Mania for quite a while now, and I've just pushed what is probably the biggest update the game has had so far. It's changed the game quite substantially, so I wanted to take a break from talking about features and instead talk about what it's actually like building a strategy game in Unity - particularly the part that's caused me the most headaches: AI and balancing.
When I originally started Dwarf Guild Mania, it was meant to be a fairly straightforward turn-based economic strategy game. The idea was simple: manage your guild, collect resources, build up your economy, and try to become the wealthiest and most prestigious dwarf faction. But over time, I just kept adding systems. Then came factions. Then politics. Then diplomacy. Then alliances and diplomatic agreements. Then warfare. Then territorial expansion. And suddenly I had a game where every player can potentially have hundreds of decisions available to them every turn.
Now you can form alliances, negotiate diplomatic deals, manage relationships with other factions, declare wars, fight battles, expand your territory, manage your domestic affairs, develop your economy, assign units, and generally try to keep an entire dwarf civilisation from collapsing in on itself. Which brings me to the problem that's taken up way more of my time than I'd like to admit: actually getting the AI to play the game.
AI is ridiculously hard
My last three games were FPS-style games, so this has been a pretty massive change in how I think about game development. With an FPS, you can give an AI a relatively small set of immediate decisions: move here, shoot that, investigate this, take cover. A strategy game is completely different. Imagine giving an AI 20 units, hundreds of tiles, dozens of possible actions, multiple resources, diplomatic relationships with 15 other players, a military score, an economy, domestic problems and a bunch of longer-term objectives. Now ask it: "What should you do this turn?" And then ask it again next turn. And again. And again. Somehow it needs to make decisions that are not only individually sensible, but also make sense as part of an overall strategy.
I ended up completely rebuilding my AI system four times before getting to the architecture I'm using now. The biggest lesson I learned was that I couldn't just make the AI ask: "What is the best action I can take right now?" It needed to first ask: "What am I actually trying to achieve?"
Breaking it into layers
The current system separates the AI's overall strategic priorities from the individual actions its units can take. At the beginning of a turn, the AI evaluates its current strategic position and produces a priority score between 0 and 1 for several broad strategic areas: Economy, Military, Domestic, Diplomacy, and Expansion. So an AI might decide that, given its current situation, its priorities look something like: Military at 0.85, Economy at 0.70, Expansion at 0.55, Diplomacy at 0.30, and Domestic at 0.15.
This doesn't tell the AI exactly what to do. Instead, it tells the rest of the AI what kind of decisions it should favour. If the AI is preparing for a war, military actions become much more valuable. If its economy is collapsing, economic actions become more important. If it's surrounded by powerful enemies, diplomacy may suddenly become a very high priority.
Then the unit-level AI takes over. Rather than having one enormous AI system evaluate every possible action for every unit, each unit is responsible for figuring out what it can realistically do. A merchant might evaluate markets, trade opportunities, valuable resources, and potential trade routes. A diplomat might look at rival factions, existing diplomatic relationships, potential alliances, and players that might be willing to negotiate. A military unit might look at enemy territory, friendly territory, strategic positions, potential attacks, and defensive positions.
The important part here is that the unit doesn't necessarily evaluate every tile on the map. If I have 500 tiles and a merchant can only meaningfully interact with 30 of them, there's no reason to make the merchant score all 500. Instead, each AI unit first filters the map down to a sensible subset of potential targets and then evaluates those. This made a surprisingly large difference to performance. The AI was originally doing an enormous amount of work every time you clicked "Next Turn", because it was effectively considering thousands of pointless combinations.
Scoring with context
Once a unit has figured out what it can actually do, it scores those actions. You might end up with a list like: Merchant trading at Market A scoring 72, Merchant trading at Market B scoring 61, Builder constructing a House scoring 58, Diplomat proposing a Pact scoring 54, Soldier attacking an Enemy scoring 51. But those aren't the final scores. The AI's overall strategic priorities get factored into them. If the AI has decided that Military is extremely important this turn, military actions get boosted. If diplomacy is currently a low priority, diplomatic actions get reduced. This means the individual unit doesn't need to understand the entire strategic situation. The strategy layer says "Military is important right now", the military unit says "Here are the best military things I could do", and the AI planner combines the two.
Once every unit has generated its best possible actions, they all get combined into a ranked list and sorted by strategic score. The AI now has something resembling a giant shopping list: Attack enemy position, Build military barracks, Recruit regiment, Establish trade route, Build house, Send diplomatic proposal, Expand into territory, and so on. The planner then works its way down this list and tries to actually assign those actions to units. When it sees "Build House → Builder #3", it checks whether Builder #3 can actually perform that action. If they can, the action gets assigned. Once a builder has been assigned an action, I remove other conflicting builder actions from consideration. There's no point in the AI planning five different things for the same unit in the same turn.
This sounds fairly simple, but there are a lot of edge cases once you start dealing with multiple units competing for the same tiles, actions that conflict with each other, and resources being spent by previous decisions.
The resource problem
The biggest problem I had with the AI was actually resource management. Originally, the AI would look at its available actions and pick the highest-scoring action it could currently afford. That sounds logical. It wasn't. It resulted in the AI constantly spending its resources on cheap, relatively unimportant actions while never making progress towards the expensive things it actually needed. Imagine the AI wants to build a powerful military structure that costs 500 gold. It currently has 400 gold, so it can't afford it and ignores it. Then it finds a low-priority building costing 50 gold and buys that. Then another cheap action. Then another. It would continuously spend its money without ever saving enough to do the thing it actually wanted.
So I introduced a planning budget. The AI generates a snapshot of its available resources at the beginning of the planning phase, and every time it considers an action, the cost of that action is accounted for against the planning budget - even if the AI can't currently afford to execute it. This was a really important change. If the AI decides "I really want to build this 500 gold military structure" but only has 400 gold, that action still consumes 500 from its planning budget. The AI therefore doesn't suddenly spend that 400 gold on five unrelated actions. Instead, it effectively decides: "I'm going to save for this." On a future turn, once it has enough resources, it can actually execute the action. This makes the AI feel much more intentional because it isn't just reacting to whatever it can afford at that exact moment. It's actually capable of planning around future resource requirements.
Why not just simulate ahead?
One of the obvious solutions would be to simulate several future turns and pick the sequence that produces the best result. The problem is computational cost. When you have hundreds of possible actions, multiple units, dozens of possible tiles, and interactions between diplomacy, economy, warfare, and territory, the number of possible future states gets ridiculous very quickly. Trying to brute-force every possible decision tree would be completely impractical for what I'm trying to achieve.
Instead, I'm using a more hierarchical approach: Strategic goal → Action evaluation → Unit selection → Resource planning → Execution. Rather than asking the AI to simulate everything, I try to make each layer make a reasonably intelligent decision and then combine those decisions. It's not perfect, but I've found that it gives me a much better balance between AI quality and performance. And honestly, getting that balance right has probably been one of the hardest parts of the entire game.
And then there's balancing
Balancing a strategy game is basically a full-time job by itself. Every time I change one number, it can affect five other systems. Increase the value of a resource and the economy changes. Economy changes and military production changes. Military production changes and diplomacy changes. Diplomacy changes and AI expansion changes. Expansion changes and resource availability changes. Suddenly a small balance change has completely altered the way the AI plays the entire game.
I've spent a ridiculous amount of time watching AI games play out, looking for situations where an AI is making decisions that technically make sense according to its scoring system, but are obviously stupid when you watch the game as a human. That's actually been one of the most useful parts of developing the game: watching the AI play against itself. You start seeing emergent behaviour that you never explicitly programmed. Two factions becoming long-term allies. A weaker faction desperately trying to build an alliance because it knows it can't win a war alone. An AI expanding aggressively and then completely wrecking its economy. A faction becoming extremely wealthy but militarily vulnerable. Or an AI deciding that war simply isn't worth the cost and instead building up economically. Those moments are probably the most rewarding part of developing the game.
Everything else
Outside of the AI, I've also been putting a lot more work into the presentation recently. I've been rebuilding and refining a lot of the UI, improving the map presentation, adding more feedback to actions, and generally trying to make the game feel less like a collection of systems and more like an actual cohesive strategy game.
I also added a heraldry system because, well, why not? You can create a coat of arms for your faction and have it represent your civilisation across the game world. It's one of those features that isn't necessarily required for the gameplay to work, but adds a lot of personality to the world.
I'm still very much in the process of figuring out what Dwarf Guild Mania actually wants to be. It started as a relatively simple economic strategy game and has gradually grown into this weird combination of economics, politics, diplomacy, warfare, factions, and territorial strategy. That's created a lot of technical challenges, but it's also made the project much more interesting to work on.
I'd genuinely love to hear what people think about the visual direction, UI, AI approach, and overall first impression. Especially from other Unity developers — I'm very interested in how other people approach AI architecture in strategy games, because this is definitely an area where I've learned mostly through repeatedly breaking my own system and rebuilding it.
Thanks for coming to my strategy game TED Talk. 😂
Steam page:
https://store.steampowered.com/app/4346210/Dwarf_Guild_Mania/