0.9.5 the Overland AI . I wanna help.

Anything else to do with MoM IME
Post Reply
Clythoss
Posts: 12
Joined: Fri Sep 15, 2006 2:28 pm

0.9.5 the Overland AI . I wanna help.

Post by Clythoss »

I really want do. Even though my coding abilitys are limited to say the least there must be something i can do. Maybe bring you food? Or do your RL job so you got more time? :)

No seriosly. This is my most favority projekt on the net right now. And i always wanted to contribute to make an AI. So this would be a great opportunity to me.

I watched the Version History and know this is your next big step after finishing 0.9.4 . I don´t know if you already made a global concept on how you want to handle the AI. I thought of a big load of tiny scripts all interacting with each other. Like 10-15 scripts city scripts for each kind of town. Like

10-15 Scripts for Klackon town with klackon as capital.
10-15 scripts for klackon towt without klackon as capital.
10-15 scripts for klackon on mirror with klackon as capital.

and so on...

these 10-15 scripts would be for different states the KI is in like war preparation, war, expansion, eco dominance, Mana gathering, preparation for Spell of mastery, and so on... these scripts would do callbacks to other scripts. Like when a city needs units for defense it would check the other cities if there is city better suited for this job. This city would then check on a priority list if it can do it. The global overland ki would send requests for units depending on what´s going on in the world. Any city which priority list doesn´t say it has more important things to do would follow this request. Or the magic ki would do.

I think you got the picture now.If you plan this or a similar concept you know you got an awful lot of writing todo. Not to mention the testing. Here is where i could fit in. I got 24h free time a day and would love to contribute. Even though i got no experience on that ( i guess writing a starcraft ai doesn´t count ;) ) i think i´m capable of helping. And there would be no reason to not start while you are still working at 0.9.4. But there is one thing. I wouldn´t like if you just say "ok do what you can, i´ll see if i can use it somehow." This is an awful lot of work as i mentioned before, so i would need to know if you would realy want to work closely with someone. English isn´t my primary language so i hope this didn´t come over wrong :).

Let me point this out again, i´m realy serious about this, and i got much of spare time. I would do anything. From helping you develop a concept to " Hey here is a list of 300 scripts i need and what they should do, now write them"
E=MC²+1W6
User avatar
Implode
Site Admin
Posts: 433
Joined: Fri Feb 24, 2006 3:35 am
Location: Newfoundland, Canada
Contact:

Re: 0.9.5 the Overland AI . I wanna help.

Post by Implode »

Ok this is now the official MoM IME overland AI discussion thread :D Thanks very much for bringing this up, I actually started some notes on how I was planning to do the AI ages ago, and have done very little on it since because I've been plugging away at the Java port for 0.9.4, so I'll put down my thoughts so far and we can see where we go from there, because I think we need a good design on how this will work before anyone starts spending serious amounts of time on it.

AI in the game I wrote prior to MoM IME
As background discussion, I'll mention how the AI worked in the game I wrote before MoM IME (which by the way I gave up on because I'd made too many bad design decisions up front which just turned it into an overcomplicated mess... and Microsoft keep changing the DirectX API didn't help much either). The game had an overland hex map which you'd move units around on - if you've played Battle Isle 2 or 3, its quite similar. There were no cities, but there were objectives placed around the map which you'd score points for capturing. You could see all the terrain (i.e. where there were hills, trees, water and so on) right from the start, you could see where the objectives were right from the start, but you couldn't see enemy units - you had to scout for those in much the same way as in MoM IME. So basically you had to simultaneously defend the objectives you already had while trying to capture the others.

Buying units was easy, because while there were crap cheap units and expensive good units, they functioned quite differently to MoM. Different units were good at different things, e.g. guys who were slow moving but with big guns were more suited to keeping still in cover waiting to spot an enemy unit so they could kill him - walking them out in the open to try to capture an objective would be stupid. Bikers move extremely fast but their guns are almost useless, so they're suited to dashing out, capturing an objective, then zooming on to the next objective before they meet heavy resistance. A player with lots of crap units could do just as well as a player with fewer expensive units, you could win on weight of numbers and trying to get a lucky kill shot. That just doesn't work in MoM - hordes of spearmen are never going to kill those Adamantium Hammerhands :wink: In MoM you normally just churn out as many as you can of the best unit you can build.

So the AI in my other game in the most part just bought random units, which gave it a good mix of offensive/defensive units, which is exactly what it needed. Now here's the important part. In the data for each unit, I wrote a tiny AI script. By tiny, I literally mean it was 3-8 letters long.
"A" might mean "If you can see an enemy, hide and shoot them from a distance"
"B" might mean "If you can see an enemy, rush off in the direction of the closest objective that we don't own"
"C" might mean "Sit still and wait for an enemy to appear and then shoot them"
and so on, so those slow moving guys with big guns would have an AI script of "AC". So there wasn't tons of script writing to, you just wrote a few codes which describe what that unit is good at. Even the most diverse units only had about 6-8 letter codes to describe their actions.

It worked *exceedingly* well. So much so that the AI beat me at least a third of the time. But it worked because you never had to scout aimlessley - if there were no enemy units to shoot, you knew exactly where the objectives were so still had something useful to do. That's a lot different from MoM where you don't know the terrain, don't know where the towers of wizardry are, and don't know where the enemy cities are. The overland AI in MoM IME is going to have to be a whole lot more complicated.

What I don't want to do
I don't want to have to write complicated scripts for each type of race, city or unit. MoM IME is customizable - you can add new races, buildings, spells, units, everything. I don't want modifying any of these to break the AI. So for example if you wrote a script for Klackon cities, but then someone decides Klackons are underpowered and for example allows them to build war colleges which then allow them to build some new super powerful unit that completely changes the Klackon strategy, and the Klackon scripts would then need rewriting. The AI should be clever enough to notice that Klackons can build the super powerful unit and utilize them as such, or in the unmodified version, realise that Klackon units are crap and not build them - we shouldn't have to script it to tell it all that - otherwise as you pointed out, you end up with a LOT of scripts to write - which I don't believe is the right approach.

