How to create a fully work AI?

Status
Not open for further replies.
Level 4
Joined
Jan 1, 2016
Messages
77
Hey again dudes, i think that you are tired to see this kid writing a lot of posts, but what can i do, in noob in everything i do ;/

But this is not the case, i'm here now to ask you how can i make a AI to my map, a fully work AI, like dota 1 with AI.
If you can't tell me in this thread, i'll have to ask you to send me a tutorial that i can understand :ogre_haosis: Thanks!
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
How you implement an AI all depends on what sort of map you are making.

If it is an AoS (which by you referencing DotA Allstars I am guessing it is) then you need a trigger system to control their hero.

Fundamentally there is a periodic "think" trigger which is run for the player. This should decide the overall goals of the player and update AI state and issue orders when appropriate.

A simple example one for an AoS might look at gold and health. If sate is "idle" and health >80% then order to lane and set state to "going to lane". If at lane and state is "going to lane" then set state to "laneing". If state is "laneing" and gold > 1,000 then set state to "going to shop" and order to shop. If state is "going to shop" and unit is at shop then run some shopping logic (AI could buy all the stuff instantly) and set state to "idle". If state is "laneing" and health <25% then set state to "retreating" and order to health fountain. If state is "retreating" and at fountain then set state to "idle".

As one can guess this thinking process is a simple state machine. It will certainly do something and be harder to kill than "beginner" AI in Heroes of the Storm but it will still be easy to kill and show absolutely no map awareness at all.

When in each state you make sure it progresses towards another state. For example if it is in the "retreating" state you make sure it is retreating every time the think process is run, and if it is not then you re-issue the order to run back to base.

One could expand it by adding more states to deal with more cases. For example you might add an "off-lane" state for dealing with creeps, or a "prowling" state for hunting down wandering or low health heroes. One could add states unique to each hero to represent capabilities of heroes, eg a pushing hero might not have a "prowling" state as they are terrible at chasing and killing other heroes. You could also add extra break out states, for example if "retreating" and it wanders across a hero which is as good as dead then you might want to switch to "prowling". You could also add additional state types such as a "victim" unit so that when in a "prowling" state you could focus and chase down a specific target.

At some stage you will have to deal with the possibility of deciding which state to move into from a current state. For example when "retreating" that low health hero could be an easy victim, but also it could still be strong enough to turn the tables on the player. In this case you might want to consider what hero it is, its current health and its item values and compare them with yours and work out a probability of "how successful" attacking it will be. If there is a good success rate then switch to "prowl", otherwise keep "retreating". If the success rate is very bad, to the point it is very likely to try and kill the hero, you might want to move into another state "evade" during which you use escape skills and avoid running into the hero. This is sort of fuzzy logic and is a simple for of decision network. You could adjust the results by adding even more factors such as enemy reinforcements, allied reinforcements, self-sacrifice bonuses (eg if it can stop them from killing 2 other heroes) etc.

The main "states" can be thought of as activities. In a true AI the states would be much more abstract and actuator commands issued as the result of the command choosen being the most favourable to send based on previous states and the current sensor input. Such an implementation will potentially create an AI with the capabilities of a human however it is extremely complex, to the point it is not viable with current technology (hence why terminators have not killed us all, yet). Instead you use the activity abstraction to make decision making much easier and simpler to implement. The entire AI then becomes selecting and configuring the right activities based on sensor input and current activity state, which is the sort of system I described above. It still makes intelligent decisions, but at a high level as opposed to a truly intelligent system such as yourself which has to make decisions ultimately at a very low level (such as move muscles to press hotkey, move mouse to move cursor to right place of screen etc).

Working with this global think loop you have a "tactical" think loop. Where as the global think loop is responsible for macro (overall game strategy), the tactical think loop is responsible for micro (individual unit use). The tactical think loop is responsible for getting the hero to interact with what is around it, eg casting abilities, avoiding enemy abilities or last hitting. This can be implemented a lot simpler than the global think loop as it might not even need persistent state, making all decisions at any given time based purely on the percepts available to it at that given tick.

An example tactical AI loop could be as follows. If the hero is closer to the enemy core than nearby minions, then order it towards friendly core a bit (stay behind minions). If there are 7 units bunched together or 2 heroes then cast Blizzard on them. If health is below 50% then cast Death Pact on the lowest health friendly minion. If a friendly minion has health less than 10% then attack it (kill deny). If an enemy minion has health less than 10% then attack it (last hit). If there is an AoE danger marker (you will need to make such a system yourself) and unit is inside the area then order it to move (or blink) outside the AoE danger marker area (avoid AoE abilities).

