62
Inteligência artificial Overview Bruno Duarte Corrêa – poli/usp Thiago Dias Pastor – poli/usp

Artificial Inteligence for Games an Overview SBGAMES 2012

Embed Size (px)

DESCRIPTION

An overview of artificial inteligence used in games and a case study of L4D

Citation preview

Page 1: Artificial Inteligence for Games an Overview SBGAMES 2012

Inteligência artificial Overview

Bruno Duarte Corrêa – poli/usp

Thiago Dias Pastor – poli/usp

Page 2: Artificial Inteligence for Games an Overview SBGAMES 2012
Page 3: Artificial Inteligence for Games an Overview SBGAMES 2012

Purpose of ai Maximize fun

Emulates the reality

Not necessarily simulation

Scoped by the gameplay

Challenging

...

Page 4: Artificial Inteligence for Games an Overview SBGAMES 2012

Desired Characteristics Be smart

Does not looks like dumb, but purposely flawed

Not intended weakness

Real time performance

Configurable

Transparent

Page 5: Artificial Inteligence for Games an Overview SBGAMES 2012

Basic needs of ai Navigation

Perceptions

Understand / Capture a snapshot of the world

Acting

Planning

Learning / adapt

Page 6: Artificial Inteligence for Games an Overview SBGAMES 2012

Navigation Path finding

Waypoints

Navmesh

Astar / Dijkstra

Steering behaviors

Field based navigation

Page 7: Artificial Inteligence for Games an Overview SBGAMES 2012

Waypoint • World Discretization • Manual Waypoints • Automatic

Waypoints • Static Environment • Connect by Raytrace • Different types

Page 8: Artificial Inteligence for Games an Overview SBGAMES 2012

NavMesh • Mesh processing algorithm • Pre-processing stage • Optimized waypoints

placement. • Sloped based • Easier to handle

• State of art

Page 9: Artificial Inteligence for Games an Overview SBGAMES 2012

NavMesh - Recast • OpenSource Api for NavMesh Generation (c++) • Used in many commercial games • Fully integrated with Detour (Navigation System) • Recast is state of the art navigation mesh construction toolset for games. • It is automatic, which means that you can throw any level geometry at it

and you will get robust mesh out • It is fast which means swift turnaround times for level designers • Extensible and easy to integrate

Source http://code.google.com/p/recastnavigation/

Information http://www.critterai.org/book/export/html/2

Page 10: Artificial Inteligence for Games an Overview SBGAMES 2012

PathFinding - Astar

• Find paths in the • waypoint graph • Robot Paths • Smooth filters • Bezier

• Highly Parallelizable • Can be implemented on

GPU

Page 11: Artificial Inteligence for Games an Overview SBGAMES 2012

PathFinding - Astar F = G + H

where G = the movement cost to move

from the starting point A to a given square on the grid,

following the path generated to get there.

H = the estimated movement cost to move from that given

square on the grid to the final destination, point B.

Page 12: Artificial Inteligence for Games an Overview SBGAMES 2012

PathFinding Summary of the A* Method 1.Add the starting square (or node) to the open list. 2.Repeat the following:

1. Look for the lowest F cost square on the open list. We refer to this as the current square.

2. Switch it to the closed list. 3. For each of the 8 squares adjacent to this current square … 4. If it is not walkable or if it is on the closed list, ignore it. Otherwise do the following. If it

isn’t on the open list, add it to the open list. Make the current square the parent of this square. Record the F, G, and H costs of the square.

5. If it is on the open list already, check to see if this path to that square is better, using G cost as the measure. If so, change the parent of the square to the current square, and recalculate the G and F scores of the square. If you are keeping your open list sorted by F score.

3.Stop when you: 1. Add the target square to the closed list, in which case the path has been found (see note

below), or 2. Fail to find the target square, and the open list is empty. In this case, there is no path.

4.Save the path. Working backwards from the target square, go from each square to its parent square until you reach the starting square. That is your path.

Page 13: Artificial Inteligence for Games an Overview SBGAMES 2012

PathFinding

Page 14: Artificial Inteligence for Games an Overview SBGAMES 2012

Steering Behaviors • Flow Driven • Atraction and Repulsion • No need for environment

discretization • Dynamic calculation • More human like (natural)

walking style • Characters can get stuck !!! • Swarm Behavior !!!

Page 15: Artificial Inteligence for Games an Overview SBGAMES 2012

Basic Behaviors Seek and Flee

Pursuit and Evasion

Page 16: Artificial Inteligence for Games an Overview SBGAMES 2012

Basic Behaviors Collision avoidance Path Pursuit

Follow the Leader Advanced Collisions Avoidance

Page 17: Artificial Inteligence for Games an Overview SBGAMES 2012

Steering Behaviors

• Combine all results like a Resultant Force • Use physic Integration to get: • Force • Aceleration • Velocity • Space

• Can be integrated with common physics APIs

Page 18: Artificial Inteligence for Games an Overview SBGAMES 2012

Basic needs of ai Navigation

Perceptions

Understand / Capture a snapshot of the world

