Frogboy Frogboy

AI Wars Part 2: Building a better empire.

AI Wars Part 2: Building a better empire.

For you  map makers out there, you’ll be happy to know that I have modified the code today so that if you set your map to NO objects that it will create no objects at all (before it used to still seed the basic set which is no longer needed in v1.1). 

This means I can make a really boring but --- explicitly controlled map.

Screenshots of what’s going on

Please excuse the ugly screenshots. I’m in the debugger.

Turn 1:

image

Everyone on my test map gets 1 fertile land and 1 shard. It’s a barren, ugly world. This world has no quests. No goodie huts. No Monsters.

 

Turn 20: Comparison time

image ME

 

image AI: Gilden – The heavy production faction

image AI: Capitar – The merchant heavy faction

imageAI: Yithril – Warrior/Archer faction

So as the AI guy, my first evaluation on this is to decide whether they are making the right choices.  All three of the AI here have decided not to put any resources into training units but instead have put it into building up their city.

Turn 50: AI errors

image

 

Version 1.1 of Elemental supports mana maint. The AI must learn how to use this.

image

 

I don’t need to go further. Now it’s time to go back and make adjustments.  Stay tuned for part 3.

94,098 views 47 replies
Reply #26 Top

Quoting Heph_, reply 22

The pawlowian-reflex is an aquired thus learned behaviour which is entwined with a preset behaviour (a "baseprogram" in this case) that made the dog water its mouth upon seeing food.
End of Heph_'s quote

Speaking of all things culinary and Pavlovian Mmmmmmm.

Reply #27 Top

Quoting Gene1966, reply 24
Brad,  you wanted CHEESE, here is my cheese.

The current AI is flawed in that it does not react to the following situation.

AI 'X' decides I'm a good target and attacks my newest outpost, while I may be weaker ATM I used summoned creatures and magic to break the AI's assault and then immediately follow up with a counter assault of my own which steamrolls the AI all the way back to its Capital.  My analysis is that the AI is not capable in its present state to adapt its suplly line of fresh troops allowing me to pick them off 1-3 at a time before they and consolidate and become a serious threat.

That was problem #1, problem #2 is that the AI Sov seems against common sense to refuse to defend its capital and the Sov stack tends to be the last significant threat once war breaks out. 

Combined, these are the two flaws that make the Hardest AI setting to be a cakewalk imho ...
End of Gene1966's quote

 

This.

Reply #28 Top

To quote mister Carrol:

 

"Enquiries have been so often addressed to me, as to whether any answer to the Hatter's Riddle can be imagined, that I may as well put on record here what seems to me to be a fairly appropriate answer, viz: 'Because it can produce a few notes, though they are very flat; and it is nevar put with the wrong end in front!' This, however, is merely an afterthought; the riddle as originally invented, had no answer at all."

End of quote

 

edit: but actually the answer

 

Because Poe wrote on both.
End of quote

 might be more fitting to the situation since this answer indicates that in the original situation it was ambiguous to whom Heavenfalls statement was directed.

Reply #29 Top

Quoting Heph_, reply 28


Because Poe wrote on both.
End of Heph_'s quote

 

Get your hair cut!

Reply #30 Top

What I meant with my earlier post is it could learn build orders, sneaky tactics, and other stuff, from humans.  Not that it would try to do everything from the ground up.

 

 

Reply #31 Top

Do we know each other? Hehe yeah maybe i should get my hair cut - just the tips.

 

Frogboy did you solve your problems yet? Anything we cold help with?

Reply #32 Top

Quoting Istari, reply 12
This is tedious. Why not have the AI design the AI?

For example, during the game, the tally system can keep records of how much was put into research of different kinds, how many resources of particular types were harvested, how many units with particular abilities were trained, how many cities, improvements, spells of type, expenditures, etc. When the AI loses, it examines at what stages of the game it was behind in any particular aspect, and automatically re-prioritises a new XML.
End of Istari's quote

It's never that simple. If there was an in-game reason why the AI researched Tech 1 it is pointless to record that it was researched without factoring in the reason.
Recording the fact that Tech 1 was researched due to the AI's successfully implemented desire to do it also does not necessarily have to be connected to "winning the game".
It could have been the fact that the enemy did not use a particular spell or weapon that this tech is especially vulnerable to.