Now, if you need to do like in my old game and write a *tiny* piece of script for a unit or a race, that's perfectly fine, because it isn't going to take much time to write those, and they'd be easy to change if someone did significantly alter the game balance enough that the AI would have to play differently.

MoM IME overland AI ideas so far
My attitude towards design and coding is that I don't have to know what steps 4, 5 and 6 are to know that steps 1, 2 and 3 are the right thing to do. And normally, by the time I've written 1, 2 and 3, it becomes increasingly clear what 4, 5 and 6 should be. So this isn't fully through through yet, although now I'm writing all this out it actually seems to fit together better than I thought :) Overall I feel the aim should be to get the AI to play like a human player, so I try to think about the way I decide what to do, and then try to figure out how I can teach the AI to make the same decision.

What the AI needs to do is:
1) Decide what spells to research
2) Decide buildings to build in each city
3) Place new cities
4) Decide how much defence is required for each of its cities
5) Scout
6) Build unit stacks to go attacking with, and work out where to attack
7) Decide the likelehood of winning a combat (don't attack if we're just going to get beaten up!)
8] Decide spells to cast overland
9) Decide allocation of magic power to mana/research/skill improvement
10) Use Alchemy when appropriate
11) Diplomacy

(1) is already done in 0.9.3, and I think it works satisfactorily enough. I basically tagged the more useful spells, so the AI picks spells to research randomly, but still tends to pick the better spells first.
(2) is also kind-of-done in 0.9.3, but needs revising since now it'll have to weigh up whether to construct buildings or units.
(3) is easy, I've got code already for deciding where are the best places to put cities.
(4) thru to (7) is what I'd like to do for 0.9.5. Worry about spells, magic, alchemy and diplomacy later.

Unit strength, friendly zones and city defence
In MoM you can't just decide city X needs better defence and build those units at city X. City Y might have an amadamtium deposit, war college and more production. On the other hand, if city Y is on the other plane and on the other side of the map, it isn't much good to us. So what I was planning to do is to get the AI to paint "friendly zones" by finding all of their own cities which are close enough together that you can reasonably expect to be able to walk units between those cities without them being ambushed. The city that can produce the best units within a friendly zone is designated the troop factory for that zone, and would be used to build defensive units and distrbute to the other cities that needed more defence, and to build attack squads. There might be multiple troop factories within the same friendly zone. Friendly zones can extend across both planes if they include a tower that's under our control. Once there's diplomacy, the AI would consider enemy units entering one of its friendly zones as a hostile action.

Unit ratings be calculated from the attributes (e.g. melee attacking rating) and skills (e.g. Fire Breath 3). Coding a value in to say e.g. Spearmen have rating 10, Swordsmen have rating 20 just isn't appropriate to MoM - if someone casts Lionheart on those spearmen, they suddenly become much better than the unimproved Swordsmen. So the unit ratings have to be calculated on the fly. Probably this will involve assigning a value to each melee point, ranged attack point and so on, and defining that for example "Fire Immunity" improves the unit quality rating by +15.

City ratings will be calculated from the size of a city, its buildings, and its terrain (cities with adamantium deposits or containing a wizard's fortress are WAY more valuable than any others). City ratings will be used both for the owner to decide how heavily they need to defend the city, and to decide which are the better targets when choosing which enemy cities to try to capture, and it will tend to put less defence in cities that are a long way inside our friendly zone (since its less likely someone can sneak an attack force that far in without us noticing... unless they're clever and use e.g. Planar Travel). Nodes and Towers will be defended in much the same way as cities.

So that I think gets us to the point where the AI can decide if a city has enough defence, if not figure out which troop factory to build more units in, get them built and send them over to the city. With some modification it will also do (7) - except now the unit ratings will be clever enough to know that for example "Fire Immunity" is MUCH higher rated when the enemy has units with lots of fire attacks than when they're just a bunch of halbardiers, and for example Pikemen are MUCH higher rated against enemy units with First Strike - so the unit ratings will take into account the actual type of enemy units.

Scouting and attacking
I think its also most of the way there for (6). The city ratings of enemy cities will tell the AI where to attack. Comparing our vs their unit ratings will tell us how big of a stack we need to build to have a reasonable chance of success.

Scouting shouldn't be too hard, just get some spare units who are preferably fast, and preferably can see >1 square, and wander around the blackness (especially coastline).

What's going to be really hard is: Using ships (loading units and shipping them to different islands), and getting an attacking force not always necessarily attack an enemy via the predicable straight line route... to try to make sneaky flanking attacks in the last place you'd expect them to attack (the AI in the original MoM was particularly bad at this - it used to just send droves of units in via exactly the same route every time).

Well... that's certainly my longest post ever :) Would love to hear your thoughts on how I was thinking to do this!

Thanks,

Implode.
Iluvalar
Posts: 46
Joined: Wed Oct 17, 2007 8:57 pm

Re: 0.9.5 the Overland AI . I wanna help.

Post by Iluvalar »

I'll give some technical advice to your AI ^^ .

*Building troops before the city get to the farmer market is rarely a good idea. In fact except for the alchemist guild and maybe the animist guild, buildings tends to be less and less useful the more building there's in the city because thay cost more and more production points and they are not necessary more efficient. BUT they still more efficient, so you get the more production for less surface to defend.

*Also, they're is a big geographical issue when come the time to target an enemy city. No matter how poor are the defence, the closelyness of the city, valuable deposit, building or population in a city. It is wortheless if it's but you in the middle of the warfare unless you are strong enought to move the said middle :) . Instead it would be a clever idea to defend your small frontier and take advantage of the accalmy to upgrade a bit what you already hold before moving on. And maybe stack several units (if food and gold production follow) before launching a massive attack.

*It's better if what you call "a friendly zone" have 2 military factories (especially at the start) so one of them can stop production for a while and build that sawmill (turning a 5 turns halbardier production into a 4 turns production) when the time come without putting in great danger the whole so called friendly zone.

*Targeting a city,node,dungeons and producing/reusing a stack is good, but it's just the first step. You need to reconsider your attack when you are on the last step there might be a better target close enought,less defended or more useful once you get there for real.

