Presentation is loading. Please wait.

Presentation is loading. Please wait.

Applying Blackboard Systems to First Person Shooters Jeff Orkin Monolith Productions

Similar presentations


Presentation on theme: "Applying Blackboard Systems to First Person Shooters Jeff Orkin Monolith Productions"— Presentation transcript:

1 Applying Blackboard Systems to First Person Shooters Jeff Orkin Monolith Productions http://www.jorkin.com

2 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.

3 No One Lives Forever 2: A Spy in H.A.R.M.’s Way

4 Agenda Blackboards are wicked cool. What is a blackboard? Inter-agent coordination Intra-agent coordination

5 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.

6 But wait! There’s more! …simplifies agent architecture. …reduces code bloat. …facilitates AI LOD system. …facilitates variations, re-use, and sharing. …allows complex reasoning.

7 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.”

8 What is a blackboard?

9 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.

10 A blackboard is shared memory Read/write memory Working memory Like a hard-drive Like a database No processing (other than sorting)

11 A blackboard is a means of communication Centralized communication Agents communicate Sub-systems of an agent communicate

12 A blackboard is an architecture Changes how agents and/or sub-systems interact Like an interface Reduces coupling of sub-systems

13 Blackboard implementation There’s no wrong way to eat a blackboard. Two flavors: – Static – Dynamic

14 Static blackboards class CBlackboard { private: Vectorm_vPos; Vectorm_vVelocity; intm_nHealth; // etc… public: // access functions… };

15 Static blackboards (cont.) Predetermined data to share. Static amount of data. Best for intra-agent coordination.

16 Dynamic blackboards struct BBRECORD { … }; typedef std::vector BBRECORD_LIST; class CBlackboard { private: BBRECORD_LISTm_lstBBRecords; public: // query functions… };

17 Dynamic blackboards (cont.) struct BBRECORD { ENUM_BBRECORD_TYPEeType; HANDLEhSubject; HANDLEhTarget; floatfData; };

18 Dynamic blackboards (cont.) enum ENUM_BBRECORD_TYPE { kBB_Invalid = -1, kBB_Attacking, kBB_Crouching, kBB_NextDisappearTime, kBB_ReservedVolume, // etc… };

19 Dynamic blackboards (cont.) // query functions int CountRecords( ENUM_BBRECORD_TYPE eType ); int CountRecords( ENUM_BBRECORD_TYPE eType, HANDLE hTarget ); floatGetRecordData( ENUM_BBRECORD_TYPE eType ); floatGetRecordData( ENUM_BBRECORD_TYPE eType, HANDLE hTarget );

20 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.

21 Inter-agent Coordination Using a blackboard to solve coordination problems on NOLF2.

22 Inter-agent Coordination Problems 1. Agents doing the same thing at the same time. 2. Agents doing things too often. 3. Special constraints for tactics. 4. Agents take same paths. 5. Agents clump at destinations.

23 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

24 NOLF2 Blackboard (cont.) Query: – Count matching records – Retrieve data from matching records

25 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

26 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 ); }

27 Problem #2: Agents doing things too often Examples: Soldiers going Prone Ninja Disappear-Reappear Combat/Search sounds

28 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 ); }

29 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.

30 Blackboard Solution: Tactical behavior has special constraints Should I attack from the roof? if( g_pAIBB->CountRecords( kBB_AttackingRoof, m_hTarget ) > 0 ) { return false; }

31 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 );

32 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.

33 Problem #4: Agents take same paths (cont.) NOLF2 AIVolume system:

34 Problem #4: Agents take same paths (cont.) NOLF2 AIVolume system:

35 Problem #4: Agents take same paths (cont.) NOLF2 AIVolume system:

36 Problem #4: Agents take same paths (cont.) NOLF2 AIVolume system:

37 Problem #4: Agents take same paths (cont.) NOLF2 AIVolume system:

38 Blackboard Solution: Agents take same paths Volume reservation system: Reserve the Volume before the destination. Reserved Volume Cost == Cost + 500

39 Blackboard Solution: Agents take same paths (cont.) Volume reservation system:

40 Blackboard Solution: Agents take same paths (cont.) Volume reservation system:

41 Blackboard Solution: Agents take same paths (cont.) Volume reservation system:

42 Blackboard Solution: Agents take same paths (cont.) // Pathfinding if( g_pAIBB->CountRecords( kBB_ReservedVolume, hVolume ) > 0 ) { fNodeCost += 500.f; }

43 Blackboard Solution: Agents take same paths (cont.) // Movement g_pAIBB->RemoveRecord( kBB_ReservedVolume, m_hObject ); g_pAIBB->AddRecord( kBB_ReservedVolume, m_hObject, hVolume );

44 Problem #5: Agents crowd at destination Examples: Player knocks over a bottle. Characters converge on bottle position. Characters discover dead body and converge.

45 Blackboard Solution: Agents crowd at destination First agent claims volume for investigation. Other agents stop at edge of volume.

46 Blackboard Solution: Agents crowd at destination (cont.)

47

48