Your tactical decision loop can vary based on the current activity the global loop decides. So for example in the "retreating" state you might want to hit Windwalk if enemies are nearby or Blink over enemies if they walk at you. In the "Prowl" state you might want to save kill securing moves until the victim is low health. If in the "retreating" state you might be more liberal with ability use, casting expensive area moves on single targets chasing you, since your mana will be replenished when you heal.

One could make a simple list of tests, ordered by priority of execution, for the tactical AI. I think this is how Heroes of the Storm implements it and is how StarCraft II units work (so the idea is pretty solid and should work in WC3). Of course one could use a decision network to come to which action is the best to create as that could technically be more correct however it is also a lot more complicated and pretty solid results can be obtained from a simple sequential list of tests.

There are several reasons why it is good to divide the thinking process. The first is modularity, they can be developed separately from each other. Then there is reuse, since generally global think loops could be recycled between heroes where as each hero likely needs its own tactical think loop to use its abilities appropriately. Then there is reducing overhead, since global think loops can have a period of 1 to 10 seconds where as a tactical think loop might have a period of 0.1 to 1 second. Finally there is the object relationship, since there is only ever 1 global loop but depending on game there may be multiple tactical loops per player for example in a dual hero mode (one for each hero) or if a summon is involved (one for hero and one for summon).

In the end the AI will never be perfect. It will always be exploitable, and act stupid at times. However it can still be good enough to give newbies a run for their money which probably justifies all the work.
 
Level 4
Joined
Jan 1, 2016
Messages
77
How you implement an AI all depends on what sort of map you are making.

If it is an AoS (which by you referencing DotA Allstars I am guessing it is) then you need a trigger system to control their hero.
It is an Arena map. When i say i want to make like dota, i want they to use spells, attack enemies, move, defend, recognize allies, enemies etc.

Thanks a lot for the help, i'll try to make this.
EDIT spot:
If you guys already saw a map called samurai Brawl (if you don't you should, its very cool), i want to make like him, an AI like that.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
It is an Arena map. When i say i want to make like dota, i want they to use spells, attack enemies, move, defend, recognize allies, enemies etc.
The same principles apply as I described above. Just the various states (activities) are different to reflect those you will perform in an arena map rather than in an Aeon of Strife.

A simple one might have 2 activity states, "retreat" and "hunt". When in "retreat" run back to safe area or a healing spot. When in "hunt" move to a random creep site or attack any nearby players. Change between "hunt" and "retreat" is hitpoint percent or mana percent triggered, with some cutoff like 30% to run away and 90% to start hunting again. You might add more activities like specifically hunting down players, or hunting powerful boss mobs if desired with appropriate change overs.

Tactical AI is then customized for each hero to use their abilities. For example if your hero has Storm Bolt then search if there are any nearby heroes, and if so order it to Storm Bolt them when possible. An AoE move like Flame Strike might be used if it will hit at least 3 or 5 enemeies. Moves like Divine Shield may only be used in emergencies such as when "Retreat" activity is active.

Your global AI loop may also have to think about learning hero skills (if applicable) and item management (if applicable). Actual learning could be executed by tactical AI loop based on parameters set from the global loop every time the hero has a free skill point. Item management probably needs its own state and should be executed every time sensible (eg after some items drop, or if significant gold is accumulated).

A good idea to make skills and items easier to manage is hard-coding sequenced acquisition tables. When the hero has skill points it learns the abilities in the sequence you specified in the table. Items are also acquired in the sequence you specify in the item table, with any non-sequence items being sold or discarded when the space is required for an item in the sequence. A hero could have multiple such tables for different battlefield cases. For example if faced with a lot of Assassin type heroes then it may learn more defensive orientated skills and buy toughness or escape related items to become harder to kill.
 
[...] but what can i do, in noob in everything i do ;/
I want to be really honest with you:
Without a certain level of scripting experience, your AI will probably suck and be exploitable as hell.

DSG basicly outlined how most AI systems work in strategy games (by having a dynamic weighted decision table). As you can see from the length of his post alone, it's pretty complicated.
Even professional game studios struggle with good AI.


I don't want to decourage you from trying it, but if you consider yourself a "noob in everything", you are probably better of trying to find other options for your game.

For example, you could compensate the team with missing players with other benefits like a higher income or handicap the team with more players.
 

Chaosy

Tutorial Reviewer
Level 41
Joined
Jun 9, 2011
Messages
13,239
For example, you could compensate the team with missing players with other benefits like a higher income or handicap the team with more players.

I did this in my castle fight-ish map. I basically gave twice the gold income periodically and three times as much from kills. On higher difficulties I even buffed the units. The AI used is really simple but due having so many advantages it proved somewhat troublesome to defeat it :)
 