*Adding / multiplying some stats about the enemy units is great, but you should compare the units each other (hability and stats).For exemple, a unit with high defense is stronger then it's look if you don't have enought power to get trought but is not good at all if you have it and the unit as not enought strenght to retaliate.

City type:
*Free city (best result) :
Builds building from the cheapest to the strongest with low emphasis in military building. Easy to convert in another type if necessary.
*HQ : these cities are well positionned geographicaly. Starting city is generaly one of them.
Same as Free city but with more gold support from the wizard, they are ready to switch to any type when the time come.
*Military factory (better with favorable deposit, otherwise close but not too much from the front)
Rush toward military building in time of peace, produce the best troops they can otherwise.
*Unrest control plant (center of your kingdom best with alchemist guild)
produce low-cost spearmen or bowmen when extra defense is needed and distribute then in cities with unrest (not much productive since you need food for them but procure an extra defense as well and increase gold supply nationwide).
*Farms (Good max population)
Rush toward animist guild and take make more then usual food supply (should be defended with special care).
*Expension post (Good max population also, near expension project)
Stop building after farmer market and produce settler. building more is pointless since it will lose population faster anyway.
*Slave camp (Newly aquired strangers species, if not particulary friendly to your cause)
Rush faster toward religious building to keep the unrest reasonable. Also produce his own spearmen if the "Unrest control plant" is not accessible.
*Specialists production (tamed slave camp)
Basicaly a military factory. Most of the races have a special unit that can mix in the troops particulary well (not always the strongest one) one or two of these specialist can improve greatly the value of a troop. Exemples: Troll shaman (outragesly good), Paladin (holy bonus ^^), ranger (pathfinding), warlock (doombolt), slingers, any flying for scouting, etc.

I hope it will be useful somehow, if not for the AI for other players :) .
User avatar
Lucern
Posts: 113
Joined: Sat Jun 02, 2007 9:13 am

Re: 0.9.5 the Overland AI . I wanna help.

Post by Lucern »

Implode wrote:
What I don't want to do
I don't want to have to write complicated scripts for each type of race, city or unit. MoM IME is customizable - you can add new races, buildings, spells, units, everything. I don't want modifying any of these to break the AI. So for example if you wrote a script for Klackon cities, but then someone decides Klackons are underpowered and for example allows them to build war colleges which then allow them to build some new super powerful unit that completely changes the Klackon strategy, and the Klackon scripts would then need rewriting. The AI should be clever enough to notice that Klackons can build the super powerful unit and utilize them as such, or in the unmodified version, realise that Klackon units are crap and not build them - we shouldn't have to script it to tell it all that - otherwise as you pointed out, you end up with a LOT of scripts to write - which I don't believe is the right approach.
Glad you mentioned this Implode. I'm working on my 5th race lol. As a bonus, this method would allow one to quantitatively compare races that one would put into the game. If we did it right, the Klackons are probably on the low end aside from Stag Beetles, barring some kind of modification. Of course, different circumstances change the value of one's abilities (such as swimming for Lizardmen on a big land map), but it's a good overall measure. If you can have that, you may just need a few special scripts for things like "This unit is a settler, it needs protection badly", or "This unit is a siege engine, mix with other troops."

I like the direction that this AI is going, especially in regards to scouting. I've played too many games with AI that plays like it knows exactly where you are, without scouts.

I also wanted to point out that it's worth considering how long a unit takes to build before beginning. Though I appreciate that MoM is a game of domination by the most powerful units, I also know that some of the game options shift this a bit. If you're playing on one of the modes that makes units have 4x as many members, the game certainly downgrades the power heroes at least. Many of us are spoiled on the super-powerful lone units coupled with bad original MoM combat AI that we can rely on them to win any battle, or failing that, we can load. We shouldn't forget that sometimes you lose your hero to veteran halberders and you load, but that's not happening in MoM IME. Computer Gaming World, when this game came out, determined that the most cost effective units in the game were swordsmen based on a gold-production per power kind of calculation. I'm just pointing out the benefits of having many low-midrange troops as the basis of any empire, backed by those elites, rather than having a bunch of cities guarded by a single unit of paladins where they could have 5-6 more diverse troops that might actually be more powerful, and would certainly quell the city's rebels better.*

And game-wise, I'd hate to see just a few unit types spammed instead of seeing some of the diversity that the game has to offer. I don't care what the unit is, all units have a disadvantage, and it will eventually come up. When it turns sour, you won't be able to load. Adamantium Hammerhands are great, but you could be one crack's call away from being severely outmatched from their production time. One way to create diversity in one's build while still building useful troops (as I wager most of us do) is to have a simple bit of code that changes the value of a troop slightly based on how many you already have. That 11th paladin is less valuable than the 3rd longbowmen to me. The more diverse your empire is, the better armies you'll come up with, just as a human will, as some of Iluvar's discussion illustrates.

One more thing...No ships on lakes lol. Unless it's an extraordinarily large lake or something, I don't want to see a 2 square lake with 5 triremes on it unless there's a really good strategic reason (like using it as a refuge for troops staging a battle or something that no computer would ever devise). While we're on that, perhaps the land-to water ratio should affect the value of ships to some degree. I wouldn't want to see some kind of divide between naval and army units though, because MoM's current crop of ships might see some additions that make them more strategically interesting. Aside from that, any unit can be made to be sea-worthy via water walking or flight. And with flight, as we know, some ships have been known to sail the land.

So, my overall comment is to take seriously the customizable spirit of this project, and the AI for it will serve us all very well.

*I was thinking about the benefits of a Master of Orion 2 type production system, with not only a queue, but the capacity to build more than one unit in a turn if you've got the production for it. If one can build 3 swordsmen units in a turn that come out as veterans and the enemy is 2 turns away from endangering you, might come in handy. Aside from that, a couple of the races I will add rely on horde tactics, which I believe are viable in many situations in a game with good combat AI and no loading. Even if they're not viable, they're certainly fun lol.
Clythoss
Posts: 12
Joined: Fri Sep 15, 2006 2:28 pm

Re: 0.9.5 the Overland AI . I wanna help.

Post by Clythoss »

Uff...


Yup thats a long post :)

