Simple decision making examples

Decision making task

Today, we will answer to a simple decision making exercise :

a) Draw a decision tree for an AI bot that must exhibit the following 
behaviours:
i)      If there is no enemy in sight, random wander
ii)     If an enemy is in sight and has more health than bot, then flee
iii)    In an enemy is in sight and has less health than bot, then attack
iv)     If the bot is at less than 50% health take healing
b) Draw a state machine for a guard with the following behaviours:
i)      Patrol
ii)     If an intruder is heard, search for a few minutes then resume patrol
iii)    If an intruder is seen, alert other guards and then attack
iv)     If the intruder is captured or killed, resume patrol
c) With the previous state machine, adapt it to be a hierarchical state 
machine.
i)      Expand the search state to move closer to the sound, then if nothing is
        seen, to randomly select a direction to search. If a sound is heard again 
        move in that direction. Maintain this pattern for 5 minutes before 
        resuming patrol state.
ii)     Expand the alert/attack state to use missile weapons if the target is 
        beyond a certain range otherwise select a melee weapon and close to 
        melee range.

a) Decision tree example for an AI bot

decision-tree-for-an-ai

Actions are framed while conditions are surrounded.

In order to make this decision tree work, at the end of each actions, we have to repeat this sequence of choices usually by using a loop where the bot will check every time the decision tree to avoid it being stuck in one action. For example, here, if the enemy has more health, bot will attack it, but when its health will be lower than enemy’s health, the bot will flee and then heal himself when the enemy will not be in sight. Decision tree are good representation for a simple AI, and they are organized in a hierarchical order.

b) State machine example for a guard

statemachine.jpgSame here, we have to repeat actions until something happens to make this state machine working. The difference with the previous decision making pattern is that the AI will carry on doing the same thing until something will trigger another state. Here, if the guard sees an intruder while patrolling, he will still be alerting others guards until one guard (or more ?) is alerted. State machine can be more realistic than decision tree because the bot will memorize that a certain event happened and will perform a certain action for a while. Indeed, if you provoke a bull, it will still be angry for a while even if you stopped provoking him.

c) Hierarchical state machine example for a guard

statemachine2

And this is how state machines become hierarchical state machines so that several actions can still be within a same state.

The pros for States Machines is that there are simple, easy to design and can still make your AI expressive but the cons are that the numbers of states and transitions can grow really fast and there is not shades in transitions or actions (is the noise I’m hearing far away ? I want to attack the nearest enemy)

For more complex AI the following methods can be used like Fuzzy logic or Neural Networks.

References :

State Machine article

Fuzzy logic (wikipedia)

what is fuzzy logic

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s