4/10/20151 State Driven Agents CIS 479/579 Bruce R. Maxim UM-Dearborn.

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Behavioral Pattern: Visitor C h a p t e r 5 – P a g e 224 When an algorithm is separated from an object structure upon which it operates, new operations.
8.3. A GENT AND D ECISION M AKING AI Agent driven AI and associated decision making techniques.
TP4: S TATE M ACHINE D ESIGN P ATTERN  Definition  Infrastructure  Transition Code  Conclusion.
AP Computer Science A – Healdsburg High School 1 Unit 3 - Classes and Objects - Example.
Title Name institution. April, 9-11th, 2015FORIL XI
1/10/20151 Mobile Computing COE 446 Network Operation Tarek Sheltami KFUPM CCSE COE Principles of Wireless.
Analysis of Algorithms
T-Talk. Javascript. Module Pattern. Namics. Thomas Junghans. Frontend Engineer. 12 h August 2009.
4/5/20151 Mobile Ad hoc Networks COE 549 Mobility Models II Group Mobility Tarek Sheltami KFUPM CCSE COE
Corso di Algoritmi e Strutture Dati con Laboratorio A.A. 2014/15 Lezione 5.1 The String and Scanner classes.
James. Heckman University of Chicago
State-Space Collapse via Drift Conditions Atilla Eryilmaz (OSU) and R. Srikant (Illinois) 4/10/20151.
LINEAR PROGRAMMING Modeling a problem is boring --- and a distraction from studying the abstract form! However, modeling is very important: --- for your.
Real-Time Library: RTX
CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Software Frame Simulator (SFS) Technion CS Computer Communications Lab (236340) in cooperation with ECI telecom Uri Ferri & Ynon Cohen January 2007.
Artificial Intelligence in Game Design Representing NPCs as Finite State Machines.
Artificial Intelligence in Game Design Intelligent Decision Making and Decision Trees.
Artificial Intelligence in Game Design Hierarchical Finite State Machines.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Scripting Languages For Virtual Worlds. Outline Necessary Features Classes, Prototypes, and Mixins Static vs. Dynamic Typing Concurrency Versioning Distribution.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Guide To UNIX Using Linux Third Edition
JokerStars: Online Card Playing William Sanville Milestone 4.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
The chapter will address the following questions:
UNIT-V The MVC architecture and Struts Framework.
1 CSE 331 The Strategy and State Patterns slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
SDS Foil no 1 How to make real systems: Implementation design, deployment and realisation.
M1G Introduction to Programming 2 4. Enhancing a class:Room.
Dr. Ahmad R. Hadaegh A.R. Hadaegh California State University San Marcos (CSUSM) Page 1 Virtual Functions Polymorphism Abstract base classes.
Artificial Intelligence in Game Design Problems and Goals.
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Artificial Intelligence in Game Design
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 7 OS System Structure.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Games Development 2 Overview & Entity IDs and Communication CO3301 Week 1.
Artificial Intelligence for Games Finite State Machines
Computational theory techniques in interactive video games.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
6.5 Implementing a State Machine Language. State Machine in game AI The most used software pattern Simple to program Easy to comprehend Easy to debug.
M1G Introduction to Programming 2 5. Completing the program.
F.E.A.R. Game AI Evaluation by Robert Rak. What is F.E.A.R. ? FEAR is a First Person Shooter game Player takes on the role of an elite strike force team.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Dr Nick Mitchell (Room CM 224)
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Finite State Machines Logical and Artificial Intelligence in Games Lecture 3a.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Active-HDL Server Farm Course 11. All materials updated on: September 30, 2004 Outline 1.Introduction 2.Advantages 3.Requirements 4.Installation 5.Architecture.
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
The Game Development Process: Artificial Intelligence.
Behavioral Design Patterns
Creational Pattern: Prototype
Enemy and Friendly AIs Richard Gesick.
…and web frameworks in general
Design and Maintenance of Web Applications in J2EE
CO Games Development 2 Week 19 Extensions to Finite State Machines
Finite State Machines in Games
CIS 488/588 Bruce R. Maxim UM-Dearborn
Agenda Software development (SD) & Software development methodologies (SDM) Orthogonal views of the software OOSD Methodology Why an Object Orientation?
Presentation transcript:

4/10/20151 State Driven Agents CIS 479/579 Bruce R. Maxim UM-Dearborn

4/10/20152 Buckland Software The executables and source code available The Boost library is available from The Visual C++ environment need to be configured to compile the source code by setting the appropriate paths

4/10/20153 Paths Include file paths C:\boost C:\AI_Source\Common C:\AI_Source\Common\lua-5.0\include C:\AI_Source\Common\laubind Source file paths C:\AI_Source\Common C:\AI_Source\Common\lua-5.0 C:\AI_Source\Common\laubind Library file paths C:\AI_Source\Common\lua-5.0\lib

4/10/20154 FSM Agent Advantages Quick design and simple to code Easy to debug Low computational overhead Intuitive so they make sense to domain experts Flexible, easy for programmers to tweak to modify behaviors

4/10/20155 FSM State Examples Pacman ghosts –evade, chase Quake bots –find armor, find health, seek cover, run away FIFA soccer players –strike, dribble, chase ball, mark player NPC’s in real time strategy games –move to position, patrol, follow path