I know it would be cool to have a AI acting like a human, able to play with every new race. An Ai which does not cheat at all and knows whats the most effective way to play. An AI which sees your tactic and can react in a "i´m not falling for this" way. But let´s be serious. Even Big company´s fail to do so today. I guess you can´t get all. You have to sacrifice one the get the other. I guess the first thing falling is the AI not cheating. When i made my post i already had in mind that the AI would cheat in some way. Like Always knowing where all Cities are and how big army´s are. An AI is just a bunch of scripts and can´t decide on intuition. And an AI always doing the same thing won´t be competitive. A compromise would be that the AI still has to scout, but knows where to scout. Hey realy an AI has to know that on the other plane which it couldn´t reach till now, a player has big citys and is putting evrything into research so it can get spell of mastery some day.

I don´t know how a AI that would be able to react on modified races can be realized. But the scripts can maybe be held simple enough so it can be altered by the one´s modifying the race. The reason why i mentioned a script for every race and kind of city is that you most times end up with cities of many kinds. Rebell cities are evrywhere :) . And i have made the experience that the more scripts you do, the simpler you can hold them. But as i said before i´m no expert on this matter. But it´s the only concept i right now can clearly understand and exactly imagine how it would work. I know that this can also cause strange and dumb behavior sometimes. Let´s take C&C Kane´s wrath for example. It´s a bunch of many little scripts. One script is for spikes. As long as there are unclaimed spikes on the map it will order an engineer send it there and try to claim it. This script doesn´t interact with the rest of the AI, so a single rifleman guarding a spike can end up killing dozens of engineers in the battle.But i realy can´t imagine an AI in such a complex game like mom to work any other way. That doesn´t mean it´s not possible , it just means i can´t imagine.

As to the friendly zones. It´s a good start but there are more factors. Like when City a b c d e and f find that city x is the best city to produce defense units. while it should also build offense units. Maybe better would be some kind of rating system.For example : (it´s realy just an example the values may or may not make sense)

CIty A Needs defense:
CIty a would get the following rate
Can build Spearman +5
has 0 buildings raising exp +0
Is demanding city but no enemy´s near +0 (would be +100 if troops are able to attack the next few rounds)
0 squares away -0
low production -3
0 other units in queue -0
Buildings to build left 8 -16
Rating :-14

City b would get the following rate.
Can build Hammerheads +20
Has adamantium +10
has 2 buildings raising exp +10
24 squares away -12
has to cross plane -5
high production +10
7 other units in queue -35
buildings to build left 0 -0
Rating : -2

City c would get the following rate:
...
...
...
no direct path -9999
...
...
...

City d would get the following rate:

Can build halberds +8
has 2 buildings raising exp +10
9 squares away -4
high production +10
3 other units in queue -15
buildings to build left 0 -0

rating: +9

So the city would put a halberd in the queue. With queue i don´t mean a real queue but an intern list of requests. When the current production is finished it would then check on a similar concept which of the requests to follow next. The Defense of a Border city may or may not be more important than another unit for the planned attack force another script is requesting.

About the things on how to actualy handling attacks and prioritize targets i have made no thoughts yet. I guess these things can wait. Since you don´t plan an attack and then do the army ( or do you?) but build an attack force and then decide what to do with it would already be a very big success to have an AI which just expands and defends effectivly while building up an army. I guess this should be the first major goal. It could conquer rebell cities with a fixed army.(This would of course be replaced later in the developemt process)


Coding an AI can be a very nasty thing :) . Things that are so very obvious for a human simply isn´t for an AI.

Like your point 2 in your list. Decide what buildings to build. You think it´s done? Believe me it isn´t :) There are so many situations which one has to react to, (i´m not going to list ;) ) and not all of these situations can be thought of at the start. In the course of testing you will surely expand this section a lot.

And most important and hardest thing. Humans learn from mistakes. AI doesn´t. This will be a great challenge.

( i wished english would be my primary language i hope you understand my next question)

I would like to know how the overall concept is going to work. How does the AI know what to prioritize on when not based on many little scripts?

i realy don´t know how to formulate this question better sorry.
E=MC²+1W6
User avatar
Implode
Site Admin
Posts: 433
Joined: Fri Feb 24, 2006 3:35 am
Location: Newfoundland, Canada
Contact:

Re: 0.9.5 the Overland AI . I wanna help.

Post by Implode »

