gate-561 1 common ai architectures (gate-561) dr.Çağatay ÜndeĞer instructor middle east...

40
1 GATE-561 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer Engineering & General Manager SimBT Inc. e-mail : [email protected] Game Technologies Program – Middle East Technical University – Fall 2009

Post on 22-Dec-2015

229 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

1GATE-561

Common AI Architectures (GATE-561)

Dr.Çağatay ÜNDEĞER

InstructorMiddle East Technical University, GameTechnologies

Bilkent University, Computer Engineering

&

General ManagerSimBT Inc.

e-mail : [email protected]

Game Technologies Program – Middle East Technical University – Fall 2009

Page 2: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

2GATE-561

Outline• Introduction to AI Architectures• Entities, Attributes and Relations• Tasks, Actions, States and Events• Finite-State Machines• Hierarchical Finite-State-Machines

Page 3: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

3GATE-561

AI Architecture

• A complete system architecture (AI engine) – That defines mechanizm of a percept-

reasoning-action cycle• For modeling autonomous entity

behaviors

Page 4: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

4GATE-561

An Example AI Architecture

Percepts Actions

Environment

SeeingHearingSmellingTasting

Touching

MovingTalkingFiring

...

InferenceInterpretation

Conflict resolutionPlanning

...

Situation Awareness

Reactive Behaviours

Delibrative Behaviours

Action Selection

Reasoning

Short & Long Term Memory

Learning Rule Matching...

Known facts& Rules

Page 5: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

5GATE-561

Entities

• Any kind of objects within an environment

Page 6: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

6GATE-561

Entities

• Trees• Bushes• Rocks• Cars• Tanks• Bridges• Human beings• Animals• Houses

Page 7: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

7GATE-561

Attributes

• Any kind of parameters describing properties of an entity

Page 8: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

8GATE-561

Attributes• Tank

– Type– Coordinate– Orientation– Velocity– Damage– Gun 1

• Loaded• Number of munitions left

– Gun 2• Loaded• Number of munitions left

Page 9: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

9GATE-561

Relations

• Any link between two entities, groups of entities or types of entities defining a fact

Page 10: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

10GATE-561

Relations

• Ahmet is father of veli• Suzan is mother of veli• Mustafa, Kenan and Oya are friends• Iraq forces is an opponent of US forces• TSK and SSM are stakeholders• X may have a relation with Y

• Strike is an eagle• Eagle is a bird• Bird is an animal

Page 11: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

11GATE-561

Tasks

• Any piece of work, – Which has been undertaken or attempted – By someone – To reach a desired goal

Page 12: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

12GATE-561

Tasks

• Playing backgammon• Doing a project• Going to school• Performing surveillance• Managing an accident• Defending a town• Attacking a town

Page 13: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

13GATE-561

Sub-Tasks

• Smaller pieces of work to be done in order to perform and complete a task

Page 14: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

14GATE-561

Playing Backgammon

• Determining the first player• Doing your move• Waiting opponent’s move• Becoming happy• Becoming sad

Page 15: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

15GATE-561

Doing a Project

• Generating a list of candidate topics• Selecting one of the topics• Determining requirements• Performing research on requirements• Preparing a design• Implementing • Testing• Documenting development• Writing users-manuals

Page 16: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

16GATE-561

Going to School

• Remembering the location of school• Planing an initial path to school• Going to school through the path

– Replanning a path to school if required• Entering the school• Planing an initial path to the classroom• Going to the classroom through the path

– Replanning a path to classroom if required• Entering the classroom

Page 17: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

17GATE-561

Performing Surveillance• Determining the surveillance start location• Determining the surveillance path• Going to surveillance start location

– Replanning a path to location– Replanning a path to location if required

• Moving through surveillance path– Replanning a surveillance path if required

• Looking around to detect any suspicious activity

• Examining suspicious activity (detection)• Reporting details of detection

Page 18: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

18GATE-561

Managing an Accident

• Waiting a call• Answering a call• Getting accident information on call• Finding nearest hospital• Calling nearest hospital for an ambulance• Getting an ambulance aircraft if required

– Calling Turkish General Staff– Requesting an ambulance aircraft approval– Waiting for approval– Getting approval / reject– Organizing an ambulance aircraft– ....

Page 19: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

19GATE-561

Actions

• A primitive (may be un-interruptable) work to be done in order to perform a task

Page 20: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

20GATE-561

Actions

• Do a chess move• Do a forward step• Change direction• Hang up a phone• Send a fax• Say a statement to someone• Talk to someone• Engage a target• Fire a target• Throw a bomb• Give an order

Page 21: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

21GATE-561

States

• A position in time.

• A specific situation/case/condition – Among a set of all possible situations a

system may be in.

Page 22: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

22GATE-561

States

• Standing• Sitting• Walking• Running• Jumping• Talking• Defending• Attacking

