Piggybanks for dynamic AI


27/05/25: Wallets for AI

I've been tinkering with weights and rules for the AI to keep building mines and ships, developing planets, and constructing new shipyards — but only after achieving a certain level of economic stability.

It all turned out to be a bit trickier than I had thought. For a long while, Al kept buying the first thing it could afford. This led to a "massive" fighter fleet purchased with starting resources — but left no money for building mines, for example. You can't get that many fighters with just the starting resources, and without mines, you're stuck with that fleet for the rest of the game.

I needed a different approach.

I tried adjusting the priorities and introduced weights. While the weights worked as intended, the underlying mechanics still forced the AI to bypass the weighted option in favor of the cheapest one. No matter what I did, I couldn't seem to get past this logic. I introduced a saving-for-something mechanic, but that alone wasn’t enough to make the AI truly strategic.

For example, if the AI decided to start saving for a shipyard while only having 15 mines, that decision would lock out all other spending for a long time — and the mine count would remain at 15 until the shipyard was finally built. I could add a safeguard, such as triggering the saving behavior only if at least 50% of the required resources were already available. But since shipyards and infra upgrades are expensive, you'd need something like 70 mines before that trigger would realistically activate. And that's not likely — 70 mines is deep late-game territory.

Deep down, I felt the saving mechanic was essential — but it needed something alongside it to really work.

Then it hit me: what if Al had different wallets — separate piggybanks for different types of purchases and developments? With this setup, the saving mechanic started to shine. The AI could spend freely on fighters and mines while still saving for infrastructure upgrades and new shipyards.

It also allowed me to introduce general rules based on the game’s phase. Early on, the AI now focuses heavily on expansion and economy, saving only about 10% of its income for future infrastructure. In the mid- to late-game, the tech wallet receives more funds. And in the late game, most of the money goes toward ships and tech upgrades, with minimal investment in new mines.

(Sidenote: Since minerals are the scarcest resource, I’ve started using mineral income to define game phases — less than 15 is early game, 15–40 is mid-game, and 40+ is late game. By 30 mines, you're able to sustain upgrades fairly consistently.)

Anyway, this separate-wallets approach also opens up possibilities for tweaking internal priorities — making it easier to define rules like when to upgrade a shipyard vs. when to build a new one, or when to prioritize planetary defenses vs. destroyers.

And that’s what this week is for: finding a working balance between priorities, even if cruisers still fly sideways.

Files

index.html Play in browser
31 days ago

Leave a comment

Log in with itch.io to leave a comment.