I did this in my castle fight-ish map. I basically gave twice the gold income periodically and three times as much from kills. On higher difficulties I even buffed the units. The AI used is really simple but due having so many advantages it proved somewhat troublesome to defeat it :)
It requires a lot of balancing, true, but it's still easier to handle than having a crippled AI bot anyway.

Heck, even blizzard struggled to create a good melee AI in Starcraft II so that they essentially gave up and added the "cheater" difficulty to the AI to allow computers to compete with gold and diamond-league players.
 
Level 4
Joined
Jan 1, 2016
Messages
77
I want to be really honest with you:
Without a certain level of scripting experience, your AI will probably suck and be exploitable as hell.

DSG basicly outlined how most AI systems work in strategy games (by having a dynamic weighted decision table). As you can see from the length of his post alone, it's pretty complicated.
Even professional game studios struggle with good AI.


I don't want to decourage you from trying it, but if you consider yourself a "noob in everything", you are probably better of trying to find other options for your game.

For example, you could compensate the team with missing players with other benefits like a higher income or handicap the team with more players.

I know something about, i just need make them walk (or run), attack, use spells, defend and retreat. Just this i need to make. I'm collecting every information i can about the AI, everything you know about tell me, that guy who helped me gave a kickstarter, in other post, other guy told me how to use spells, and etc.

If you can tell me something about, just do it!
Edit: Tell me the most simple way you can. Don't tell me in a way i can understand, tell me in the most simple that you can.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,285
Edit: Tell me the most simple way you can. Don't tell me in a way i can understand, tell me in the most simple that you can.
The simplest way you can do it is to start from the ground level and slowly extend it as your understanding grows.

For example create a trigger with a periodic event set to run every 1 second. Use a pre-placed AI controlled unit for now (replace with variable later). Start by simply ordering it around to a random enemy unit. Congratulations you have made a very simple but extremely stupid AI.

One could expand on this by adding a level check to make sure the enemies you order it to are equal or lower than its level so it does not run into that boss nearby and suicide. It is now a slightly less stupid AI.

Time for some abilities. Add a check to the trigger for if there are any enemy units within 500 range and cast that single target damage ability and that area damage ability at them. It is now using abilities to, although very stupidly.

Maybe improve the abilities by only using the single target on heroes and the area one if it can hit 2-3 units. This needs additional logic (conditions in the if statement). The AI is now less wasteful with its abilities.

Time to stop the AI from committing suicide all the time. Add a check for if its health is less than 30%, if so then retreat to the fountain. Only if it is greater than 30% do you do all the above stuff, since survival comes before killing stuff. Now our AI will even appear to have some sense of self-preservation. Man they certainly grow up fast!

Do not stop there, extend to your hearts content. Eventually you might want to tidy the code up a bit with concepts such as states and such otherwise you end up with an unreadable mess of flow control statements. For better tactical performance you might want a separate, high-frequency trigger so it makes more APM. It will never be perfect, but if you find flaws with its behaviour you can try to extend it to fix it.
 
Level 13
Joined
Mar 19, 2010
Messages
870
Hi, it's interesting that someone want to do the same like me. I'm not sure if i can help you but i'm working since Nov. last year on a hero AI for my map Forsaken Bastion's Fall. It's 100% jass/vJass but maybe it can help u to understand how to write an AI.

All information about the AI can be found in my signature (source code --> src/AI-Systems).
If u have question just drop me a line ;)

Best Reg
 
I know something about, i just need make them walk (or run), attack, use spells, defend and retreat. Just this i need to make.
Let me give you an analogy to what you just said:

"I had biology in school. I just need to understand how the human genome works and what each protein means in it. Just this!"

What you described sounds simple on paper. But that doesn't mean that this is easy to make.

Take DSG's example above: This is simple to make, yes, but the AI is also extremely stupid. So stupid that your AI units will basicly be cannon fodder.
And the twist is: for every noticable layer of "intelligence" added to your AI, the complexity increases tenfold.
 
Status
Not open for further replies.
Top