Page 23: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

23GATE-561

Events

• Something that happens in time.

• An action, occurrence or a condition that causes a state transition

• Thus in addition to actions, – An external or internal event may cause a

transition

Page 24: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

24GATE-561

Events

Getting dress

Going to school

Going to classroom

Sleeping

States

Clock rang

Events

Dressing completed

School reached andDoor open

Page 25: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

25GATE-561

Attributes vs States• Attributes of an entity can be considered as a part of its state

information as below.

• Tank– Coordinate– Orientation– Velocity– Damage– Gun 1

• Loaded• Number of munitions left

– Gun 2• Loaded• Number of munitions left

• But usually they are not used that way.

Page 26: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

26GATE-561

Tasks vs States• Meanwhile performing a task;

– A system may be in one state (may have sub-states) and

– May transite from one state to another.

• In a time instant, a system may:– Be in one state or– Be in more than one sub-states in a set of

parallel tasks: –Moving somewhere–Talking at the same time–Looking around at the same time

Page 27: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

27GATE-561

Tasks vs States

1. Remembering the location of school2. Planing an initial path to school3. Going to school through the path4. Entering the school5. Planing an initial path to the classroom6. Going to the classroom through the

path7. Entering the classroom

Staying

Walking

Running

Opening Door

Sitting

Task: Going to schoolStates

Sub-Tasks

Page 28: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

28GATE-561

Actions vs States

• An action may move a system from one state to another state

• From “Waiting a call” to “Talking on phone”– By a “Hang up phone” action

• From “Moving randomly” to “Attacking someone” – By an “Engage an enemy” action

Page 29: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

29GATE-561

Actions vs States

Staying

Walking

Running

Opening Door

Sitting

States

Stand up

Actions

Go to location slowly

Go to location fast

Open door

Stop

Sit down

Actions

Page 30: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

30GATE-561

Actions vs States

• It is also possible and common to model actions as states.

• In that condition;– A state will either:

• Perform some action or• Be idle.

– Only events will cause transitions.

Page 31: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

31GATE-561

Finite-State Machines (FSMs)

• Defined by a set of states and transitions between them.

• Transition from a state to another state is triggered by a change (event or action) in the environment.

Page 32: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

32GATE-561

Finite-State Machines (FSMs)

• FSMs are used broadly in the video game industry. – Quake and Quake 2: a simple FSM system. – Warcraft III: a complex FSM system

• FSMs also have a large role outside of the video game industry. – For example, cars, airplanes, and robotics have

complex FSMs.

Page 33: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

33GATE-561

Finite-State Machines (FSMs)

• Also called “State Transition Networks/Diagrams”

Wander

AttackEnemy

SearchEnemy

Spawn

see enemy

initial state

not see enemy

hear sound

not hear sound

see enemy

dead

reborn dead

dead

Page 34: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

34GATE-561

Finite-State Machines (FSMs)

• An FSM has an entry (initial) state for starting the execution.

• After execution starts, events and/or actions cause state transitions.

• Each state may execute a code while;– Entering a state– Maintaining a state in every step and/or – Leaving a state

Page 35: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

35GATE-561

A Sample

Initial state

Standing

Sitting

Walking

Running

Working

Page 36: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

36GATE-561

Hierarchical Finite-State Machines

• When the number of states increases,– It becomes very complicated to define the

FSMs and– High probable to have some bugs !

• A solution is to ddefine some higher level states, and

• Refine the details of states hierarchically.

Page 37: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

37GATE-561

A Sample

Start

Load weapon

Point at enemy

Fire

weaponloaded

weaponunloaded

weaponunloaded

weaponloaded

enemy engaged

weaponloaded

Sub-finite state machine

Wander

AttackEnemy

SearchEnemy

Spawn

see enemy

not see enemy

hear sound

not hear sound

see enemy

dead

reborn dead

dead

Page 38: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

38GATE-561

Advantages

• Very fast to execute.• Expressive enough for simple behaviors.• Can create tools for non-programmers to

build behaviors.• Probabilistic transitions can be introduced to

make unpredictable transitions/behaviors.

Page 39: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

39GATE-561

Disadvantages

• Number of states and arcs can grow very fast.• Easy to do errors in complex FSMs.• Difficult to;

– Put propositional representations such as:• Pick up the best weapon • Attack the closest enemy

– Count such as: • Wait until the third time I see the enemy,

then attack– Perform actions in parallel

Page 40: GATE-561 1 Common AI Architectures (GATE-561) Dr.Çağatay ÜNDEĞER Instructor Middle East Technical University, GameTechnologies Bilkent University, Computer

40GATE-561

Disadvantages

• But they are still prefered in many games, and• They can be improved with some special

additions such as:– Parallel finite-state machines– Higher level scripts to perform complex

transitions