Lucern wrote:changes the value of a troop slightly based on how many you already have. That 11th paladin is less valuable than the 3rd longbowmen
That's a really neat idea, thanks. Although personally I do normally go for the ranged-units-always-being-better strategy, so end up churning out hundreds of the most elite longbowmen or slingers I can build... and really, why would I want to build anything else? The only thing that gives them a little bit of grief is units with missile immunity, which there aren't many of, so you'd have to be facing a pretty determined opponent for them to show up with a whole army of missle immune units that were still strong enough to knock you down hand-to-hand.
Clythoss wrote:I know it would be cool to have a AI acting like a human, able to play with every new race. An Ai which does not cheat at all and knows whats the most effective way to play.... When i made my post i already had in mind that the AI would cheat in some way. Like Always knowing where all Cities are and how big army´s are.
I think that's totally achievable. The AI will not cheat. I *might* let it have a few bonuses to production, research and so on like in the original, but it absolutely will not know where enemies are without scouting - its been written like that ever since I wrote the fog of war code. Every player - AI or human - has their own memory of what they've seen and they *cannot* access the server's special memory of the "true map" where the real location and size of all cities and location of all units is held.
Clythoss wrote:An AI which sees your tactic and can react in a "i´m not falling for this" way.
Sure, that's impossible. So is writing an AI that learns from its mistakes or observing the strategies of its opponents.
Clythoss wrote:But let´s be serious. Even Big company´s fail to do so today.
They're driven by lets-get-this-game-out-as-fast-as-possible-and-make-some-money, so they write an AI that's good enough to sell the game and leave it at that. They don't care about making it *really* good. Now I'm not saying I'm absolutely brilliant and am going to make it work, but I'm going to have a damn good go at it and view it as a challenge rather than being impossible.
Clythoss wrote:An AI is just a bunch of scripts and can´t decide on intuition. And an AI always doing the same thing won´t be competitive.
I think if you taught the AI to build up its strength, capture all the lairs/nodes it could, build new cities until it had an army strong enough to attack enemy wizards, then walks on in with a huge arms and kicks your butt would be competitive, even if it did it the same way each time.
Clythoss wrote:A compromise would be that the AI still has to scout, but knows where to scout.
While there's certain things human players are better than AI players at - like intuition and adaptation - there's things AI players are better than human players at, like micromanaging production and being very very thorough. You don't need to know where to scout, just scout *everywhere*. I can see the AI just flooding the map with magic spirits zooming around constantly scouting enemy activity, something a human player just could never be bothered to do.
Clythoss wrote:I don´t know how a AI that would be able to react on modified races can be realized.
I think it can, but in any case, I don't mind needing a script or two per race as long as they're really easy to do. But I'm sceptical about whether scripts it even works for MoM - the way you'd play say High Elves with 11 Life books (build an elite Troop Factory city, churn out Longbowmen, conquer the world) would be completely different to the way you'd play them with 11 Death books (park yourself in the city, max out taxes and production to summon as many Wraiths/Shadow Demons as possible, conquer the world). Its the totally dynamic nature of MoM that makes the AI really challenging to do.
Clythoss wrote:About the things on how to actualy handling attacks and prioritize targets i have made no thoughts yet. I guess these things can wait. Since you don´t plan an attack and then do the army ( or do you?) but build an attack force and then decide what to do with it
I think it needs to do both, like build your first army and try to scout around enemy cities - maybe you find city A that you think you stand a good chance of attacking, but also scout another city B that has way too much defence. You then know how big you have to make your 2nd army to stand a chance of capturing that city (especially if its the enemy capital).
Clythoss wrote:already be a very big success to have an AI which just expands and defends effectivly while building up an army. I guess this should be the first major goal.
Yup, that's the way I'm looking at it too - get that much working, see how well it works, and plan the rest from there.
Clythoss wrote:Like your point 2 in your list. Decide what buildings to build. You think it´s done?
In combination with some of the other AI elements I mentioned, yes. There's codes in the database for what type each building is, so there's buildings which are defined as "this building makes the units you build in the city better", so your troop factory would know to build those. There's other buildings which are marked as "this produces magic power/research" so non-troop factories will build those. There's buildings marked as "this reduces unrest", so it will know to build that when there's too many rebels. I don't see it needs to be cleverer than that.
Clythoss wrote:How does the AI know what to prioritize on when not based on many little scripts?
You mean know whether to worry about say building more defence, expanding or building attacking armies? In the most part it'll work out values for how badly it needs each, and then react accordingly. But I will also include some of the wizard personality types from the original, so there will be for example expansionist wizards who put more emphasis on building cities, and militarist wizards who put more emphasis on builidng armies to capture cities rather than settling their own.
Clythoss
Posts: 12
Joined: Fri Sep 15, 2006 2:28 pm

Re: 0.9.5 the Overland AI . I wanna help.

Post by Clythoss »

Implode wrote: I think that's totally achievable. The AI will not cheat. I *might* let it have a few bonuses to production, research and so on like in the original, but it absolutely will not know where enemies are without scouting - its been written like that ever since I wrote the fog of war code. Every player - AI or human - has their own memory of what they've seen and they *cannot* access the server's special memory of the "true map" where the real location and size of all cities and location of all units is held.
Well i´m not gonna argue with that.Of course i like evryone else would prefer this. :) If you think you can do it, then i think thats a great thing. A production and research bonus or unlimited food like in the original i would realy don´t like, anything but this. But i didn´t overread the "*might*".
Implode wrote:They're driven by lets-get-this-game-out-as-fast-as-possible-and-make-some-money, so they write an AI that's good enough to sell the game and leave it at that. They don't care about making it *really* good. Now I'm not saying I'm absolutely brilliant and am going to make it work, but I'm going to have a damn good go at it and view it as a challenge rather than being impossible.
Well if you can do it you would make dreams come true. Mine included. as i said before i´m totally on your side.And i will help you on your chosen path as good as i can.
Implode wrote:I think if you taught the AI to build up its strength, capture all the lairs/nodes it could, build new cities until it had an army strong enough to attack enemy wizards, then walks on in with a huge arms and kicks your butt would be competitive, even if it did it the same way each time.
Can be true or untrue, we will have to see. It could also turn out that a specific strategie will always work against AI. But i guess the more wizards on a map, the more unlikely it is that will happen.
Implode wrote:While there's certain things human players are better than AI players at - like intuition and adaptation - there's things AI players are better than human players at, like micromanaging production and being very very thorough. You don't need to know where to scout, just scout *everywhere*. I can see the AI just flooding the map with magic spirits zooming around constantly scouting enemy activity, something a human player just could never be bothered to do.
You got a good point there. My concern is just that an AI could be easily overcome economic wise. Just watch Alpha Centauri or the new Civilization 4. If you play these games on difficulty levels where the AI doesn´t cheat, You could just try to ignore spending resources on defense and reduce scouting to a minimum, and the 1 or 2 production you get more in the beginning will exponentialy turn into a huge advantage later. Maybe the AI should prioritize to attack such players, regardless of diplomatic value´s
Implode wrote:I think it can, but in any case, I don't mind needing a script or two per race as long as they're really easy to do. But I'm sceptical about whether scripts it even works for MoM - the way you'd play say High Elves with 11 Life books (build an elite Troop Factory city, churn out Longbowmen, conquer the world) would be completely different to the way you'd play them with 11 Death books (park yourself in the city, max out taxes and production to summon as many Wraiths/Shadow Demons as possible, conquer the world). Its the totally dynamic nature of MoM that makes the AI really challenging to do.
hmm... am i the only one always turtling, raising an invincible single hero and destroy the whole world, regardless what spellbooks i picked? :) . But i know where you are getting at. So maybe an Idea would be to write a different AI for every pre defined Wizard in the game? Or what do you plan to archive this?
Clythoss wrote:already be a very big success to have an AI which just expands and defends effectivly while building up an army. I guess this should be the first major goal.
Implode wrote:Yup, that's the way I'm looking at it too - get that much working, see how well it works, and plan the rest from there.
Well it´s a plan then. :) . Question is how can i help you at that? There must be something i can do.

