AI Wars

The plumbing for Armageddon Empires is in fine shape and only occasionaly do I get an error or bug that I have to stamp out in the interface or basic game logic.  The last several months have been almost entirely focused on getting the AI to play a competitive game.  Along the way I have had my fair share of groans as the AI players did some boneheaded things.  I’ve also been pleasantly surprised at some solid execution and even I might dare say “emergent” type behavior.  Without going into too much technobable that might bore the non code junkies, I built the game from the ground up with the AI in mind.  Since the game was going to be a solitaire game, I new that a solid AI would be crucial to a “fun” or “challenging” experience.  My computer coding skills go back to the early eighties when I was an undergad studying electrical engineering.  I coded in Pascal on a VAX 11780.  The year before I arrived at the school, they had just gotten rid of punch cards and switched to terminals.  Wooden ships and iron men.  I’m not a particularly talented programmer but I have what you might call the Sharingan Eye if you are a Naruto fan.  I’m a copy ninja.  If I see some good examples I can nuke them out and elaborate a little.  The AI for Armageddon Empires is inspired from many books I read but “Programming Game AI by Example” was probably the biggest help.  http://www.amazon.com/Programming-Game-Example-Mat-Buckland/dp/1556220782

 Mat Buckland has a section on Goal-Driven Agent Behavior that helped me design a goal based architecture for my AI players.  Basically each AI player has a goal qeue that stores a goal object.  The qeue is sorted by priorities assigned to each goal and every turn the AI moves through the qeue processing the goals and spending Action Points and resources as best it can.  The generation of goals and the appropriate priorities is a tricky thing but I divided up the possibilities into several basic categories….Exploration, Resource Collection, Offense Ops, Defense Ops, and Support Ops.  If a threat is detected then the priority for Defense Ops is increased.  More defense type goals will be generated and they will have a greater urgency. 

 Time after time I ran across a problem where I needed to rate options and come up with some type of metric to compare them.  I implemented my own fuzzy logic system inspired by Mat’s examples as well as others.  Fuzzy logic is a great way to take a bunch of crisp parameters like Attack = 8 dice, Defense = 2 dice, and HP = 5 points fuzzy them up into Attack = “Above Avg”, Defense = “Below Average” and HP =  “Average” and then manipulate them with some logic rules.  For example, If Attack = “Above Avg” then “Target Desire” = “Strong”, If HP = “Above Avg” then “Target Desire” = “Below Avg.”  By using a thing called “The Combs Method” you can drastically reduce the number of rules like this.  The end result is a target rating that you can use to compare with others.  Once you have that you can pick the highest, lowest or use some other scheme to come up with the best choice.

So a goal based architecture and extensive use of fuzzy logic are the two big components.  Finite state machines are also a key component but they are tireless work horses that are so common they are almost taken for granted.  Each goal object is really just a finite state machine of a sort.  These programming techniques make up the Brains of the AI players but another important part is the actual architecture of the game itself.  I really wanted to make a game whose AI’s saw the same thing that the human player did.  So information storage and access was designed from the outset to facilitate this.  Each player and AI has an Intel Object that stores it’s own copy of what the player or AI knows about the game board.  Every turn or as a playing piece moves and observes more of the map that information is transfered from the main game map object to the players’ Intel Objects depending on what they can see (as determined by dice rolls that make observation checks)  The AI can only see what its armies deployed to the board can tell it.  Sounds great huh!  Well it opens up a whole new challenge for getting the AI to seek out the information it needs or even infer (gasp!) information from what it does not see.  Countless times I’ve had to dig into the reasons why an AI player passed up opportunity X.  Did the Intel Object not have the info and it simply did not see it?  Did it rate the chance of success too low? If so should the parameters be adjusted so such a no-brainer is recognized. 

Hidden information from the human can make the AI look stupid.  The game that I was playing last week as the Machines is a good case in point.  After my initial exploration and expansion, the Imperials kicked my butt pretty badly and forced me to pull back my supply lines to a more defensible perimeter.  I hunkered down and started rebuilding an army to go back out and kick some human butt.  6 or 7 turns clicked by and I was completely unmolested.  I thought, “damn!, something is broken.” The AI should have pressed forward by now and come after me.  He had harrassed me with some air attacks but nothing serious.   I dug back into the saved files for each turn and was surprised to discover that the Humans and Xenopods had made contact right above my little holdings and had been savaging each other a mere hex from my stronghold.  Both had been moving in for a kill and stumbled upon the other.  Soon their aggression rating with each other had built up enough that they were going at it full tilt and leaving puny me to be dealt with later. 

That’s a pretty basic description of the AI.  Here is a screenshot of a game that I am currently testing that has had a pretty epic sweep.  After getting some great resources and finding some excellent specials (the ones that provide a free outpost are real momentum accelerators) I pushed headlong into Xenopod territory.  Playing as the Imperials I found some key allies out in the wastelands as the humans are wont to do and I had a nice army built around some advanced combat mechs.  I got a little ahead of myself and left my supply anchor lightly defended.  A Xenopod army captured it and that left my mech army out of supply and crippled.  They fought a series of battles retreating back to a hex in supply.  The momentum has definately swung in the Xenopods favor.  I’ve got a huge stockpile of resources and good scientists so once I can get some tactic cards created to ensure success I’m going to build a city killer and see if I can even the odds. 

XenopodAdvanse