4/10/20156 Switch Implementation - 1 Define an enumerated type with the state names enum StateType(RunAway, Patrol, Attack); Then define method that manages the transitions void Agent::Update(StateType CurrentState) { switch (CurrentState) { case Runaway: EvadeEnemy( ); if (Safe( )) ChangeState(Patrol); break; …

4/10/20157 Switch Implementation - 2 This works OK for simple FSM’s Becomes overly complicated for FSM’s with lots of states and transitions Requires recompilation if states are changed Not easy to have simultaneous behaviors implemented (run and shoot) without defining lots of states

4/10/20158 State Transition Table -1 Current StateConditionState Transition RunawaySafePatrol AttackWeaker than enemyRunaway PatrolThreatened and stronger than enemy Attack PatrolThreatened and weaker than enemy Runaway

4/10/20159 State Transition Table - 2 Agent queries table as needed Table can stored in file and edited without recompiling the program Each state can be modeled as a separate objects or functions called by the agent Fairly easy to extend and modify

4/10/ State Design Pattern - 1 The state transition rules can be embedded in the states themselves All states share a common interface using a pure virtual class class State { public: virtual void Execute(Troll* troll) = 0; }

4/10/ State Design Pattern - 2 class Troll { State* m_pCurrentState; public: void Update() { m_pCurrentState->Execute(this); } void ChangeState(const State* pNewState) { delete m_pCurrentState; m_pCurrentState = pNewState; }

4/10/ State Design Pattern - 3 class State_Runaway : public State { public: void Execute(Troll* troll) { if (troll->isSafe()) troll->ChangeState(new State_Sleep()); else troll->MoveAwayFromEnemy(); }

4/10/ State Design Pattern - 4 class State_Sleep : public State { public: void Execute(Troll* troll) { if (troll->isThreatned()) troll->ChangeState(new State_RunAway()); else troll->Snore(); }

4/10/ West World Miner States EnterMineDigForGold QuenchThirstSaloon VisitBankDepositGold GoHomeSleep wealthy enough not thirsty not wealthy rested thirsty pockets full

4/10/ Classes All West World inhabitants are derived from the base class BaseGameEntity Each entity will be assigned a unique identifier The Miner class is an example of one such class The State class is the base abstract class and each of the four Miner states needs its own class definition

4/10/ Reusable Classes The State base class and the Miner owned classes would be more easily reused if were templates Creating a StateMachine class with ways of tracking the Miner’s current, previous, and global states gives the FSM a crude memory to allow more complex (context sensitive) behaviors

4/10/ Adding New NPC Elsa only visits two states VisitBathroom (1 chance in 10) or DoHouseWork This makes use of the template version of the State class and required the definition of a new global state WifeGlobalState to deal with the bathroom visits This requires adding classes MinersWife and MinersWifeOwnedStates

4/10/ Adding NPC Communication Good games make use of event driven architectures When events occur they are broadcast to other game objects who are programmed to react to the event or ignore it Intelligent game agents can send messages to each other to allow cooperative behaviors

4/10/ Telegram Structure struct Telegram { //the entity that sent this telegram int Sender; //the entity that is to receive this telegram int Receiver; //the message itself. These are all enumerated in the file //"MessageTypes.h" int Msg; //If a delay is necessary this field is stamped with the time //the message should be dispatched. double DispatchTime; //any additional information that may accompany the message void* ExtraInfo; // constructors not shown here }

4/10/ Message Types #include enum message_type { Msg_HiHoneyImHome, Msg_StewReady, }; inline std::string MsgToStr(int msg) { switch (msg) { case 1: return "HiHoneyImHome"; case 2: return "StewReady"; default: return "Not recognized!"; }

4/10/ Elsa’s New States CookStew VisitBathroom DoHouseWork previous state Previous state Receive “honey I’m home” Delayed message to self “Stew Ready” 1 chance in 10

4/10/ Message Management Creation, dispatch, and management of telegrams is handled by the class MessageDispatcher The method DispatchMessage is used by every agent to send a message to entity with a known ID The database of ID’s are managed by the class EntityManager

4/10/ Use Priority Queue Telegrams with delays are store in a priority queue ordered by their Time Stamp data Telegrams without delays (e.g. “I just shot you with my crossbow”) are sent right away The front queue message is removed long with any unprocessed expired telegrams

4/10/ FSM Changes The BaseEntity class needs to be modified (add HandleMessage ) so that any derived class can receive messages The State class needs to be modified so that BaseEntity states can choose to accept and handle messages (add OnMessage method) The StateMachine class needs its own version of HandleMessage

4/10/ Elsa Cooks Dinner Miner enters shack and sends “honey I’m home” message Elsa receives “honey I’m home” and changes state to CookStew Elsa puts Stew in oven and sends delayed message “Stew ready” Elsa receives “Stew ready”, takes out stew, and sends Miner “Dinner ready” message Miner receives “Dinner ready” and changes state to EatStew

4/10/ What happens? In between messages the NPC’s are free to respond to all state appropriate inputs This may means that the Miner has left the building before receiving the “Dinner ready” message Sometimes you need two FSM’s working in parallel (one for character movement and one for character’s weapon) Sometimes you need nested state machines (aka hierarchical FSM’s)