AI Development



How should an AI computer play Fate of Empires? Here's a rough sketch of the systems processes involved in its decisions.

When originally designing Fate of Empires, I wanted to have every game feel different. Deck builders are pretty good at that due to the variance inherent in having a stack of unique cards that is shuffled and revealed throughout the course of the game, but I wanted the "best" strategy to be one that always depended on exactly which cards were available throughout the course of the game.

I was envisioning something along the lines of: "Well, I was planning to go Technology exclusively this game to power up the Tech that count for each Technology in your hand, but because I have enough wild resources this turn and I see Ada Lovelace there, I'll buy her and then swap my worse technologies out for better ones, despite diluting the deck with a Person." Or perhaps someone with the City + Technology Trait would decide at first they wanted to invest heavy into Cities but upon seeing a particularly fun Technology decide to switch to that.

I didn't want a best because best is boring. Best is easily attainable if you know what it is. I'm always a fan of trade offs. I was hoping for a flowing best, the strategy of allowing your game to be directed by the interplay of cards as they appear during the game. It turns into an everything matters sort of situation, where even the smallest decision of which card to shuffle away from the central purchasing area (Supply Area) can be game changing.

I'm very happy with how the 6 years of game balance has slowly allowed for exactly this to happen.

So when planning the AI, the computer opponent for solo play, things started to get very difficult very quickly. It turns out that not having a best strategy and having a flowing best means that not only is it computationally intensive to accurately compute each decision in the game, it may not be strictly possible, as there is no known metric for determining if one choice was better than another.

Heuristic based approaches tend to work best in these situations. You may not be able to decide at the grocery store which variety of greens to use for your salad, but you can come up with some simple rules to adhere to. "I like the Spring Greens mix better than the 100% Spinach container" at the grocery store produce aisle, "but if the 100% Spinach container expires 2 or more days after the Spring Greens, I'll buy the Spinach instead."

With 120 unique cards that can be purchased and 50 unique Wonders, things like this can get out of hand extremely quickly. "If I have Ada Lovelace already, I should purchase this cheap Technology instead of the most expensive one because she can swap cheap Technologies for expensive ones later." While that thought makes sense, it also requires the AI to play completely differently just because it has Ada Lovelace in its deck.

Even more bare-bones logic must be ironed out first. Which thing should the AI focus on spending its resources on? Which order should the AI play the cards from its hand? Which choice should the AI make on the cards that have them?

The problem was overwhelming at first, and it doesn't help that we need the code for the AI to run on a mobile device, meaning we can't have it even consider half of the things a human would or its turns would take too long.

Enter the simplifications. First, card priority logic. Some cards should be played first; the ones that count how many of a specific type of card is in your hand. It makes sense you'd want to play those before you no longer have cards in hand. After that it gets a lot less obvious. Should you play a card that draws you another card before you play your Artist (which only gives you resources)?

Next, how do you determine whether to save resources on your Capital or to play them? Typically, a human would choose to leave assets on their Capital unless there is something particularly exciting to purchase. Desirability indexes have to be created for that choice.

The list of things goes on, but I was very excited to finally get the pseudo logic completely drafted today. I had 9 Notepad++ files, 5 notebook pages of notes/ideas, and several floating sheets of paper with things that the AI had to track down, and finally I have a completed first-edition rough draft of AI logic completed. It almost feels like I've created a sentient thing, ready to go out and beat new players of Fate of Empires!

A lot of work will come to turn the pseudo code into functioning code, but the first step, the hardest and most uncomfortable step I've taken in designing Fate of Empires, is done!

Comments

Popular Posts