Clythoss wrote:How does the AI know what to prioritize on when not based on many little scripts?
Implode wrote:You mean know whether to worry about say building more defence, expanding or building attacking armies? In the most part it'll work out values for how badly it needs each, and then react accordingly. But I will also include some of the wizard personality types from the original, so there will be for example expansionist wizards who put more emphasis on building cities, and militarist wizards who put more emphasis on builidng armies to capture cities rather than settling their own.
I guess we need to do a chat or something on this one. It isn´t quite what i ment. It reads something like this for me:

Me : I´m Hungry what do i do?
You: Well you find something to eat and eat it.
Me: But how do i do this?
You: You check all the ways there are to find something to eat, pick the most effective and do it.
Me: I still don´t know what to do...

But i guess we can worry about all of this later. First things First. The Base AI.Expand, defend, attack rebell cities, build up an army/task forces. How Can i best help you?
E=MC²+1W6
Virm
Posts: 63
Joined: Sat Sep 23, 2006 3:54 pm

Re: 0.9.5 the Overland AI . I wanna help.

Post by Virm »

food for thought, Implode:

the most effective way to have a highly adaptive and variant selection mechanism is to have dynamic valuation of goals (buildings, city housing, building new towns, producing army, dropping all other production in favor of researching and casting the Spell of Mastery, etc.) such that in one turn, with the information the AI has, city-building and research takes priority, but when a scout moves after that turn and discovers a full-size enemy city with two moderate to large stacks just outside it's gate the priorities shift into military (both defensive and offensive) and mana production (so it can cast the combat spells that may save it's troops).

for high adaptiveness, you'd really need to clasify everything into a series of cascading values. these values would need to have a high variability range (0-65535 or similar) with no practical upper limit for the total added value of each nested classification. by doing this you'll allow for an AI comparison within a tolerance range, such that if the current estimated value of additional military units is (roughly) equal to the estimated value of additional city-building, the AI should divide production more-or-less equally between these areas, presmably taking into account the current and potential production abilities of the cities involved.

rough classifications would probably nest into a tree, resembling something like this:

Friendly
city/territory groupings
cohesive and (somewhat) independent area for produtions and resources
distance between groupings (am I a bunch of small provinces, or my own continent?)
productivity
group production needs (more housing to increase size? more food? more defensive units?)
total available production (some form of maximizing or estimation to reach highest efficiency)
defensibility of the area
more border troops? stacks patroling the border or interior?
available resources (food, mana, gold)
able to withstand assult or seige?
relavent spells being researched?
ability to maintain standing or growing army?

Neutral (these would be values that may need special considderation and may involve wierd behaviour algorithms)
Allied Wizard
Potential to become an enemy soon (1-4 turns?)
current and ongoing gains from trade
responsibility to send aid?
neutral territory (space that's outside the estimated influence of the AI or any other specific player)
available resources (expandability)
Ability to maintain control of towers and nodes

Enemy
known enemy settlements
city sizes
distance from friendly territory
enemy province groupings
estimated enemy troops and predicted positions (based upon most recent scouting intel)
chances of successful assult on enemy troops/cities


this is by no means a comprehensive list, but by grouping related items and classifying them as friend or foe (friendly to determine growth and settlement expansion, threats to determine military growth and aggressiveness) you reach a series of numbers that can be reasonably compared to guide AI choices for general build and movement choices. It also gives you numbers which can be broken down to their components to more finely guide the micromanagement and allows for enormous diversity in the end result for AI decisions.
Coyote
Posts: 21
Joined: Mon Jun 26, 2006 11:09 pm
Location: Austin, TX

Re: 0.9.5 the Overland AI . I wanna help.

Post by Coyote »

This might be considered an AI 'cheat', but one way you could prevent the AI from building ships on lakes, is to write some sort of code along the lines 'may only build ship(s) if there is a second city adjacent to this body of water' (anywhere). The other option could be 'may only build ship(s) if this body of water has greater than x water tiles'.

The rest I'll have to think about. I may write something up later. I might also track down my old post on the topic and repost it here.

At one point I mentioned attaching certain overall strategies to certain AI's. You could add to that by writing several AI 'scripts', and then have the computer randomly pick which 'strategy' that particular AI player will use that game. That should spice things up nicely, without leaving it too repetitive. You could also allow the players to customize the picks (maybe call the scripts various personalities, and assign 'aggressive expansionist' to all the AI's? That would be an interesting experience!)

I like your description of attaching tiny bits of code to each unit. I think you could add on to that by tying code to cities 'build units with these codes' until it meets a certain quota number with those codes. And perhaps a check against turn length to build, so that if it *can't* meet its quota by say turn 20 'change city within 20 squares to build (desired) unit and move to this city'. Assuming several units have the same coded strategies, ie a group, it would be simple for the computer to randomly pick which unit with that code it chooses to build. That would lead to diversified army types, and potentially allow exotic army combinations.

I think cities tend to fit certain roles, and it will be important for the AI to be able to recognize what role a city is filling, and what conditions trigger that role. Maybe it checks an overall strategy list of 'goals' to reach, and assigns cities to meet those goals. Local conditions may trump those roles, such as 'recently captured city' and 'recently attacked city' = send troops & build fortifications! Quickly! and 'food shortage' = build settler & establish farmer city, use summoned units.

There are also various missions you can assign to a group of troups.

Scouting army: fast moving, capable of crossing unique terrain, aim for the "black" squares, with preference toward exploring "valuable" resources, and a preference toward avoiding units and cities (staying out of their visual range, if possible). The key to the scout is survival. Code to switch from scouting army to skirmishing army for a region with lots of scout mission 'failures'.

Skirmishing army: Mix of scout and assault: Aims for exploring discovered city terrain, coded to avoid large army groups and assault small army groups, and stay out of cities unless poorly fortified / small garrison.

Crack assault army: 'The best of the best' coded to move to areas where other exotic armies are spotted, and conquer any cities in that path.