The learning bit itself is simple. That's just recording. Now figuring out which cause lead to which result - that's the tricky bit.
And it's the easiest one to gloss over in suggestions... because it's obvious... to a human. =P

A big part of smart AI is teaching it to "understand". Recognise patterns and situations, recognise 5 armies within 12 squares of each other as an "army buildup".
Doing stuff based on this is easy. Computers are very good at just doing stuff once you tell them what to do.

Reply #33 Top

Quoting Gene1966, reply 24

The current AI is flawed in that it does not react to the following situation.

AI 'X' decides I'm a good target and attacks my newest outpost, while I may be weaker ATM I used summoned creatures and magic to break the AI's assault and then immediately follow up with a counter assault of my own which steamrolls the AI all the way back to its Capital.  My analysis is that the AI is not capable in its present state to adapt its suplly line of fresh troops allowing me to pick them off 1-3 at a time before they and consolidate and become a serious threat.
 
End of Gene1966's quote

I was surprised the first time I ran into this scenario.  The AI was quite undone by it and I quickly conquered several AI towns, though my army was not large enough to hold them; I essentially only had my stack of summoned creatures and a dragon.  The war degenerated into a take/take-back merry go-round, but it never addressed my summoned stack.

Reply #34 Top

Speaking of cheese, I like pepper jack. Especially on some johnsonville bratwurst burgers (Cooked in beer, if possible). Most delicious thing I've ever had. How about you guys?