Acting

Planning

Learning / adapt

Page 19: Artificial Inteligence for Games an Overview SBGAMES 2012

Perceptions “See the world as like a human does”

Emulate human senses Response time

Sensors Sight

Field of view/Raycast Sounds Smells ?!?!

Receive Messages

Page 20: Artificial Inteligence for Games an Overview SBGAMES 2012

Basic needs of ai Navigation

Perceptions

Understand / Capture a snapshot of the world

Acting

Planning

Learning / adapt

Page 21: Artificial Inteligence for Games an Overview SBGAMES 2012

Finite state machine

algorithm • Simple theoretical

construct – Set of states (S) – Input vocabulary (I) – Transitional function

T(s,i)

• A way of denoting how an object can change its state over time. State: Set of properties of the environment at a time

Page 22: Artificial Inteligence for Games an Overview SBGAMES 2012

Finite state machine

• States – E: enemy in sight – S: hear a sound – D: dead

• Events – E: see an enemy – S: hear a sound – D: die

• Action performed – On each transition – On each update in

some states (e.g. attack)

Page 23: Artificial Inteligence for Games an Overview SBGAMES 2012

Non deterministic

Finite state machine

Page 24: Artificial Inteligence for Games an Overview SBGAMES 2012

FSM - Limitations

Hard to Expand

Hard to Maintain

Not Flexible enough

As larger it gets as f... you are.

Page 25: Artificial Inteligence for Games an Overview SBGAMES 2012

Behavior tree Replaces fsm

Encapsulates Actions / Logic / State

Direct acyclic graph that is traversed

Non-leaf = Condition

Leafs = Actions

Divide to conquer approach

Page 26: Artificial Inteligence for Games an Overview SBGAMES 2012

Crysis Soldier

• Real Time Extensible • SIMPLE • Scriptable

Page 27: Artificial Inteligence for Games an Overview SBGAMES 2012

Generic Behavior Tree

Page 28: Artificial Inteligence for Games an Overview SBGAMES 2012

Example

Page 29: Artificial Inteligence for Games an Overview SBGAMES 2012

Example

Page 30: Artificial Inteligence for Games an Overview SBGAMES 2012

Example

Page 31: Artificial Inteligence for Games an Overview SBGAMES 2012

Example

Page 32: Artificial Inteligence for Games an Overview SBGAMES 2012

Example

Page 33: Artificial Inteligence for Games an Overview SBGAMES 2012

Example

Page 34: Artificial Inteligence for Games an Overview SBGAMES 2012

Example

Page 35: Artificial Inteligence for Games an Overview SBGAMES 2012

Example

Page 36: Artificial Inteligence for Games an Overview SBGAMES 2012

Example

END OF FRAME

Page 37: Artificial Inteligence for Games an Overview SBGAMES 2012

Basic needs of ai Navigation

Perceptions

Understand / Capture a snapshot of the world

Acting

Planning

Learning / adapt

Page 38: Artificial Inteligence for Games an Overview SBGAMES 2012

Planning

Goal oriented planning (GOAP)

HTN planning

STRIPS

Planning is a formalized process of searching for sequence of actions to

satisfy a goal.

Page 39: Artificial Inteligence for Games an Overview SBGAMES 2012

GOAP • Composed by:

• Collection of states • Pre-condictions • Pos-condictions • Starting State • Goal State

• Answer the What question

• Self adaptable

Page 40: Artificial Inteligence for Games an Overview SBGAMES 2012

GOAP-Example

Page 41: Artificial Inteligence for Games an Overview SBGAMES 2012

GOAP-A*

Page 42: Artificial Inteligence for Games an Overview SBGAMES 2012

Basic needs of ai Navigation

Perceptions

Understand / Capture a snapshot of the world

Acting

Planning

Learning / adapt

Page 43: Artificial Inteligence for Games an Overview SBGAMES 2012

Supervised Learning

• Learning an input-output relationship from examples

• Tasks: regression, classification, ranking • Applications: skill estimation, behavioural cloning

Reinforcement Learning

• Learning policies from state-action-reward sequences

• Tasks: control, value estimation, policy learning • Applications: learning to drive, learning to walk, learning to fight

Unsupervised Learning

• Learning the underlying structure from examples

• Tasks: clustering, manifold learning, density estimation • Applications: modelling motion capture data, user behaviour

Learning

Page 44: Artificial Inteligence for Games an Overview SBGAMES 2012

Neural Network • Information processing paradigm • Is inspired by the way biological nervous systems • Composed of a large number of highly

interconnected processing elements • ANNs, like people, learn by example.

Page 45: Artificial Inteligence for Games an Overview SBGAMES 2012

Neural Network-Neuron

Page 46: Artificial Inteligence for Games an Overview SBGAMES 2012

Neural Network

Page 47: Artificial Inteligence for Games an Overview SBGAMES 2012

Neural Network Learning Actual algorithm for a 3-layer network (only one hidden layer): Initialize the weights in the network (often randomly)

Do

For each example e in the training set O = neural-net-output(network, e) ; forward pass