Support army: Defensive, slow moving auxiliaries designed to follow the assault army or skirmishing army, even if several turns behind, and coded to enter recently captured cities OR merge or stand in front of retreating wounded crack assault armies and stop moving, giving those units time to heal.

Siege army: Pairing of one skirmish army and one support army, parks by an enemy city, and the skirmishing army assault anything that leaves the city while the support army defends the skirmish army, until one or two crack assault armies are built & can arrive.
Korenn
Posts: 22
Joined: Thu Oct 09, 2008 8:07 pm

Re: 0.9.5 the Overland AI . I wanna help.

Post by Korenn »

Ooooo, AI. always interesting. (as a coder I mean)

A big point for developing an AI: Don't reinvent the wheel unless you absolutely have to. It has already been observed that a lot of games fail at creating a good AI, but some haven't (usually because they didn't write one from scratch). That AI code is mostly proprietary unfortunately, but not all!

For a good example, look at freeciv: http://www.freeciv.org
It's an open source clone of civilization, aimed at multiplayer gaming, but it's AI is *damn* good. I'm a pretty good civ player (I like to think) but I have trouble with the 'easy' AI if I meet it soon into the game. I've never defeated the other AI's. Best of all, because it's open source, the code is there to read!

Freeciv is also very heavily moddable, to the point where they now also allow LUA scripting to do fancy stuff. Some of it may be of interest to MoMIME. One interesting design decision is that they unhooked gameplay from graphics. So you can define a new unit with stats and abilities and have it point to a new unit graphic, and an old one as default (with a string, that may or may not be defined in the tileset), but you don't actually need to have new graphics. This allows players to use completely different tilesets while playing the same game, even with modified rules. Ofcourse, having units with the same graphics is confusing so players would be encouraged to install a tileset that has graphics for it, but it's not necessary.

Some other observations about this thread:

I see everyone wants an AI that doesn't cheat. That would be awesome, but only up to 'hard' difficulty. Personally, if I pick 'impossible' as difficulty, I expect the AI to cheat. horribly. In fact, I've never understood why the different AIs in MoM fight each other on 'impossible'. They should be ganging up and whiping me from the map as fast as they possibly can. As it is, 'impossible' is badly named and quite easily beaten.

About ships on lakes: Depending on the situation, the AI doesn't actually need ships until he has somewhere to go that has water in the way. There's no reason for him to invest in ships anywhere until a) he sees other ships, b) find enemy cities on a shore, c) wants to go to somewhere that's not (easily) reachable by land or d) has no where else to go (island explored). In all of those cases, it should be easy to define in which cities the ships should be built.
Any green wizard should just mass-enchant his troops with waterwalking and invade without those silly boats 8)
Iluvalar
Posts: 46
Joined: Wed Oct 17, 2007 8:57 pm

Re: 0.9.5 the Overland AI . I wanna help.

Post by Iluvalar »

Korenn wrote:In fact, I've never understood why the different AIs in MoM fight each other on 'impossible'. They should be ganging up and whiping me from the map as fast as they possibly can.
No ! It's worst then cheating ! It's not playing well. Every AI should "play" in a way that increase their own chances to <b>win</b>. That imply that if defeating the player can give a serious advantage to one of them, they should do everything that is possible to hinder him in the process. Even trading or giving new spells and money with him, to make sure he will resist the longest time possible (As long as he is not himself a menace to them). That's what I am doing with AI player that are about to lose. I recall a game at impossible where an AI player gave me an High prayer spell, just because I was sure to lose anyway. I hate player (and AI alike) in any games that quit playing to win, and start playing to make someone else lose instead.

By "not cheating" we mean, giving them some advantages like more picks at start,gold,mana, wizard tower production. But not something weird like "they do not have to pay foods for their troops" or "knowing right at the start the position of your cities" as it is right now, since it make some tactics (famine,corruption) barely useless. Ideally giving them 2 more picks at start should be enough to make them close to impossible to defeat.
Virm
Posts: 63
Joined: Sat Sep 23, 2006 3:54 pm

Re: 0.9.5 the Overland AI . I wanna help.

Post by Virm »

I have to agree entirely with Iluvalar on this one. Especially since the whole idea of this game rewrite by Implode is to make the game truly multiplayer. If the 'Impossible' setting just makes all AI players automatically band together against the player, than what is the AI supposed to do when there's 6 AIs and 5 humans? Even if Implode throws in an option for an Allied win, it would likely be limited to a 2 or 3 player alliance as most other games with that option have done (thinking Alpha Centauri here...). The AI has to be playing for the win, because if it doesn't, somebody (possibly one of the other AIs) is going to screw it over as soon as the human(s) are gone, and there shouldn't be any real way for the AI to tell the difference between a human player and a CPU player for precisely that reason.

It's perfectly fine for harder AIs to become more and more devious and backstabbing in their methods, that's perfectly natural. By selecting a higher difficulty, you're telling the game that you want to play for higher, and therefore riskier, stakes. At the highest difficulty, the AI should be virtually perfect at macro- and micro- management of it's resources, cunning in its intelligence gathering, and deadly efficient on the battlefield. When I envision an 'Impossible' AI, I'm assuming that I'm asking to be pitted against the best and most ruthless player the game has ever seen. When I make that choice, I should be expecting to lose, quickly, and by a wide margin. The existing AI in the original MoM should pale to an extreme in comparison, but under no circumstances should that 'Impossible' AI be capable of doing anything that I couldn't do if I was in identical circumstance. As a player I'm taking on the role of a leader, and the defining characteristic of a leader is someone who can make decisions, especially under pressure. A great leader, is someone who, in making those decisions, makes the right decisions most of the time. The most difficult AI option should be, as much as possible, the best leader of all time.
Last edited by Virm on Fri Oct 31, 2008 5:47 pm, edited 1 time in total.
elliott20
Posts: 108
Joined: Tue Nov 21, 2006 8:56 pm

Re: 0.9.5 the Overland AI . I wanna help.

Post by elliott20 »

I'm not sure where this is at right now, but what if we were to again, use tags to define each resource, building, city, military unit, etc? The tag would pretty much designate their contribution towards a particular area or role. and based on these, we can calculate their worth towards a particular computer's strategy, modified by their personality.

