960 likes | 1.04k Views
Applying Blackboard Systems to First Person Shooters. 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.
E N D
Applying Blackboard Systems to First Person Shooters 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.
Agenda • Blackboards are wicked cool. • What is a blackboard? • Inter-agent coordination • Intra-agent coordination
What if there was an architecture that… • …was simple to implement. • …was flexible & maintainable. • …handled coordinated behavior: • Coordinated timing of behaviors. • Coordinated pathfinding. • Coordinated tactics.
But wait! There’s more! • …simplifies agent architecture. • …reduces code bloat. • …facilitates AI LOD system. • …facilitates variations, re-use, and sharing. • …allows complex reasoning.
Blackboards: the magical animal Homer: “What about bacon?” Lisa: “No!” Homer: “Ham?” Lisa: “No!” Homer: “Pork chops?!?” Lisa: “Dad! Those all come from the same animal!” Homer: “Yeah right Lisa. A wonderful magical animal.”
A blackboard is a metaphor • Physical blackboard • Publicly read/writeable. • Possibly organized. • Maybe more like a bulletin board • Post requests and information. • Respond to items of interest.
A blackboard is shared memory • 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 • Changes how agents and/or sub-systems interact • Like an interface • Reduces coupling of sub-systems
Blackboard implementation • There’s no wrong way to eat a blackboard. • 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.) • Predetermined data to share. • Static amount of data. • Best for intra-agent coordination.
Dynamic blackboards struct BBRECORD { … }; typedef std::vector<BBRECORD*> BBRECORD_LIST; 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 int CountRecords( ENUM_BBRECORD_TYPE eType ); int CountRecords( ENUM_BBRECORD_TYPE eType, HANDLE hTarget ); float GetRecordData( ENUM_BBRECORD_TYPE eType ); float GetRecordData( ENUM_BBRECORD_TYPE eType, HANDLE hTarget );
Dynamic blackboards (cont.) • Data to share is not predetermined. • Dynamic amount of data. • Best for inter-agent coordination. • Also useful for intra-agent complex reasoning.
Inter-agent Coordination Using a blackboard to solve coordination problems on NOLF2.
Inter-agent Coordination Problems • Agents doing the same thing at the same time. • Agents doing things too often. • Special constraints for tactics. • Agents take same paths. • Agents clump at destinations.
NOLF2 Blackboard • Add Records: • Enumerated type • Subject ID • Optional Target ID • Optional float data • 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? if( g_pAIBB->CountRecords( kBB_Crouching ) == 0 ) { // Crouch… g_pAIBB->AddRecord( kBB_Crouching, m_hObject ); }
Problem #2: Agents doing things too often Examples: • Soldiers going Prone • Ninja Disappear-Reappear • Combat/Search sounds
Blackboard Solution: Agents doing things too often Should I go prone? if( fCurTime > g_pAIBB->GetRecordFloat( kBB_NextProneTime ) ) { // 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 Should I attack from the roof? if( g_pAIBB->CountRecords( kBB_AttackingRoof, m_hTarget ) > 0 ) { return false; }
Blackboard Solution: Tactical behavior has special constraints (cont.) if( g_pAIBB->CountRecords( kBB_Attacking, m_hTarget ) < 2 ) { return false; } // Attack from the roof… g_pAIBB->AddRecord( kBB_Attacking, m_hObject, m_hTarget ); g_pAIBB->AddRecord( kBB_AttackingRoof, m_hObject, m_hTarget );
Problem #4: Agents take same paths 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.) NOLF2 AIVolume system:
Problem #4: Agents take same paths (cont.) NOLF2 AIVolume system:
Problem #4: Agents take same paths (cont.) NOLF2 AIVolume system:
Problem #4: Agents take same paths (cont.) NOLF2 AIVolume system:
Problem #4: Agents take same paths (cont.) NOLF2 AIVolume system:
Blackboard Solution: Agents take same paths Volume reservation system: • Reserve the Volume before the destination. • Reserved Volume Cost == Cost + 500
Blackboard Solution: Agents take same paths (cont.) Volume reservation system:
Blackboard Solution: Agents take same paths (cont.) Volume reservation system:
Blackboard Solution: Agents take same paths (cont.) Volume reservation system:
Blackboard Solution: Agents take same paths (cont.) // Pathfinding if( g_pAIBB->CountRecords( kBB_ReservedVolume, hVolume ) > 0 ) { fNodeCost += 500.f; }
Blackboard Solution: Agents take same paths (cont.) // Movement 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 • First agent claims volume for investigation. • Other agents stop at edge of volume.
Blackboard Solution: Agents crowd at destination (cont.) // AI reached the dest volume first. if( g_pAIBB->CountRecords( kBB_InvestigatingVolume, hVolume ) == 0 ) { g_pAIBB->AddRecord( kBB_InvestigatingVolume, m_hObject ); } // AI did not reach the dest volume first. else { // Look at dest. }
Einstein says… “Hang in there, we’re half-way done!”