Professional Documents
Culture Documents
utgameAI03 Orkin
utgameAI03 Orkin
utgameAI03 Orkin
Jeff Orkin
Monolith Productions
http://www.jorkin.com
No One Lives Forever 2:
A Spy in H.A.R.M.’s Way
aka NOLF2
A.I. Systems
re-used:
– TRON 2.0
– Contract J.A.C.K.
No One Lives Forever 2:
A Spy in H.A.R.M.’s Way
Agenda
Physical blackboard
– Publicly read/writeable.
– Possibly organized.
Read/write memory
Working memory
Like a hard-drive
Like a database
No processing (other than sorting)
A blackboard is a means of
communication
Centralized communication
Agents communicate
Sub-systems of an agent communicate
A blackboard is an architecture
Two flavors:
– Static
– Dynamic
Static blackboards
class CBlackboard
{
private:
Vector m_vPos;
Vector m_vVelocity;
int m_nHealth;
// etc…
public:
// access functions…
};
Static blackboards (cont.)
class CBlackboard
{
private:
BBRECORD_LIST m_lstBBRecords;
public:
// query functions…
};
Dynamic blackboards (cont.)
struct BBRECORD
{
ENUM_BBRECORD_TYPE eType;
HANDLE hSubject;
HANDLE hTarget;
float fData;
};
Dynamic blackboards (cont.)
enum ENUM_BBRECORD_TYPE
{
kBB_Invalid = -1,
kBB_Attacking,
kBB_Crouching,
kBB_NextDisappearTime,
kBB_ReservedVolume,
// etc…
};
Dynamic blackboards (cont.)
// query functions
Remove Records:
– Specific by type and Subject ID
– All by type
Replace Records
NOLF2 Blackboard (cont.)
Query:
– Count matching records
– Retrieve data from matching records
Problem #1: Agents doing same
thing at same time
Examples:
Soldiers Crouching
– Random chance of
crouch
– Dodge roll into crouch
– Crouch to get out of
firing line
Ninja Lunging
Blackboard Solution: Agents doing
same thing at same time
Should I crouch?
Examples:
Soldiers going Prone
Ninja Disappear-Reappear
Combat/Search sounds
Blackboard Solution: Agents doing
things too often
Should I go prone?
g_pAIBB->ReplaceRecord( kBB_NextProneTime,
m_hObject,
fCurTime + fDelay );
}
Problem #3: Tactical behavior has
special constraints
Example:
Ninja only attacks from a rooftop if two other ninja are
already attacking on ground, and no one is on a roof.
Blackboard Solution: Tactical
behavior has special constraints
Example:
Player runs around the corner, and characters
follow in a congo line and get killed one by one.
Problem #4: Agents take same
paths (cont.)
A
B
Problem #4: Agents take same
paths (cont.)
A
B
Problem #4: Agents take same
paths (cont.)
A
B
Blackboard Solution: Agents take
same paths
P
1 1
1
1
A
6 1 B 1 1
Blackboard Solution: Agents take
same paths (cont.)
P
1 1
1
1
A
6 1 B 1 1
Blackboard Solution: Agents take
same paths (cont.)
d!
P s erv
e
1 Re 5 011
1
1
A
6 1 B 1 1
Blackboard Solution: Agents take
same paths (cont.)
// Pathfinding
g_pAIBB->RemoveRecord( kBB_ReservedVolume,
m_hObject );
g_pAIBB->AddRecord( kBB_ReservedVolume,
m_hObject,
hVolume );
Problem #5: Agents crowd at
destination
Examples:
Player knocks over a bottle. Characters
converge on bottle position.
Characters discover dead body and converge.
Blackboard Solution: Agents crowd
at destination
B
A
Blackboard Solution: Agents crowd
at destination (cont.)
B
A
Blackboard Solution: Agents crowd
at destination (cont.)
B
A
Blackboard Solution: Agents crowd
at destination (cont.)
// AI reached the dest volume first.
“Less is more”:
Less to debug
Less to maintain
Less to port
Less to compile
Less to document
Less to learn
Less data (per volume)
Why use blackboards??
Problem:
Pathfinder needs to look up Volume
Reservation status every iteration thru A*.
What about performance?! (cont.)
Solution:
A* flags array
char astarFlags[NUM_VOLUMES];
enum ASTAR_FLAGS
{
kNone = 0x00,
kOpen = 0x01,
kClosed = 0x02,
};
What about performance?! (cont.)
Solution:
A* flags array
char astarFlags[NUM_VOLUMES];
enum ASTAR_FLAGS
{
kNone = 0x00,
kOpen = 0x01,
kClosed = 0x02,
kReserved = 0x04,
};
What about performance?! (cont.)
RunAStar()
{
ClearFlags();
Search();
}
What about performance?! (cont.)
RunAStar()
{
ClearFlags();
MarkReserved();
Search();
}
Intra-agent Coordination
Intra-agent Coordination
A character is an entire world.
Sub-systems are characters in the world.
– Navigation
– Movement
– Target/Attention selection
– Senses
– Animation
– Weapons
– Decision-Making
NOLF2 Agent Architecture
Animation Decision-Making
Navigation Sensory
W eapons
NOLF2 Agent Architecture
Animation Decision-Making
Navigation Sensory
W eapons
Blackboard Agent Architecture
Animation Decision-Making
W eapons
Blackboard Agent Architecture
class AgentBlackBoard
{
private:
Vectorm_vDest;
NAV_STATUS m_eNavStatus;
HANDLEm_hTarget;
AISenses m_aSenses[MAX_SENSES];
// etc…
public:
// Access functions…
}
Benefits of Decoupling
Sub-systems
Benefits of Decoupling:
1. Development/Maintenance
2. Flexibility
3. Performance
Benefit #1:
Development/Maintenance Benefits
Problem:
Difficult to upgrade or replace old systems.
Example:
Re-writing navigation system
Benefit #1:
Development/Maintenance (cont.)
Various calls to sub-system:
pAI->GetPathManager()->SetPath(vDest);
pAI->GetPathManager()->UpdatePath();
if( pAI->GetPathManager()->IsPathDone() )
...
Problem:
Different characters have
different needs.
Example:
Humans plan paths to a
dest.
Rats and Rabbits wander
randomly to a dest.
Benefit #2: Flexibility (cont.)
Example (cont.):
if( pAI->GetPathManager()->IsPathComplete() )
{
// etc…
}
Benefit #2: Flexibility (cont.)
Blackboard Solution:
if( pAI->GetAIBlackboard()->GetNavStatus()
== kNavStatus_Done )
{
// etc…
}
Benefit #2: Flexibility (cont.)
Example:
Humans need a lot of sensory information to
make complex goal-based decisions.
Rats and Rabbits need very little info for
simplistic behavior.
Benefit #2: Flexibility (cont.)
Benefit #2: Flexibility (cont.)
Friend?
Benefit #2: Flexibility (cont.)
Benefit #3: Performance
Problem:
All characters in NOLF2 are
active all of the time,
regardless of player location.
Example:
Characters are pathfinding,
moving, animating, and
sensing as they work at desks,
go to the bathroom, etc.
Benefit #3: Performance (cont.)
Blackboard Solution:
Sub-systems communicate through the
blackboard.
LOD system swaps sub-systems behind the
scenes.
Benefit #3: Performance (cont.)
LOD 5:
Benefit #3: Performance (cont.)
LOD 5:
Benefit #3: Performance (cont.)
LOD 5:
Benefit #3: Performance (cont.)
LOD 2:
Benefit #3: Performance (cont.)
LOD 2:
Don’t run away…
GDC 2001
Creature Smarts: The Art and Architecture of the
Virtual Brain
Intra-agent Dynamic Blackboard
(cont.)
Intra-agent Dynamic Blackboard
(cont.)
Intra-agent Dynamic Blackboard
(cont.)
Benefits:
Keep track of multiple types of information in a
consistent way.
Open-ended architecture: different games may
use different data in different ways.
Complex reasoning.
Intra-agent Dynamic Blackboard:
Complex Reasoning
Queries:
“Is there food near me?”
Find the “red object that is making the most
noise.”
“Find an object that is humanoid-shaped and
go to it.”
Intra-agent Dynamic Blackboard:
Complex Reasoning (cont.)
Spatial Reasoning:
Agent is more alarmed if multiple disturbances
are found near each other.
Intra-agent Dynamic Blackboard:
Complex Reasoning (cont.)
Temporal Reasoning:
Anticipation and surprise.
Intra-agent Dynamic Blackboard:
Complex Reasoning (cont.)
Deductive Reasoning:
Agent sees dead body.
Agent sees player with a gun.
Agent draws the conclusion that the player was
the killer.
Intra-agent Dynamic Blackboard:
Complex Reasoning (cont.)
Multi-tasking:
Agent targets enemyA.
Agent targets enemyB.
Agent kills enemyB.
Agent is aware that he
was also fighting
enemyA.
Take-away
December 2003:
AI Game Programming Wisdom 2
“Simple Techniques for Coordinated Behavior”
More Information
Slides:
http://www.jorkin.com/talks/UT_blackboards.zip
jeffo@lith.com
Questions?
Slides:
http://www.jorkin.com