so, let us start off with some basic axioms:

computer is always trying to gain the maximum number of resources
computer will not throw away good units in a futile fight. they will fight fights that they think they can reasonably win
while an object may have multiple roles and multiple contribution, it does have a primary usage and should be treated as such.

with that in mind, I think for one, we need to consider that a city has several strategic values: economic, military, magic, research, deterrent, and overall.

overall value of a city is basically the total worth of the city itself. It's complete utility value. Thus overall = economic + military + magic + research. This value, however, is different from wizard to wizard, depending upon their current priorities. So, say we have a wizard who values economic prowess very strongly, making it so that say, econ resources are worth double their value to him. then in this case, a city with an econ 15 mil 10 magi 10 re 10 city is far more valuable than a city with econ 5 mil 15 magi 15 re 15, even though the later city would have a higher overall value to a wizard with neutral priorities on all resources. (45 vs 50, respectively, while in the econ wizard's mind, he's looking at 60 vs. 55)

but would the wizard automatically jump in with his armies? well, it depends on the deterrent factor. the deterrent factor is, as the name suggests, a value that shows how much is stopping the AI from attacking. things that can effect this factor? military force size, diplomatic status, personality, and other factors that I just can't seem to pull out of my head at the moment.

But then, so what if you have deterrent factor? how does it actually stop someone from invading? well, it also depends on the computer's own invasion force. If the computer feels confident in his ability to invade and hold the city, he will invade. That is, we need to figure out the invasion capability of the computer. How do we do this? we take the AI's localized forces (using Implode's algorithm to calculate what constitutes a unit that is capable of participating in the fight), and cross it with other modifiers like spells and heroes, and off you go. If it's higher, than the computer will at least know he has a mathematical advantage in the fight. And at higher level difficulties, the computer should pretty much be running this kind of analysis at every step of the way.
elliott20
Posts: 108
Joined: Tue Nov 21, 2006 8:56 pm

Re: 0.9.5 the Overland AI . I wanna help.

Post by elliott20 »

so how do you know how much each units is worth on the invasion scale? a flat calculation will not do here, as other things like spells will change that equation significantly. But at the same time, even a computer has limited resources on what kind of set up he can run with. this is where it can get tricky, as we'll be asking the computer to try to calculate various set ups and then using the best option as his best foot forward calculation. basically, we're asking the computer to mathematically optimize as oppose to tell him to use a straight formula. And again, depending upon how we define the value of each unit, we can end up with some very strange armies, so everything is tentative to testing.

but at it's core, I think we need to consider military roles.

in MoM, I can see several base roles: missile, shock troop, defensive, controller, buffer, splash damage, focus damage, healer, hero, and finally transport.

what does each role mean though, mathematically? well for one, tally up your stack's capability quotient essentially tells you what is the strength of that stack. These are strengths that I think a lot of us take for granted but a computer just cannot put together that well. the reason why each different unit type has different value calculation? well, so that we don't end up with a false sense of what our stack is capable of. After all, if we have 9 missile guys stacked together, with their missile value at 2, and shock trooper value at 1, then the end army result would be missile capability: 18, shock trooper 9. This means we'd still be able to do well against certain armies right? wrong. you don't usually use missile guys to do melee combat unless you absolutely have to, and to take that into account as a strength could be dangerous.

missile: as it suggests, your ability to do damage via missiles. this includes the various wizard standard attacks, arrows, etc. What does it mean when a troop has this tag? it means their primarily role is to shoot, shoot and shoot some more. The rest of their stats like armor and all that will not matter nearly as much as they shouldn't be getting into melee combat anyway.

shock troops: these are units whose primary role is dish out damage via close hand combat. And so for these troops, the ability to deal damage via close hand combat is probably as important as the ability to take damage. defense icons are worth more, and so are hits.

defensive: these troops are basically just there to take damage and nothing more. I'm not quite aware if any of these kind of units exist, but just in case they do, I'd make a tag for them. Their role? to stand there and soak up the damage so the other units can do what they need to do. Primarily, they protect the ranged guys and casters from other melee units. In this case, their health and defense icons will give them the most value.

controller: these units serve a different function. Their value lies in their ability to alter the battlefield in stack's favor. However, unlike the buffer, they do so by doing things to enemy troops. i.e. they cast webs on enemies, they create walls that prevent movement, etc. These character are probably one of the hardest to value as their value is dependent almost entirely upon what their shtick is. for spiders, that would be the web ability. My best guess, however, is to not calculate their worth by itself, but rather by what it can do to enemy forces. In the case of web, for example, it's primary ability is to temporarily remove someone from the fight. So the target matters. In which case, the web ability doesn't add to a stacks value, but rather it removes value from another stack. so, on a battlefield where the controller can target only peons, they're not really all that of a big deal. they're just there, and pretty much they are worth about as much as their combat abilities. this, of course, means that the controller cannot be valued on it's own, and it could make things really messy.

buffers: buffers are units with the ability to make other units fight better. (i.e. by giving them bonus swords, bonus to hit, or some other area) valuing buffers basically is their own unit worth + the total bonuses they give the stack. So, a character that gives everyone on the field a +1 to hit (like an angel, for example) might not be worth as much in a stack of 1 spearmen as opposed to a stack of 7 barbarians. the inverse of this, the debuffer, works on the same principle as the controller in terms of valuation.

splash damage: much like controller, these guys are guys who can do damage to a lot of units at the same time. Their valuation is based on how much damage they can do, multiplied by how many times they can do it, multiplied by how many people they can do it to.

focus damage: the inverse of the splash damage, these guys have abilities that can only target one unit, but is deadly to that unit. i.e. crack call, psionic blasts, firebolt.

healer: valued at the amount of damage they can prevent.

hero: heroes are the wild cards valuation and thus they are worth the total summation of their abilities calculated by how well they fulfill each role. So, Elana the Priestess will get value from both being a healer, a buffer, and other abilities.

transport: while extremely crucial, does not contribute to the battle directly. the value of transport, therefore, should be an "or" statement kind of thing that allows the wizard to add in OTHER units that normally it wouldn't be able to be part of the calculation to join in. Also, some transport do have limited combat ability.
Post Reply