23
Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Embed Size (px)

Citation preview

Page 1: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Artificial Intelligence in Game Design

Intelligent Decision Making and Decision Trees

Page 2: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Decision Making

• Based on internal and external information

• Defines a current action (“eat food”)

• Changes world and internal state

“I am hungry” “There is food nearby”

“I am not hungry”“Food nearby is gone”

Page 3: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

“Intelligent Agent” Approach

• Reflex agentNo memory, just “if-then” rules

• Memory-based agentAlso based on current state

• Goal-based agentChooses actions that best help meet current goal

• Utility-based agentBalances multiple weighted goals, choosing actions that give best overall state Sims

Goal-based planning

input rules action

input rules action

memory

Page 4: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Reflex Agents

• Example: “orc” reflex agent

if hitPoints < 5 then run away from playerif distance to player < 2 units then attack playerif player visible then run towards playerelse move in random direction

Internal state

External state

Page 6: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Reflex Agents

• Must consider cost of gathering inputs

if hitPoints < 5 then run away from playerif distance to player < 2 units then attack playerif player visible

then run towards playerelse move in random direction

This requires complex computations

if player in same room or distance to player < 5 units

Page 7: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Hierarchical Rules

• Actions often hierarchical

if hitPoints < 5 then moveTowards(player)if distance to player < 2 units then attack(player)if player visible then moveTowards(player)else moveTowards(random)

These will call complex navigation subroutines to implement the action

Page 8: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Hierarchical Rules

• Lowest level = actions supported by game engine

void moveTowards(object) if not facing object then turn towards object else if facing obstacle at distance < 2 units then turn right or left at random move forward else move forward

Page 9: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Designing Hierarchies

• Strategy Level– What goal does character attempt to meet?

• Build, attack, negotiate

• Tactical Level– How does character meet current goal?

• Which city to attack• Which resources to use

• Motion Level– What action does character take this turn?

• Move forward, left, right…

Page 10: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Designing Hierarchies

• Task based– Major tasks NPC performs

• Guard• Patrol• Defend

– Steps in tasks• Wait• Chase• …

– …– Motion

• Turn• Move• …

High level character design team (works with game designers)

Character motion team(works with animation team)

Page 12: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Level of Detail in AI• Only use full AI when necessary

– Fast approximations in other situations– Often when NPCs “off screen”

Use full passing AI for cars visible to player

Simple rule for cars not visible to player“Faster car has 75% chance of successful pass”

Page 13: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Swarm Intelligence

• Simple NPCs in groups can appear to cooperate

• Decision example:if no other player shooting, I shootif in open, run for cover and shoutif in cover, reload and wait

• Orc motion example:…if NPC blocking path to player then run sidewayselse run towards player…

NPCs appear to be covering one another and coordinating attack!

Page 15: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Randomness in Games

• Goal: Randomness should not appear random• Best solution: Randomness used to “tweak”

existing rules

if hitPoints < 5 then run away from playerelse if hitPoints < 10 and random# < 0.5

then run away from player

else attack player

Unpredictable behavior in borderline situations

Logical behavior in extremes

Page 16: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Potential Problems with Randomness

• Possibly many parameters to tweak– How do we know these are the best probabilities to use?

• Difficult to thoroughly test– Combinations of probabilities may create a bad case (i.e.

easy win) which is possible but very unlikely– That case will be found by some player

Confident Angry Frightened

Attack Left 40% 60% 30%

Attack Right 40% 35% 20%

Defend 20% 5% 50%

Page 17: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Prioritization

Problem:• Multiple rules may fire with contradictory actions

– Problem if rules added by multiple developers(side effects)

if hitPoints < 5 then run away from playerif distance to player < 2 units then attack player

What if next to player and have low hit points?

Page 18: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Decision Trees

• Simple tree traversal– Node = question– Branch to follow

= answer– Leaf = final action

to take

Hit points < 5?

yes no

Obstacle betweenmyself and player?

yes

hide

no

run

Within one unit of player?

yes

attack

no

Path to playerclear?

yes

run towardsplayer

no

runsideways

Page 19: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Decision Trees

• Not necessarily binary• Can merge branches

Hit points

HP < 5

light

run away

Within one unit of player?

heavy

attack

HP ≥ 10

yes

holdposition

no

runtowardsplayer

Weapon type

5 ≤ HP < 10

Page 20: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Designing Decision Trees

• Identify possible actions (leafs)• Identify internal/external knowledge for choosing action• Order questions in tree:

– Crucial factors (health, etc.)– Ease of gathering knowledge (fastest first)

yes

Player visible?

no

attack

yes

hide

patrol

HP < 5?

no

yes

Player visible?

no

attack

yes

hide

patrolHP < 5?

no

Page 21: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Randomness in Decision Trees

• Make decisions at some nodes based on random number

Math.random() < 0.5

yes

defend

no

Math.random() < 0.2

yes

Swing swordfrom left

no

Swing swordfrom right

Page 22: Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees

Randomness in Decision Trees

• Problem: Randomness in high level decisions

• Stands still or patrol for a few frames at a time• Better if it decided to do one and keep doing it for a while

Math.random() < 0.4

yes

Stand still

no

Patrol