Anyway, I played an online game a while back and was beating the tar out of the AI (Yes, I played my first online game against an AI, mainly because my machine is still getting OOM's) and before it crashed, I had searched the entire map and found them in one tiny city. I had cities all over (City spam ftw) and was consolidating choke points left and right, and the most I saw of the AI before i found their only city was a few adventurers roaming around. The city had a few militia in it and nothing else.

Was the AI code just that defunct (This was 1.08 I believe) that the AI just wouldn't expand or react at all? I've played other games where they've expanded all over the place. What triggers expansion? This particular map was full of resources and good city plots, and with the AI bonuses I would have thought they'd have taken full advantage of everything.

Anyway, looking forward to 1.1. Once the OOM's are gone from my machine I'll be looking to play a little more.

Reply #35 Top

Quoting Alstein, reply 30
What I meant with my earlier post is it could learn build orders, sneaky tactics, and other stuff, from humans.  Not that it would try to do everything from the ground up.

End of Alstein's quote

Certainly easier than trying to teach it to really learn how to play. But still not really viable, the issue with this is the number of possible moves each turn in a game of elemental, the variability of terain and resources and all the possible actions a player can take each turn. It's just not possible to record every move of every game then pick it appropriatley for any situation because of limits on computing poer to search the hudge database. Even then context is everything and by not properly understanding the context a computer AI would make hudge mistakes just copying moves.

Even if the implement a database that records every game played and then have some sort of logic to search all games and compare to the current situation in any given turn of any given game, we just don't have the computing power.

The AI will of course be based on rules the developer codes to decide what to do in a given circumstance they will try and generalise from how they play the game themselves when scripting. They probably will include variables like agression to influence how likley a nation is to go to war, these will be hooks for personalities. The hard part is making the AI not cheat and still be a challenge e.g. have it make decisions based only on information it would have if it was a player and still be able to keep up with an agile, and unpredictable human player.

The problem with AI oponents is they almost always are predictable once a player has studied them long enough.

You should go to game developers net and read up on game AI it's an interesting area.  

Reply #36 Top

Quoting Tydorius, reply 34
Speaking of cheese, I like pepper jack. Especially on some johnsonville bratwurst burgers (Cooked in beer, if possible). Most delicious thing I've ever had. How about you guys?

Anyway, I played an online game a while back and was beating the tar out of the AI (Yes, I played my first online game against an AI, mainly because my machine is still getting OOM's) and before it crashed, I had searched the entire map and found them in one tiny city. I had cities all over (City spam ftw) and was consolidating choke points left and right, and the most I saw of the AI before i found their only city was a few adventurers roaming around. The city had a few militia in it and nothing else.

Was the AI code just that defunct (This was 1.08 I believe) that the AI just wouldn't expand or react at all? I've played other games where they've expanded all over the place. What triggers expansion? This particular map was full of resources and good city plots, and with the AI bonuses I would have thought they'd have taken full advantage of everything.

Anyway, looking forward to 1.1. Once the OOM's are gone from my machine I'll be looking to play a little more.
End of Tydorius's quote

As you say the AI is normally better than that, I think you found a bug in the AI something about that map may have stopped it expanding.

Reply #37 Top

Frogboy,

In your turn 50 AI error image, I would argue that you are incorrect with the placement of your boxes. It would be in the best interest of each player to attempt to get as close to the center of the tri-bottle neck as possible, as this would not only give them a method of holding their own choke point, but also starving out the expansion of their potential enemies.

Edit: The expansion done by frogboy is not actually a choke point but a strategic intersection. Choke point implies there would be only one way in or out.

Reply #38 Top

Except for one of the 3 points it looks more like a resource allocation problem. These Points may not have the highest war-strategical value but a very high economy-strategic value. If my eyes dont betray me 2 of the 3 points exhibit Gold, iron, and crystals each of high economical value if it comes to trade and better army tech like magical equipment.

Reply #39 Top

Does the AI know what the player is doing? I don't know what they are doing when I play so is the AI cheating?

Reply #40 Top

Quoting FatNonFree, reply 39
Does the AI know what the player is doing? I don't know what they are doing when I play so is the AI cheating?
End of FatNonFree's quote

At present, I tend to doubt the AI even knows what its doing, much less the player.  They may have sight of you and all sorts of omniscient information, but they can't do squat with it right now.  They can't even do squat with the information on their own realms.  Fortunately, that looks like it's changing.

Brad, I wanna tell you somethin'.  My biggest gripe with AI in every game I've played to date, is how they value objects*.

*What these are changes from game to game, and is a very blanket term the way I'm using it.  Using Starcraft as an example, I'm talking about Base Structures, Resources, and Units, the three types of objects that make the game what it is.

In every game I've played, the AI is never capable of valuing these objects appropriately.  It generally gives all of them a blanket rating.  Going back to Starcraft, the AI will value base X just as much as base Y, despite base X being on the complete opposite end of the map and almost totally indefensible.  It will also value resources the same way.  Starcraft 2 is a little different in this regard, with the advent of Gold Mineral Patches.  (For those unfamiliar, they yield extra resources per trip compared to their lesser blue counterparts.)  Unfortunately, in SC2, they value these much too highly, and will often over-extend to get their hands on them, consequently making both that base, and their empire as a whole, an easy target.

Still using Starcraft as an example, they also value units the same way.  Playing against a Zerg for instance, I'll be winning a fight, but he'll still have Defilers in the back lines, and a mere handful of Zerglings at the front.  When the AI decides it's time to retreat, it sends ALL the units back.  Zerglings, being much faster, blow by the Defilers, leaving them to be picked off by my forces, despite the fact that with a few more units and the Defilers intact and at home, they could have otherwise prevented me from annihilating them.  Instead they should have valued the Zerglings as absolutely nothing, or rather, as a stop-gap, sacrificing themselves to let the Defilers get away.

I've run into this same problem with GalCiv 2 today.  Granted, I'm playing on Beginner with Sub-Normal AI, so I don't know if that's going to change when I bump everything up later, but even at the most basic levels, players assume their opponents are capable of thinking, "I can't possibly win against all of that, I need to cut my losses and defend what's most important rather than stretching myself thin."

The problem is obviously 'teaching' the AI to prioritize at least semi-intelligently...  But, my two cents are out there now.

Reply #41 Top

The thing is that that the Ai could defend the resources if it would use Teleports but i see what you mean. I think the resource value of a cluster of tiles has to be rated against the strategic value of these tiles in a first step. Part of this calculation should be that the distance to next bigger city is taken into account. 

A retreat behaviour is also needed upto thepoint that the ai does scorched earth tactics and burns a city beforeit falls into the hands of the enemy.

Reply #42 Top

Spacial awareness is always something that is harder to programme that you think.  That is why Go is harder to programme than chess.  What you are trying to do is get the AI to maximise the cumulative influence on it territory.  One possible algorithm would be something like this.

Step 1 project influence

give each city a weight based on its current strength (measured somehow -e.g. current army strength plus k*production capability)

Let it project that strength onto a distant tile based on some decay function.

That function would take into account the "distance" of the current best route (say 1/X or 1/X^2 or 1000-x^2)

The distance would accumulate the cost of the route based on how difficult it would be to project force through that route.

Open terrain would be a base cost

water terrain may be a higher cost (infinite without sea invasion)

Enemy territory may be a still higher cost.

Forrest/spawn grounds could also be taken into account as they would be avoided or fought through.

unknown terrain may need a different cost.

Step 2 calculate spheres of influence

if you have the highest influence in a plot it is yours and you count full value for it

if your influence is close to a rival or combination of rivals, then it is borderlands and you count half value for it

otherwise don't bother.

The value for each square will depend upon what it has in it (either a base value for nothing or  a higher value for some resources)

Step 3- evaluate options

what does you territory look like after you have done what you are going to do, is it a good option.

 

Of couse all this is computationally intensive (path finding is a real pain, let alone keeping track of what each AI knows, and managing the strategic options) - but that is what multi threading will cope with isn't it Brad!

Reply #43 Top

Quoting Napean, reply 33



Quoting Gene1966,
reply 24

The current AI is flawed in that it does not react to the following situation.

AI 'X' decides I'm a good target and attacks my newest outpost, while I may be weaker ATM I used summoned creatures and magic to break the AI's assault and then immediately follow up with a counter assault of my own which steamrolls the AI all the way back to its Capital.  My analysis is that the AI is not capable in its present state to adapt its suplly line of fresh troops allowing me to pick them off 1-3 at a time before they and consolidate and become a serious threat.
 



I was surprised the first time I ran into this scenario.  The AI was quite undone by it and I quickly conquered several AI towns, though my army was not large enough to hold them; I essentially only had my stack of summoned creatures and a dragon.  The war degenerated into a take/take-back merry go-round, but it never addressed my summoned stack.
End of Napean's quote

 

Napean,  When you have a strategic situation where you know you will be able to take a city or town but not hold it (ie, defend it from attack) then you are faced with three options.  The one you mentioned of take lose, take it again, lose it again etc...   Two, take it and raze it so the enemy cannot take it back.   And finally #3, Take it and don't stop, keep on rolling enemy town after town until you reach the AI capital.

In light of this you never really experienced "my scenario" only the first part of it.

As a boxer in the ring, if I connect my glove solidly with my opponent, to the point of ringing his bell, the last thing I want to do is back off into a defensive stance, I want to redouble my offence and finish the fight as efficiently as possible , preferrably with a K.O.

In this TBS game, I try not to start wars but when the AI does I go for the throat and I do not pussy foot around.  Then again I learned to fight over two decades ago at Annapolis.  War and Strategy as well as boxing and martial arts were just a few of our studies. 

Reply #44 Top

At present, I tend to doubt the AI even knows what its doing, much less the player. They may have sight of you and all sorts of omniscient information, but they can't do squat with it right now. They can't even do squat with the information on their own realms. Fortunately, that looks like it's changing.
End of quote

You are correct just like every other computer AI in every other game the AI is not sentient and so does not understand what it's doing^_^ . That aside I do agree the current AI is not great and needs improving which is of course what Frogboy is doing and what this thread is all about. I think the rest of your post is really a lot more productive by the way it's much better to say what you think the AI is doing wrong rather  than just saying it's rubbish.

Reply #46 Top

Full rewrites including the ability to work with files and Databases would be serious stuff. Especially if it comes to faction specific ability's one could just stick a file with some code to a existing General purpose Ai.

Reply #47 Top

Frogboy,

I'm fairly new to the game and unfamiliar with the AI.  I don't have a feel for how large that map is and how easily it would have been to figure out what the lay of the land was. Be that as it may, a thought occurs to me...  Some of the AI have clearly done some exploring and checked out the map, but what if some have done little exploring and don't yet really know the lay of the map or have explored poorly.  For example, purple and red only seem to have their sovereigns as units.  What if the AI has not yet established that it is sitting on a peninsula with only one entrance to and from its capital, and therefore it does not realize the value of placing the second city in the choke point? This *could* account for their poor choice in placement.

Just my two cents.  Keep the updates coming, I find this highly interesting!