49 // 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. }

50 Einstein says… “Hang in there, we’re half-way done!”

51 Why use blackboards??

52 “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)

53 Why use blackboards?? Decouple data from game-specific purpose: Designs change Re-use systems in other games (other genres?) OO design is not always the right choice.

54 What about performance?! Problem: Pathfinder needs to look up Volume Reservation status every iteration thru A*.

55 What about performance?! (cont.) Solution: A* flags array char astarFlags[NUM_VOLUMES]; enum ASTAR_FLAGS { kNone= 0x00, kOpen= 0x01, kClosed= 0x02, };

56 What about performance?! (cont.) Solution: A* flags array char astarFlags[NUM_VOLUMES]; enum ASTAR_FLAGS { kNone= 0x00, kOpen= 0x01, kClosed= 0x02, kReserved = 0x04, };

57 What about performance?! (cont.) RunAStar() { ClearFlags(); Search(); }

58 What about performance?! (cont.) RunAStar() { ClearFlags(); MarkReserved(); Search(); }

59 Intra-agent Coordination

60 A character is an entire world. Sub-systems are characters in the world. – Navigation – Movement – Target/Attention selection – Senses – Animation – Weapons – Decision-Making

61 NOLF2 Agent Architecture

62

63 Blackboard Agent Architecture

64 class AgentBlackBoard { private: Vectorm_vDest; NAV_STATUSm_eNavStatus; HANDLEm_hTarget; AISensesm_aSenses[MAX_SENSES]; // etc… public: // Access functions… }

65 Benefits of Decoupling Sub-systems Benefits of Decoupling: 1. Development/Maintenance 2. Flexibility 3. Performance

66 Benefit #1: Development/Maintenance Benefits Problem: Difficult to upgrade or replace old systems. Example: Re-writing navigation system

67 Benefit #1: Development/Maintenance (cont.) Various calls to sub-system: pAI->GetPathManager()->SetPath(vDest); pAI->GetPathManager()->UpdatePath(); if( pAI->GetPathManager()->IsPathDone() )... AIVolume* GetNextVolume(AIVolume* pVolume, AIVolume::EnumVolumeType eVolumeType);

68 Benefit #2: Flexibility Problem: Different characters have different needs. Example: Humans plan paths to a dest. Rats and Rabbits wander randomly to a dest.

69 Benefit #2: Flexibility (cont.) Example (cont.): AIStatePatrol::Update( AI* pAI ) { pAI->GetPathManager()->SetPath(vDest); if( pAI->GetPathManager()->IsPathComplete() ) { // etc… }

70 Benefit #2: Flexibility (cont.) Blackboard Solution: AIStatePatrol::Update( AI* pAI ) { pAI->GetAIBlackboard()->SetDest(vDest); if( pAI->GetAIBlackboard()->GetNavStatus() == kNavStatus_Done ) { // etc… }

71 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.

72 Benefit #2: Flexibility (cont.)

73

74

75 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.

76 Benefit #3: Performance (cont.) Blackboard Solution: Sub-systems communicate through the blackboard. LOD system swaps sub-systems behind the scenes.

77 Benefit #3: Performance (cont.) LOD 5:

78 Benefit #3: Performance (cont.) LOD 5:

79 Benefit #3: Performance (cont.) LOD 5:

80 Benefit #3: Performance (cont.) LOD 2:

81 Benefit #3: Performance (cont.) LOD 2:

82 Don’t run away… We’re almost done!

83 Intra-agent Dynamic Blackboard MIT Media Lab Synthetic Characters Group C4 GDC 2001 Creature Smarts: The Art and Architecture of the Virtual Brain

84 Intra-agent Dynamic Blackboard (cont.)

85

86 Percept Memory Records: Only form of knowledge representation. – Game objects (characters, objects of interest, etc) – Desires – Damage – AI hints (AINodes, AIVolumes) – Tasks Can group multiple records for same object.

87 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.

88 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.”

89 Intra-agent Dynamic Blackboard: Complex Reasoning (cont.) Spatial Reasoning: Agent is more alarmed if multiple disturbances are found near each other.

90 Intra-agent Dynamic Blackboard: Complex Reasoning (cont.) Temporal Reasoning: Anticipation and surprise.

91 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.

92 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.

93 Take-away Use blackboard systems! – Less is more. – Decouple your data from its game-specific purpose. – Decouple your subsystems.

94 More Information December 2003: AI Game Programming Wisdom 2 “Simple Techniques for Coordinated Behavior”

95 More Information NOLF2 Source, Toolkit & SDK: http://nolf2.sierra.com ( AICentralKnowledgeMgr == Blackboard ) Slides: http://www.jorkin.com/talks/UT_blackboards.zip jeffo@lith.com

96 Questions? NOLF2 Source, Toolkit & SDK: http://nolf2.sierra.com ( AICentralKnowledgeMgr == Blackboard ) Slides: http://www.jorkin.com


Download ppt "Applying Blackboard Systems to First Person Shooters Jeff Orkin Monolith Productions"

Similar presentations


Ads by Google