T = teacher output for e

Calculate error (T - O) at the output units Compute delta_wh for all weights from hidden layer to output layer ; backward

pass Compute delta_wi for all weights from input layer to hidden layer ; backward

pass continued

Update the weights in the network

Until all examples classified correctly or stopping criterion satisfied

Return the network

Page 48: Artificial Inteligence for Games an Overview SBGAMES 2012

Genetic Algorithm • Genetic Algorithms are a way of solving problems

by mimicking the same processes mother nature uses.

• Use the same combination of selection, recombination and mutation to evolve a solution to a problem

• Usefull to optimize uncertain domains

Page 49: Artificial Inteligence for Games an Overview SBGAMES 2012

Genetic Algorithm

Page 50: Artificial Inteligence for Games an Overview SBGAMES 2012

Genetic Algorithm-Problems

• Takes too many time to converge • Hard to define the genes • Hard to define the objective function • Hard to delivery in games

Page 51: Artificial Inteligence for Games an Overview SBGAMES 2012

Case Study – L4D

Left 4 Dead is a replayable, cooperative,

survival-horror game where four Survivors cooperate to escape

environments swarming with murderously enraged

“Infected” (ie: zombies)

Page 52: Artificial Inteligence for Games an Overview SBGAMES 2012

Case Study – L4D

• Deliver Robust Behavior Performances

• Provide Competent Human

Player Proxies

• Promote Replayability • Generate Dramatic Game

Pacing

Page 53: Artificial Inteligence for Games an Overview SBGAMES 2012

Deliver Robust Behavior Performances • Reactive Path Following Move towards “look ahead” point farther

down path • Use local obstacle avoidance • Good

• (Re)pathing is cheap • Local avoidance handles

small physics props, other bots, corners, etc

• Superposes well with mob flocking behavior

• Resultant motion is fluid • Bad

• Can avoid off path too much, requiring repath

Page 54: Artificial Inteligence for Games an Overview SBGAMES 2012

• Locomotion Owns moving the actor to a new position in the environment (collision resolution, etc)

• Body •Owns animation state

• Vision •Owns line-of-sight, field of view, and “am I able to see <X>” queries. •Maintains recognized set of entities.

• Intention •Behavior Tree based

Deliver Robust Behavior Performances

Page 55: Artificial Inteligence for Games an Overview SBGAMES 2012

• Believability/Fairness • Imperfect knowledge (senses

simulation) • Reaction times

• Trust • Survivor Bots Helps Human • Undesirable events

CANNOT occurs (Cheating) • Bots that are far from the

battle are magicaly teleported

• Survivor Bots cannot deal friendly fire

• …. • Human Behavior

Provide Competent Human Player Proxies

Page 56: Artificial Inteligence for Games an Overview SBGAMES 2012

Promote Replayability • Complex Procedural

Population • Game session is viewed as a

skill challenge instead of a • memorization exercise • Structured Unpredictability

Page 57: Artificial Inteligence for Games an Overview SBGAMES 2012

Structured unpredictability NavMesh

Flow Distance

Active Area Set Potential Visible Area

Page 58: Artificial Inteligence for Games an Overview SBGAMES 2012

Generate Dramatic Game Pacing

Adaptive Dramatic Pacing algorithm • Creates peaks and valleys of intensity similar to the proven pacing success of Counter-Strike • Algorithm: • Estimate the “emotional intensity” of each Survivor • Track the max intensity of all 4 Survivors • If intensity is too high, remove major threats for awhile • Otherwise, create an interesting population of threats

Page 59: Artificial Inteligence for Games an Overview SBGAMES 2012

AI DIRECTOR Use Survivor Intensity to modulate the Infected population • Build Up • Create full threat population until Survivor Intensity crosses peak threshold • Sustain Peak • Continue full threat population for 3-5 seconds after Survivor Intensity has peaked. Ensures minimum “build up” duration. • Peak Fade • Switch to minimal threat population (“Relax period”) and monitor Survivor Intensity until it decays out of peak range. This state is needed so current combat engagement can play out without using up entire Relax period. Peak Fade won’t allow the Relax period to start until a natural break in the action occurs. • Relax • Maintain minimal threat population for 30-45 seconds, or until Survivors have traveled far enough toward the next safe room, then resume Build Up.

Page 60: Artificial Inteligence for Games an Overview SBGAMES 2012

Implementation considerations

Multithreading

Functional

Modular

Data driven

Cache friendly

Game interface

Level of Detail

Page 61: Artificial Inteligence for Games an Overview SBGAMES 2012

Trends Emotion !!!

Realistic Crowd simulation

Ai in contact with the player itself

Improve ai testing

Character control and animation helper

Online ais

Interactive cut scenes

Page 62: Artificial Inteligence for Games an Overview SBGAMES 2012

Artificial intelligence

‘Far too often, AI has been a last-minute rush job, implemented in the final two or three months of development by overcaffeinated programmers with dark circles under their eyes and thousands of other high-priority tasks to complete”

- Paul Tozour, Ion Storm