Magic AI

image

As I’ve mentioned in previous blogs, I don’t like game design. I like to mod other people’s games much more.  That’s what got me into game development in the first place, the love of modding or taking other people’s concepts in a different direction.

It’s probably one of the reasons I enjoy debugging so much (and hence, multithreading is so fun for me to work on).

One of the areas I desperately want to improve the computer players on has to do with spell casting.  Ideally, I’d like it all data driven in XML and then tweaked with Python.  But in the nearer term, I just want to make the computer players play Elemental extremely well. And that means, looking at the kinds of things that the computer players can easily access:

image

There are a lot of interesting APIs available to the AI to look at spells.  But like Cypher in “The Matrix”, I prefer to look at all the data at once and see what strikes me as useful.

I know, as a human that Arcane Weaponry is useful. But what kinds of things can I access in this spell that will indicate that it’s useful to the AI and how it might best be used?

As you’ve probably gathered, there’s a lot of subjectivity involved. An author bias.  As I get better at the game, read the forums, etc. I can incorporate these experiences into biasing the AI in certain directions.

48,766 views 20 replies
Reply #2 Top

Yah absolutely fantastic! Glad you guys are puttering away at it. Looking forward to better AI, and of course the expansions!

Goodwork Frogboy and the rest of stardock :D

Reply #3 Top

Elemental's wish list.

Great AI

64 bit for larger maps

 

well its more of mine but who wouldn't want that?

Reply #4 Top

I'm glad that this is getting special attention; Spells make all the difference between success and defeat, and A.I. opponents in these types of games typically under-use or incorrectly use these types of complicated mechanics.

Keep up the good work!

Reply #5 Top

I like to think of it as us all working on it together.  I read the forums and the strategies and then try to see if I can play them out.

It's amazing how big a difference a few lines can make to the quality of the opponent.

Reply #6 Top

Wouldn't the easiest approach be to just have a specific tag that tells you what the spell does?

TacticalAOEdamage
TacticalSingledamage
TacticalSelfBuff
TacticalFriendlyBuff
TacticalHeal
TacticalAvoidance (blinks and whatnot)

and so on? That would give the modders something to "tap into" as well. Then the AI can decide, based on that + which is the strongest spell what to cast.

Reply #7 Top

I love these posts! It's great to get a look under the hood of game development. I'm a little curious/concerned about this one though. Does this mean that each spell added into the game will have to have an AI component modded in to accompany it?

If yes, will we eventually have the tools to do this?

Reply #8 Top

For Arcane weaponry, it seems best to apply a more general AI algorithm to evaluate the value of a given unit (a potential target for the spell, in this case) having a given attack value (which would take into account things like whether there are any opponents with heavy armor, and how much this problem has been addressed previously), and compare the values with or without Arcane Weaponry, then consider the value added versus the amount of available mana, mana regen rate, and the other spells the AI could cast that turn.

For longer-term planning, it would be useful to consider spell targets that aren't immediately available, and reduce the relative value of such a spell-use with the distance of the target.  If this were to be done, the target would need to be aware of this, so you don't end up with the Sovereign chasing a champion around trying to cast a buff on them.

Reply #9 Top

Quoting Heavenfall, reply 6
Wouldn't the easiest approach be to just have a specific tag that tells you what the spell does?

TacticalAOEdamage
TacticalSingledamage
TacticalSelfBuff
TacticalFriendlyBuff
TacticalHeal
TacticalAvoidance (blinks and whatnot)

and so on? That would give the modders something to "tap into" as well. Then the AI can decide, based on that + which is the strongest spell what to cast.

Yes.  And if those tags were in the XML right now and read in by the XML reader I'd use them.  But they're not. 

Reply #10 Top

There are a lot of interesting APIs available to the AI to look at spells.

Speaking of API, I herd that eventually, there will be an API available for modders. I wanted to know if it was currently possible for modders to add code to Elemental? Is the feature activated? Or it's simply the lack of documentation that makes it unavailable right now?

Else is it possible to change the user interface ( the DXpack files). It might not be possible to add stuff, since that would link to some line of code, but it might be possible to hide stuff we do not intend to use from the interface.

Reply #11 Top


It’s probably one of the reasons I enjoy debugging so much (and hence, multithreading is so fun for me to work on).

Debugging is what I hate most. That and tweaking AI 8C .

My experience with coding AI showed me that planning to code all possible behaviors and conditions when the AI should perform them will yield a lot of tweaking and testing and tweaking and testing and so on. And could easily be broken by adding or tweaking a new element in the combat system. What I ended up doing was a genetic algorithm that could, over a couple hours of free delicious CPU time, computes a fairly decent AI. I was amazed by the results I got from this technic. Also, it's a lot of fun to watch how the AI evolves over several generations and what kind of solutions it gets too. I actually found several exploits in the combat system with that. It also removes subjectivity out of the equation since it a very empirical solution.

