• Advertisement
Sign in to follow this  

How to make a AI choose?

This topic is 1202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have very little experience in AI programing and was wondering how I would make the AI choose the best option for it's self.

 

example:

 

Small Sword     = 1   dmg   /cost: 1 point  

 

Medium Sword = 5   dmg    /cost: 5 points

 

Large Sword    = 15 dmg    /cost: 10 points

 

Total points = 12

 

So any player seeing this will know that the large sword is the better option, but I want the AI to know this.

 

I can't just tell it to use the highest costing attack because the values will be random.

I don't only want it to compare attacks it should also be able to decide what enemy to attack if there is more than one?

Share this post


Link to post
Share on other sites
Advertisement


you want the AI to select the weapon with the best value, where value = dmg/cost.

 

This does seam a lot simpler and I guess for healing items mixed in I could check -1*dmg.

 

Thanks for all the help, it seams that I can work something out from here.

Share this post


Link to post
Share on other sites

This does seam a lot simpler and I guess for healing items mixed in I could check -1*dmg.

 

are you selecting items to use, or buy?

 

for use, you first want to check your state:

1. i need to retreat and heal, or

2. i'm still ok, press on with the attack.

 

in case 1, you select the best healing item.

in case 2 you select the best weapon.

 

but you want a layered approach:

1. decide what in general you need to do  ( attack vs heal).

2. decide the particulars of how to do it  ( use best search algo to select best wpn or best healing item).

 

so your AI might first decide on attack vs heal, then invoke one of two sub-AI's: one that specializes in attack, the other in healing.

 

divide and conquer.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites


but you want a layered approach:

 

So It should be similar to a card battle game phases?

 

First phase:

Check to heal or attack.

Check target.

 

Second phase:

Check for most effective attack or ability.

 

Last phase:

Check to repeat First phase or pass.

 

With each phase based on the "best search" code.

Maybe even a sub step to decide what effect like poison or stun is best?

Share this post


Link to post
Share on other sites

So It should be similar to a card battle game phases?

 

not too familiar with those, but i get the idea, similar to multi-phase combat turns in tabletop wargames.

 

phases or layers, whatever you want to call it, its a MULTI-STEP process.

 

you basically follow the line of logic you yourself would use in combat if you had the luxury of time to contemplate your move.

 

first, you'd see what condition you were in, whether you had to heal or not.

if you don't have to heal, you might then check for insurmountable odds, calling for a retreat.

if you don't have to heal or retreat, then attack.

 

the result of this first "layer" or "phase" of decision making results in one of three outputs:  heal, retreat, or attack.

 

you then call the appropriate specialty AI subroutine: heal, retreat, or attack. these would be your second layer or phase of AI.

 

lets say you called the attack subroutine as an example.

 

the attack subroutine would select a target and a weapon, steer and move the unit, and trigger the attack action at the appropriate moment.

 

the attack subroutine might in turn call a lower level AI subroutines:  one for select target, one for select weapon, one for steering, one for movement, and one for triggering the attack. these would be your third  layer of AI. some of these types of routines, such as select weapon, might use the best search algo.

 

the same idea would hold for the healing AI. it would have a lower level "select healing item" subroutine, the same way the attack AI has a "select weapon" subroutine.

 

so the top later would be the "what should i do?" AI: attack, heal, or retreat.

 

the second layer would be the attack, heal, and retreat subroutines.

 

the third layer would be the low level routines like select weapon, target, healing item, etc.

 

a more concrete example might help. i'll post something from Caveman.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

 

Enter utility-based AI.

 

Thank's this does look like what I want, but it seems like a lot to learn.

Will I really need to know this for a gaming AI?

 

 

It is the fastest-growing AI architecture out there. Between behavior trees and utility systems, you can handle most of the AI needs out there.

Share this post


Link to post
Share on other sites

Alright so AI is basically logic. Unless you have some syntax or impanation problem you need to set priorities and think about how you want the AI to think.

 

 

Here is something I would try.

 

 

First I would read the health of the player to see what is best suited for killing them.If the player has really high health and a single big sword swing won't give the AI an advantage I would make it choose second best to save points If the player is on it's last leg about to die I would have the AI go all out to ensure the player will die If the player has a chance to be killed by a big sword swing but the AI doesn't have enough points I would make it choose the light attack to build up quickly

 

AI is just logic and you should think about what's the most effective way to get the result you want which mainly involve killing the player.

Share this post


Link to post
Share on other sites

Thank's everyone for all the help.

I now have a npcs that walk around and can engage in combat, the layered approach produced a great AI with out too much of a struggle.

 


It is the fastest-growing AI architecture out there. Between behavior trees and utility systems, you can handle most of the AI needs out there.

 

I have been reading up whenever I can, it's been really interesting.

I hope to implement it into my game at some time, just need to learn more.

 


First I would read the health of the player to see what is best suited for killing them.If the player has really high health and a single big sword swing won't give the AI an advantage I would make it choose second best to save points If the player is on it's last leg about to die I would have the AI go all out to ensure the player will die If the player has a chance to be killed by a big sword swing but the AI doesn't have enough points I would make it choose the light attack to build up quickly

 

I will consider this for a hard mode.

At the moment my AI always makes the best attack choice, making it really hard to win when you accidentally selected the wrong option or when you are out numbered by even one enemy.

To solve the problem I weakened the attack of regular enemy's, it's still the same for boss battles or important battles, on easy the opponent has a one out of five chance of choosing the worst possible attack.

Share this post


Link to post
Share on other sites

Game mechanics are also often more complicated

 

Such as : the large swords swings slower - taking more time for the complete cycle, thus it is not  damage-per-swing but damage-over-time.

 

This also may tie into other game mechanics like having to do another action quickly and that longer swing now delays doing some other needed operation quickly.

 

Another might be BIG swords take 2 hands when with a small the other hand could hold a shield or second weapon.

 

The bigger sword may have more reach than a smaller one or it may deliver more power to a strike that isnt soaked off as much by certain kinds of armor (or be more useful to block strikes from a equivalent large sword because of its mass)

 

DIfferent swords often have slash moves or thrusting moves  

 

A smaller weapon can be handier in a close fight.

 

Consider similarly for other weapon types available.

 

So the decision can be more complex and be effected by the situation (and thus the logic growing quite a bit more)

 

Share this post


Link to post
Share on other sites
I have made it rather obvious that I am a major fan of fuzzy logic, hehe.

The term "better" is a fuzzy term. What is better in one case, might not be better in another case. Perhaps in CQC the short sword is better, and at a longer distance, the larger sword is better.

So you have two sets. A long distance set, and a short distance set. In the set of "better at long distance", the short sword will have the mebership value of 0, and the long sword will have the membership value of 1. Any sword with a length in-between will have varying "belongingness" to the set (they will be more or less better for long distance attacks.)

Then you have the short distance set where the short sword has a membership value of 1, and the long sword has a mebership value of 0.

So any new sword will be both better and worse for any given situation, depending on the situation.

Share this post


Link to post
Share on other sites

Just try them all :)

In complex games with many arbitrary factors, using a MCTS (Google it) search can be very effective. 

 

You don't personally have to have any idea what strategy is best, and you won't have to rejigger

your whole strategy every time something changes in the game.

Share this post


Link to post
Share on other sites

Just try them all smile.png

In complex games with many arbitrary factors...

 

Hi,

 

I usually use a different goal functions and different goal value for different situations and different strategies. This function is usually selected from a possible goal value in the knowledge base table.

 

Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement