Title: Artificial Intelligence in Game Design
1Artificial Intelligence in Game Design
- Advanced Planning Algorithms
2Planning and Preconditions
- Actions may have preconditions before they can be
taken - Multiple actions often required to meet needs
Action
Preconditions
Postconditions
Action
Preconditions which character meets
Postconditions
meets
Action
Preconditions
Postconditions meet need
3Planning and Preconditions
Get food
Uncooked food in fridge
Have uncooked food
meets
Cook food in microwave
Have uncooked food Have microwave
Have cooked food
meets
Eat food
Have cooked food
Hunger - 5
4STRIPS Planning
- Simple planning for worlds with preconditions on
actions - Stanford research intelligent planning system
- Prohibitively expensive for complex problems
(thousands of possible actions, prerequisites,
etc.) - Widely used in games where actions
limited(Quake, Age of Empires, etc.) - Plan of attack for single NPC
- Series of actions to meet large-scale
goal(increase number of citizens farming)
Action
Preconditions
Postconditions
5STRIPS Planning
- Regressive searching Working backwards from
goals to preconditions - goallist unmet needs
- while (unmet goals in goallist)
- choose goal G from goallist
- select action A with G in postconditions
- remove G from goallist
- add unmet preconditions of A to goallist
6STRIPS Planning Example
- Initial goal
- Choose attack action which meets initial goal
- Precondition added to list
- Choose load weapon to meet precondition
- Its precondition added
- That precondition already true, so plan complete
7Selecting Actions
- Different characters ? Different set of possible
actions - Algorithm selects from that characters actions
which meet prerequisites
Get Key
Key in current room
Door unlocked
Open Door
Door unlocked
Be in room
Smash Door
Be in room
8Planning as Search
- Can take form of search tree
- Depth-limited search
- Must backtrack if current plan has unmeetable
preconditions - Adds appearance of intelligence
- Can be expensive if happens too often
No available action has this as postcondition
Key in current room
Get Key
Door unlocked
Open Door
Door unlocked
Backtrack and try this action
Pick Lock
Door unlocked
9Planning as A Search
- Can use A to choose next action to add to tree
- Cost of path found so far
- Actions assigned costs
- Cost of rest of plan from current state
sum of actions from
current state to goal - Heuristic estimate of rest of path
- Number of unmet preconditions
- Each possibly weighted by some expected cost
measure
Action
Action
Precondition
Goal
Precondition
Precondition
10Planning as A Search
- Example
- Open Door action has cost 1
- Get Key action has cost 2
- Pick Lock action has cost 5
- Key in current room precondition estimated cost
1
Try first since estimated path cost 4
Key in current room
Get Key
Door unlocked
Open Door
Door unlocked
Try next since estimated path cost 6
Pick Lock
Door unlocked
11Planning as Tree Building
- Actions with multiple preconditions represented
as trees - Actions with preconditions ? Nodes with
preconditions as branches - Actions with no preconditions ? Leafs
Have 1000 wood
Build Cannon Factory
Order troops to collect 1000 wood
Have 1000 iron
Build Cannons
Order troops to collect 100 wood
Mine iron
Build Iron Mine
Produce Cannons in Factory
Order troops to mine 1000 iron
12Planning and Scheduling
- Key question Scheduling actions that result from
plan - Some branches may have to be accomplished before
others - Some branches can be done in parallel
- Partial order planning used
- Determine what must happen before what (like
STRIPS) - Dont commit to a plan order until necessary
during implementation
Build Cannon Factory
Order troops to collect 1000 wood
Can be done in parallel
Build Cannons
preceeds
Order troops to collect 100 wood
Mine iron
Build Iron Mine
Produce Cannons in Factory
preceeds
Order troops to mine 1000 iron
13Hierarchical Planning
- Overall plan created at different levels of
abstraction - Low-level subplans created to do higher level
tasks - High-level tasks have preconditions and
postconditions - High-level tasks have methods for expanding into
subplans - Steps of subplan accomplishes postconditions
given preconditions
Task
Task
Task
Preconditions
Postconditions
Main plan
Action
Task
Action
Preconditions
Postconditions
Subplan
Action
Action
14Hierarchical Planning
General plan to capture a city
Gather weapons
Attack city
Move to city
Have weapons
At city
Gather wood
Build bows and arrows
Move to bridge
Cross bridge
Move to city
At city
Subplan generated for this particular city, level
of technology, etc.
15Dynamic Replanning
- Conditions used to create plan may no longer
apply in course of executing plan - Bridge NPC destroyed by player while gathering
weapons - Can create a different subplan to accomplish
specific task without replanning entire plan - Move to city subplan accomplished by building
boats
Move to city
Have weapons
At city
Move to river
Gather wood
Build boats
At city
Cross river in boats
Move to city
16Planning for Hierarchical Teams
- Goals of team should direct goals of individuals
- Individuals take actions to support overall
actions of team
17Planning for Hierarchical Teams
- Individual units meet goal based on individual
abilities - No micromanaging from overall system
Open Door
Pick Lock
Look in Room
Search all rooms
Look in Room with X-ray Vision
Overall team goal
Smash Door
Look in Room
18Planning for Hierarchical Teams
- Individual units can balance team goals with
individual goals to give appearance of
independent thought - Each individual/subteam has relevance measure for
different goals - Meets goal with highest current relevance
Goal Charge TakeCover Retreat Patrol
Relevance 0.6 0.8 0.3 0.0
Current action
19Planning for Hierarchical Teams
- Individual goal modified by goals of team
- Example Leader orders squad to charge, and not
retreat
Goal Charge TakeCover Retreat Patrol
Relevance 0.6 0.8 0.3 0.0
Modifier 0.5 0.0 -0.5 0.0
Total 1.1 0.8 -0.2 0.0
Current action
20Planning for Hierarchical Teams
- If individual goals strong, team goals may be
overridden! - Example Leader orders squad to patrol
- This unit currently under ambush
Goal Charge TakeCover Retreat Patrol
Relevance 0.4 0.8 0.6 0.0
Modifier 0.0 0.0 0.0 0.5
Total 0.4 0.8 0.6 0.5
Current action