Pathfinding - Part 1
Upcoming SlideShare
Loading in...5
×
 

Pathfinding - Part 1

on

  • 583 views

These slides are part of a course about interactive objects in games. The lectures cover some of the most widely used methodologies that allow smart objects and non-player characters (NPCs) to exhibit ...

These slides are part of a course about interactive objects in games. The lectures cover some of the most widely used methodologies that allow smart objects and non-player characters (NPCs) to exhibit autonomy and flexible behavior through various forms of decision making, including techniques for pathfinding, reactive behavior through automata and processes, and goal-oriented action planning. More information can be found here: http://tinyurl.com/sv-intobj-2013

Statistics

Views

Total Views
583
Views on SlideShare
583
Embed Views
0

Actions

Likes
0
Downloads
25
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Pathfinding - Part 1 Pathfinding - Part 1 Presentation Transcript

  • INTERACTIVE OBJECTS INGAMING APPLICATIONSBasic principles and practical scenarios in UnityJune 2013Stavros Vassos Sapienza University of Rome, DIAG, Italy vassos@dis.uniroma1.it
  • Interactive objects in games2 Pathfinding Part 1: A* heuristic search on a grid Part 2: Examples in Unity Part 3: Beyond the basics Action-based decision making AI Architectures
  • Pathfinding3 Preview
  • Interactive objects in games4 Pathfinding Part 1: A* heuristic search on a grid Part 2: Examples in Unity Part 3: Beyond the basics Action-based decision making AI Architectures
  • Pathfinding5 Find a path that connects two points in the game world
  • Pathfinding6 Find a path that connects two points in the game world Fundamental requirement in most video games Traditionally considered as “AI for games” Typically dealt as separate component of the gamethat is used “as a service” by other AI components,e.g., the decision making component of characters
  • Pathfinding7 Find a path that connects two points in the game world Fundamental requirement in most video games Traditionally considered as “AI for games” Typically dealt as separate component of the gamethat is used “as a service” by other AI components,e.g., the decision making component of characters More complicated than it looks!
  • Pathfinding8 Funny video with bugs by Paul Tozour (2008)youtube link
  • Pathfinding: A* heuristic search9 Let’s start with a textbook approach Game-world as a grid, A* heuristic search
  • Pathfinding: A* heuristic search10 Let’s start with a textbook approach Using tool from http://www.policyalmanac.org/
  • Pathfinding: A* heuristic search11 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Simple forward search Explore until the target is found Open list Possible nodes to visit next Closed list Visited nodes Choose next node using A cost function g(n) – cost so far A heuristic function h(n) – remaining
  • Pathfinding: A* heuristic search12 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Open list Possible nodes to visit next Closed list in blue Visited nodes
  • Pathfinding: A* heuristic search13 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Open list in green Possible nodes to visit next Closed list Visited nodes
  • Pathfinding: A* heuristic search14 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Open list in green Possible nodes to visit next Closed list in blue Visited nodes Here exactly one node isexpanded (i.e., the starting node)
  • Pathfinding: A* heuristic search15 Let’s start with a textbook approach Game-world as a grid, A* heuristic search Use f(n) = g(n) + h(n) for eachnode in the open list to pick thenext one to expand f(n) is computed when node n isadded to the open list, whennode n’ is expanded, e.g.: g(n) = g(n’) + 10 if straight g(n) = g(n’) + 14 if diagonal h(n) = manhattan distance to target
  • Pathfinding: A* heuristic search16 Estimated remaining cost h(n) guides the search Cost so far g(n) balances wrt weak estimatesg(n) = 0+10h(n) = 80f(n) = 90
  • Pathfinding: A* heuristic search17 Manhattan distance: x2-x1 + y2-y1 Here it is an accurate estimate as the example is trivialg(n) = 0+10h(n) = 80f(n) = 90
  • Pathfinding: A* heuristic search18 Expanding the node with the minimal value of f(n)..
  • Pathfinding: A* heuristic search19 Expanding the node with the minimal value of f(n)..
  • Pathfinding: A* heuristic search20 Expanding the node with the minimal value of f(n)..
  • Pathfinding: A* heuristic search21 Things become more interesting when there areobstacles in the way
  • Pathfinding: A* heuristic search22 What percentage of the search space will beexpanded (i.e., explored) in this case?
  • Pathfinding: A* heuristic search23 We expect that the search would go directlytoward the destination expanding only nodes to theright, until it hits the wall and then go toward upand down in parallel Then, as the g(n) cost of each expanded nodeincreases though, it forces the search method to lookback and expand also in the other directions awayfrom the goal This way, following a dead-end for too long isavoided, but also more nodes are explored
  • Pathfinding: A* heuristic search24
  • Pathfinding: A* heuristic search25
  • Pathfinding: A* heuristic search26
  • Pathfinding: A* heuristic search27All four nodes are equallypromising
  • Pathfinding: A* heuristic search28f(n1) = 54+50 = 104f(n2) = 44+60 = 104
  • Pathfinding: A* heuristic search29f(n1) = 54+50 = 104f(n2) = 44+60 = 104But why notf(n1) = 60+50 ?f(n2) = 50+60 ?
  • Pathfinding: A* heuristic search30 Some important details What happens when a node is already visited The closed list keeps track about visited nodes Also keeps track of the best way so far to get there When a node n is expanded by node n’, and f(n) isbetter than the value stored in the closed list, then weupdate the f(n) value
  • Pathfinding: A* heuristic search31This node is considered both whenthe two other nodes are expanded
  • Pathfinding: A* heuristic search32 Some important details What happens when a node is already visited The closed list keeps track about visited nodes Also keeps track of the best way so far to get there When a node n is expanded by node n’, and f(n) isbetter than the value stored in the closed list, then weupdate the f(n) value We also need to update the best path that leads there
  • Pathfinding: A* heuristic search33 Keeping track of the best path that leads to a node In general we could store with each node also the paththat takes us there (we will see this in heuristic search A*planning later) Here we just need to store the parent of the node n,i.e., the node n’ that we expanded to get n with thebest f(n) value
  • Pathfinding: A* heuristic search34 Keeping track of the best path that leads to a node In general we could store with each node also the paththat takes us there (we will see this in heuristic search A*planning later) Here we just need to store the parent of the node n,i.e., the node n’ that we expanded to get n with thebest f(n) value This is what these little arrows do in the images we saw
  • Pathfinding: A* heuristic search35
  • Pathfinding: A* heuristic search36
  • Pathfinding: A* heuristic search37f(n1) = 58+60 = 118In fact more costly than the otherf(n2) = 10+100 = 110
  • Pathfinding: A* heuristic search38f(n1) = 58+60 = 118In fact more costly than the otherf(n2) = 10+100 = 110Put it differently: alot of cost g(n1) hasbeen invested, butthe estimated costh(n1) is not smallenough to make theoverall cost f(n1) thebest promising
  • Pathfinding: A* heuristic search39
  • Pathfinding: A* heuristic search40
  • Pathfinding: A* heuristic search41
  • Pathfinding: A* heuristic search42f(n1) = 146h(n2) = 146
  • Pathfinding: A* heuristic search43 Important point about A*! Does A* provide the shortest path?
  • Pathfinding: A* heuristic search44 Important point about A*! Does A* provide the shortest path? It depends on the heuristic One particular class of heuristics that ensure optimalsolutions are the admissible heuristics These are optimistic heuristics that alwaysunderestimate the remaining cost
  • Pathfinding: A* heuristic search45 Important point about A*! Does A* provide the shortest path? It depends on the heuristic One particular class of heuristics that ensure optimalsolutions are the admissible heuristics These are optimistic heuristics that alwaysunderestimate the remaining cost Intuition1: Think of a heuristic that hugely overestimatesthe optimal path and is zero for all other nodes.
  • Pathfinding: A* heuristic search46 Important point about A*! Does A* provide the shortest path? It depends on the heuristic One particular class of heuristics that ensure optimalsolutions are the admissible heuristics These are optimistic heuristics that alwaysunderestimate the remaining cost Intuition2: When heuristic is zero for all nodes, the bestnode is based on total cost so the optimal path is found.
  • Pathfinding: A* heuristic search47 Important point about A*! Does A* provide the shortest path? It depends on the heuristic One particular class of heuristics that ensure optimalsolutions are the admissible heuristics These are optimistic heuristics that alwaysunderestimate the remaining cost (Understanding heuristics will become very importantwhen we talk about heuristic search A* planning later)
  • Pathfinding: A* heuristic search48 Basic options to consider for pathfinding problems Forward/backward/bi-directional search A*/best-first/weighted A*/… Domain-dependent/independent heuristics Manhattan, Chebyshev, Euclidian Heuristics on Amits A* pages Diagonal movement: 4-connected vs 8-connected grid A* playground to try out different combinations http://qiao.github.io/PathFinding.js/visual/
  • Pathfinding: A* heuristic search49
  • Pathfinding: A* heuristic search50h(n): EuclideanGrid: 4-connected
  • Pathfinding: A* heuristic search51h(n): EuclideanGrid: 8-connected
  • Pathfinding: A* heuristic search52h(n): ManhattanGrid: 4-connected
  • Pathfinding: A* heuristic search53h(n): ManhattanGrid: 8-connected
  • Pathfinding: A* heuristic search54 In many cases this is all you need to handlepathfinding in a game (modulo tuning yourimplementation to be efficient) In AAA modern games though, the game-world ismore complicated both in terms of features and interms of size, and tricks (or research) is needed!
  • Pathfinding: A* heuristic search55 More complicated game-worlds Different types of terrain  different cost Road, path, water, terrain, mud, … Different type of characters  different cost/ability Walking units, vehicles, air-units, scouters, … More than one level Stairs, elevators, hills, slopes, … “Nicer” paths are needed! Smoother curves, more “organic”, with variation, … The game-world is huge! Need for memory and CPU efficiency
  • Pathfinding: A* heuristic search56 More complicated game-worlds Different types of terrain  different cost Different type of characters  different cost/ability More than one level “Nicer” paths are needed! The game-world is huge! We can deal with some of these with simple tricks There is a lot of applied and research work! E.g., AI Programming Wisdom book series Also in top AI/Robotics conferences, e.g., AAAI, ICAPS,AIIDE, IROS
  • Pathfinding: A* heuristic search57 Commercial game grid-world benchmarks http://www.movingai.com/benchmarks/
  • Pathfinding: A* heuristic search58 GPPC: Grid-Based Path Planning Competition http://movingai.com/GPPC/cfp.html Maps Size at most 2048x2048 Static (unchanging) 8-connected Diagonal actions in an optimal path cost sqrt(2)
  • Pathfinding: A* heuristic search59 Many neat tricks for efficient/nice pathfinding Alternative game-world representations Better heuristics Beyond A* But first let’s see how this simple grid representationand A* heuristic works in a game setting in Unity
  • Pathfinding Part 2: Examples in Unity60