Problem is, setting up such algorithm can be tricky though :S it might not be worth it at the stage of development of Elemental.

 

Anyway, keep up the good work! I really enjoy Elemental :)

 

Reply #12 Top

Quoting Svalkisalanazar, reply 1
Great work man, Elemental will become one of the best TBS games I've ever seen : )

 

To bad it is going to take 1 year until it is. I am very P.O.ed and I have yet to enjoy this mess of a game.

Reply #13 Top

Quoting Frogboy, reply 5
I like to think of it as us all working on it together.  I read the forums and the strategies and then try to see if I can play them out.

I think its great that Stardock improves Elemental, but before there could be different strategies different options must be available and currently Elemental is missing these options, but they can be found here:

https://forums.elementalgame.com/400580

https://forums.elementalgame.com/401023

https://forums.elementalgame.com/400657

https://forums.elementalgame.com/400832

https://forums.elementalgame.com/400890

Reply #14 Top

Quoting Filthgrinder, reply 12

Quoting Svalkisalanazar, reply 1Great work man, Elemental will become one of the best TBS games I've ever seen : )
 

To bad it is going to take 1 year until it is. I am very P.O.ed and I have yet to enjoy this mess of a game.

Well, there are plenty other of good games right now. =)  I suggest you find other game/s and leave Elemental for a while, or get a 75% refund for a player who doesn't like the game if Stardock is still doing those.

What's happened has happened.  There's no way Stardock can rush to a great Elemental from this point in time.  Every step must be careful and deliberate from now on, and building a game up from a unpromising start is difficult and time-consuming.  Don't lose health and happiness by worrying too much about the state of Elemental and what could have been. =)

Best regards,
Steven.

Reply #15 Top

AI is the toughest and most expensive component of modern games (considering their complexity). Most commercial games cut the costs here and write only the dumbest AI that can convince a reviewer spending a few hours with the game to rate it positively.

If you manage to create a competent AI for Elemental, that would be wonderful. AI for Galciv2 was excellent.

Reply #16 Top

Why go for AI, what we actually want is AP - Artificial Personality.  To do that you can have a more scripted AI that follows a particular strategy.  e.g.

  • beeline for a particular tech (e.g. Archery) and then exploit it (archer squad rush)
  • Expand as fast as possible, to claim territory, build limited defense and then back fill once you encounter someone (or something)
  • Build very mobile troups and have some scouts so that you can chase down enemies
  • Rely on heros and adventuring
  • Imbue some major heros
  • Summons
  • etc

each one doesn't need to have tremendously strong analytical powers (although the stronger the better), but it would create some uniqueness.  I seem to remember that Civ 4 did this by means of a table of weightings for various strategies for the various leaders, which were somewhat random.  You then started to get the personality of the leaders after a few games (Ghandi will almost never sneak attack, others you always suspected war was coming whatever they said over the diploacy table.)

Reply #17 Top

Keep in mind that one of the advantages of computer players is they don't run into micromanagement fatigue. With tactical spells such as arcane weaponry, regenerate (which needs a huge buff), etc, I think the best thing to do is have the spell caster analyze both whether or not the spell is beneficial (ie, are they going to be going into a close fight? Is it unpredictable vs a human player?), and cast the spell then. They should remove as soon as they feel it's no longer necessary, maybe even the turn after the fight.

Reply #18 Top

If I were programming, I would create 5 to 10 caster personalities.  Each personality (just like a human opponent) would have a list of spells that they would research (in order) as they become available.  They would also have a combat personality (depending on how many and strength of opponent in a particular battle) that would weight one spell above another.

On lower difficulty levels, the casting of available spells would be more random and more sporadic. (focused more on melee)

These personalities would be randomized when you start the game so you wouldn't know that Capitar has X personality.

 

Reply #19 Top

Quoting redeye2433, reply 18
If I were programming, I would create 5 to 10 caster personalities.  Each personality (just like a human opponent) would have a list of spells that they would research (in order) as they become available.  They would also have a combat personality (depending on how many and strength of opponent in a particular battle) that would weight one spell above another.

On lower difficulty levels, the casting of available spells would be more random and more sporadic. (focused more on melee)

These personalities would be randomized when you start the game so you wouldn't know that Capitar has X personality.

 

Yes - this is of course on the presumption that several "pre programmed" AI's are easier to make than one good one. if they are you can adopt an evolutionary approach by making new ones and dropping old ones when they are either weaker or more boring than the rest.

Reply #20 Top

Master of magic had the concept of personality like: Expansionist, agressive, etc. Giving personality could be interesting. Either they are assigned at character creation. So each sovereign will have a personality of it's own (making it easier to remember them), or either they are assigned randomly.