1 Artificial Intelligence in Games Week 6 Steve Rabin TA: Chi-Hao Kuo TA: Allan.

Slides:



Advertisements
Similar presentations
Heuristic Functions By Peter Lane
Advertisements

Review: Search problem formulation
Informed search strategies
Informed search algorithms
AI Pathfinding Representing the Search Space
An Introduction to Artificial Intelligence
A* Search. 2 Tree search algorithms Basic idea: Exploration of state space by generating successors of already-explored states (a.k.a.~expanding states).
Pathfinding AI John See 29 Nov, 13 Dec 2010.
Informed Search Methods Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 4 Spring 2004.
Heuristics CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Informed Search Methods How can we improve searching strategy by using intelligence? Map example: Heuristic: Expand those nodes closest in “as the crow.
Lecture 12: Revision Lecture Dr John Levine Algorithms and Complexity March 27th 2006.
Pathfinding. “PathEngine is a sophisticated middleware tool- kit for the implementation of intelligent agent movement, built around an advanced implementation.
CSE 380 – Computer Game Programming Pathfinding AI
Search in AI.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
State Space Search Algorithms CSE 472 Introduction to Artificial Intelligence Autumn 2003.
Review: Search problem formulation
Lecture 3 Informed Search CSE 573 Artificial Intelligence I Henry Kautz Fall 2001.
Problem Solving and Search in AI Heuristic Search
Heuristics CSE 473 University of Washington. © Daniel S. Weld Topics Agency Problem Spaces SearchKnowledge Representation Planning PerceptionNLPMulti-agentRobotics.
Chapter 5.4 Artificial Intelligence: Pathfinding.
Chapter 5.4 Artificial Intelligence: Pathfinding.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Graphs II Robin Burke GAM 376. Admin Skip the Lua topic.
1 Game AI Path Finding. A Common Situation of Game AI A Common Situation of Game AI Path Planning Path Planning –From a start position to a destination.
Search: Heuristic &Optimal Artificial Intelligence CMSC January 16, 2003.
1 EE 355 Unit 14 A-Star Algorithm & Heaps/Priority Queues Mark Redekopp.
1 CO Games Development 1 Week 6 Introduction To Pathfinding + Crash and Turn + Breadth-first Search Gareth Bellaby.
P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.
Informed (Heuristic) Search
Informed search algorithms Chapter 4. Best-first search Idea: use an evaluation function f(n) for each node –estimate of "desirability"  Expand most.
Informed search strategies Idea: give the algorithm “hints” about the desirability of different states – Use an evaluation function to rank nodes and select.
Informed Search Strategies Lecture # 8 & 9. Outline 2 Best-first search Greedy best-first search A * search Heuristics.
1 Artificial Intelligence in Games Week 5 Steve Rabin TA: Chi-Hao Kuo TA: Allan.
Administration CI meetings resume next week, as usual Some TAs in labs, plus Dr. Betz –Go to your lab as usual –If your TA is not there, ask for help from.
Review: Tree search Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search.
Toward More Realistic Pathfinding Authored by: Marco Pinter Presentation Date: 11/17/03 Presented by: Ricky Uy.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Advanced Artificial Intelligence Lecture 2: Search.
MDPs (cont) & Reinforcement Learning
Informed Search I (Beginning of AIMA Chapter 4.1)
Search (continued) CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Introduction to Artificial Intelligence Class 1 Planning & Search Henry Kautz Winter 2007.
Feng Zhiyong Tianjin University Fall  Best-first search  Greedy best-first search  A * search  Heuristics  Local search algorithms  Hill-climbing.
State space representations and search strategies - 2 Spring 2007, Juris Vīksna.
1 Artificial Intelligence in Games Week 5 Steve Rabin
Searching for Solutions
1 CO Games Development 1 Week 8 A* Gareth Bellaby.
Graph Search II GAM 376 Robin Burke. Outline Homework #3 Graph search review DFS, BFS A* search Iterative beam search IA* search Search in turn-based.
CSCI 4310 Lecture 4: Search 2 – Including A*. Book Winston Chapters 4,5,6.
CSCE 552 Spring 2010 AI (III) By Jijun Tang. A* Pathfinding Directed search algorithm used for finding an optimal path through the game world Used knowledge.
CPSC 420 – Artificial Intelligence Texas A & M University Lecture 5 Lecturer: Laurie webster II, M.S.S.E., M.S.E.e., M.S.BME, Ph.D., P.E.
CSCE 552 Fall 2012 AI By Jijun Tang. Homework 3 List of AI techniques in games you have played; Select one game and discuss how AI enhances its game play.
For Monday Read chapter 4 exercise 1 No homework.
1 A* search Outline In this topic, we will look at the A* search algorithm: –It solves the single-source shortest path problem –Restricted to physical.
Review: Tree search Initialize the frontier using the starting state
Chapter 5.4 Artificial Intelligence: Pathfinding
Breadth-First Search: Complexity
Heuristic Search Introduction to Artificial Intelligence
Lesson Objectives Aims Understand the following “standard algorithms”:
Path Planning in Discrete Sampled Space
CAP 5636 – Advanced Artificial Intelligence
Heuristics Local Search
Heuristics Local Search
CSCE 552 Spring 2009 AI (III) By Jijun Tang.
The Rich/Knight Implementation
The Rich/Knight Implementation
Presentation transcript:

1 Artificial Intelligence in Games Week 6 Steve Rabin TA: Chi-Hao Kuo TA: Allan Deutsch

2 Questions 1. Name all of the search space representations 2. Name 3 search space representations that represent the walkable surface area. 3. If a pathfinding search algorithm is “complete”, then what does it guarantee? 4. Name 2 search algorithms that are “smart”. 5. A heuristic estimate is a guess of what? 6. Why do we care that a heuristic is admissible? 7. What does it mean for a heuristic to be admissible? 8. A* is a combination of which two search algorithms?

3

4 Diagonal Correctness

5 Project 2: A* Pathfinding START GOAL

6 Project 2: Without Diagonals (Wrong Way) START GOAL

7 Project 2: With Diagonals (Wrong Way) START GOAL

8 Project 2: With Diagonals (Right Way) START GOAL

9 Pathfinding Aesthetics

10 Aesthetic Optimizations Maximize responsiveness How? Make paths more direct Fewer wiggles (rubberbanding)

11 Project 2: Before Simple (Conservative) Rubberbanding START GOAL

12 Project 2: Look at Node Triplets; Eliminate Middle if Area is Clear START GOAL

13 Project 2: After Simple (Conservative) Rubberbanding START GOAL

14 Project 2: Look at Node Triplets; Eliminate Middle if Area is Clear START GOAL

15 Project 2: Look at Node Triplets Eliminate Middle if Area is Clear START GOAL

16 Project 2: Look at Node Triplets; Eliminate Middle if Area is Clear START GOAL

17 Project 2: After Rubberbanding START GOAL

18 Project 2: Straight Line Optimization GOAL START

19 Project 2: Straight Line Optimization (test) GOAL START

20 Project 2: Straight Line Optimization (result) GOAL START

21 Project 2: Straight Line Optimization START GOAL

22 Project 2: Straight Line Optimization (test) START GOAL

23 Aesthetic Optimizations: Smoothed paths Physics-based At movement time – problems? On waypoints before movement (demo) Splines Catmull-Rom Spline (Benefits? Problems?) Bezier Spline (Benefits? Problems?)

24 Catmull-Rom Spline C1 continuity (not C2) Passes through all control points

25 Catmull-Rom to Create In-Between Waypoints output_point = point_1 * (-0.5*s*s*s + s*s – 0.5*s) + point_2 * (1.5*s*s*s *s*s + 1.0) + point_3 * (-1.5*s*s*s + 2.0*s*s + 0.5*s) + point_4 * (0.5*s*s*s – 0.5*s*s); Points are waypoints in 3D s in range [0,1] Consider s=0 and s=1 You MUST understand this: Creates a new waypoint between point_2 and point_3

26 Catmull-Rom to Create In-Between Waypoints (pre-computed) //s = 0.0 output_point = point_2; //s = 0.25 output_point = point_1 * point_2 * point_3 * point_4 * ; //s = 0.5 output_point = point_1 * point_2 * point_3 * point_4 * ; //s = 0.75 output_point = point_1 * point_2 * point_3 * point_4 * ; //s = 1.0 output_point = point_3;

27 Catmull-Rom in DirectX D3DXVec2CatmullRom(D3DXVECTOR2* pOut, CONST D3DXVECTOR2* pV1, CONST D3DXVECTOR2* pV2, CONST D3DXVECTOR2* pV3, CONST D3DXVECTOR2* pV4, FLOAT s) D3DXVec3CatmullRom(D3DXVECTOR3* pOut, CONST D3DXVECTOR3* pV1, CONST D3DXVECTOR3* pV2, CONST D3DXVECTOR3* pV3, CONST D3DXVECTOR3* pV4, FLOAT s)

28 Project 2: After Rubberbanding START GOAL

29 Project 2: Make Nodes Regularly Spaced (<= 1.5 away from each other) START GOAL

30 Project 2: Apply Catmull-Rom Spline START GOAL

31 Project 2: Apply Catmull-Rom Spline START GOAL

32 Smoothing Waypoints: Project 2 Directions 1. Take your generated waypoints list after rubberbanding was OPTIONALLY applied. 2. Make a new list that has waypoints at least 1.5 grid squares away from each other. Basically, if the distance between any 2 consecutive points is > 1.5, then put a new point between them. Repeat as necessary (recursively?) until all are <= 1.5 from each other. 3. Make a new list of smoothed points by creating 3 new points in-between every set of waypoints (using 0.25, 0.5, and 0.75 in the spline formula). 4. Double up on the end-points (see following slides).

Smoothing Waypoints: Using the Formula Problem: Get 3 spline points (A, B, C) between waypoints 20 and 21. Solution: New point A: D3DXVec3CatmullRom(A, point19, point20, point21, point 22, 0.25); New point B: D3DXVec3CatmullRom(B, point19, point20, point21, point 22, 0.50); New point C: D3DXVec3CatmullRom(A, point19, point20, point21, point 22, 0.75); 33

Smoothing Waypoints: Using the Formula (double up at start) Problem: Get 3 spline points (A, B, C) between waypoints 0 and 1 (0 is first waypoint). Solution: New point A: D3DXVec3CatmullRom(A, point0, point0, point1, point2, 0.25); New point B: D3DXVec3CatmullRom(B, point0, point0, point1, point2, 0.50); New point C: D3DXVec3CatmullRom(A, point0, point0, point1, point2, 0.75); 34

Smoothing Waypoints: Using the Formula (double up at end) Problem: Get 3 spline points (A, B, C) between waypoints 49 and 50 (50 is last waypoint). Solution: New point A: D3DXVec3CatmullRom(A, point48, point49, point50, point50, 0.25); New point B: D3DXVec3CatmullRom(B, point48, point49, point50, point50, 0.50); New point C: D3DXVec3CatmullRom(A, point48, point49, point50, point50, 0.75); 35

Smoothing Waypoints: Using the Formula Original Waypoint Path: 0, 1, 2, 3, 4, 5 Final Smoothed Path: 0, A points:0012, s=0.25, B points:0012, s=0.50, C points:0012, s=0.75, 1, A points:0123, s=0.25, B points:0123, s=0.50, C points:0123, s=0.75, 2, A points:1234, s=0.25, B points:1234, s=0.50, C points:1234, s=0.75, 3, A points:2345, s=0.25, B points:2345, s=0.50, C points:2345, s=0.75, 4, A points:3455, s=0.25, B points:3455, s=0.50, C points:3455, s=0.75, 5 36

37 Project 2: After Rubberbanding START GOAL

38 Project 2: Make Nodes Regularly Spaced (<= 1.5 away from each other) START GOAL

39 Project 2: Apply Catmull-Rom Spline START GOAL

40 Project 2: Apply Catmull-Rom Spline START GOAL

41 Project 2: A* Pathfinding (due week 8) Absolute requirement: Draw the open list of quads as one color, the closed list of quads as another color, draw the final path, and have Tiny follow the path Grading (20%) Draw one step of A* each frame (use toggle) (15%) A path is always found if it exists (completeness) (15%) The path is optimal with a heuristic weight of 1.0 (15%) The path is optimal with a heuristic weight of 0.0, and the search grows in a circular pattern (5%) The path uses diagonals and doesn't run into corners (5%) Calculate heuristic using Euclidean, Octile, Chebyshev, and Manhattan methods (use toggle) (5%) Straightline optimization when possible (use toggle) (10%) Rubberband final path where possible (use toggle) (10%) Smooth using a Catmull-Rom spline (use toggle) (-10%) If it crashes at any time

42 A* Speed Optimizations

43 Heuristic Cost Guess the distance to the goal Don't over estimate (to be admissible) Best heuristic cost algorithm? In the general case? On a grid? What about node-to-node cost?

44 Heuristic Calculation Options Manhattan distance xDiff + yDiff = = 12

45 Heuristic Calculation Options Chebyshev distance max(xDiff, yDiff) = max(9,3) = 9

46 Heuristic Calculation Options Euclidean sqrt(xDiff 2 + yDiff 2 ) = sqrt( ) = 9.48

47 Heuristic Calculation Options Octile min(xDiff,yDiff) * sqrt(2) + max(xDiff,yDiff) – min(xDiff,yDiff) = min(9,3) * max(9,3) – min(9,3) = 10.24

48 Which are admissible? (never overestimates the true cost) Chebyshev distance Manhattan distance Euclidean distance Octile

49 Which are admissible? Which one is best? Chebyshev distance = 9 Manhattan distance = 12 Euclidean distance = 9.48 Octile = 10.24

50 Open List Sorting Unsorted List Pop: O(n)Brute force search for cheapest Push: O(1)Trivial to push Update: O(0)No work needed – List is not sorted Priority Queue (binary tree) Pop: O(log n) Push: O(log n) Update: O(n)Note: Typical P-Queues don’t support this Fibonacci Heap Pop: O(log n) *worst case O(n) Push: O(1) Update: O(n) ???

51 Open List Sorting: Unordered List (fast array) ABCDEFG Starting Configuration:

52 Open List Sorting: Unordered List (fast array) ABCDEFG 1. Increment Last Push Node O(1): Starting Configuration: ABCDEFG

53 Open List Sorting: Unordered List (fast array) ABCDEFG 1. Increment Last 2. Write Node Push Node O(1): Starting Configuration: ABCDEFGH

54 Open List Sorting: Unordered List (fast array) ABCDEFG 1. Increment Last 2. Write Node Push Node O(1): Starting Configuration: ABCDEFGH Pop Cheapest O(n): 1. Find Cheapest (B) ABCDEFGH

55 Open List Sorting: Unordered List (fast array) ABCDEFG 1. Increment Last 2. Write Node Push Node O(1): Starting Configuration: ABCDEFGH Pop Cheapest O(n): 1. Find Cheapest (B) ABCDEFGH 2. Replace with Last

56 Open List Sorting: Unordered List (fast array) ABCDEFG 1. Increment Last 2. Write Node Push Node O(1): Starting Configuration: ABCDEFGH Pop Cheapest O(n): 1. Find Cheapest (B) 2. Replace with Last ABCDEFGH

57 Open List Sorting: Unordered List (fast array) ABCDEFG 1. Increment Last 2. Write Node Push Node O(1): Starting Configuration: ABCDEFGH Pop Cheapest O(n): 1. Find Cheapest (B) 2. Replace with Last 3. Decrement Last AHCDEFG

58 Open List Sorting: Unordered List (fast array) ABCDEFG 1. Increment Last 2. Write Node Push Node O(1): Starting Configuration: ABCDEFGH Pop Cheapest O(n): 1. Find Cheapest (B) 2. Replace with Last 3. Decrement Last AHCDEFG Update O(0):No work (list not sorted)

59 Overestimating Heuristic Cost A* combines Best-First and Dijkstra Given cost and Heuristic cost Final cost = Given cost + (Heuristic cost * weight) f(x) = g(x) + (h(x) * weight) Consider what different weights do like 0, 1, and 2 Demo

60 Cluster Heuristic From book (p235) Cluster A Cluster C Cluster B A B C A B C x x x Precomputed Table

61 Hierarchical Pathfinding Whiteboard Demo

62 Other Ideas Bidirectional pathfinding When is it a good idea? 50 NPCs want paths simultaneously What’s your strategy? Global optimization?

63 A* Speed Enhancements: Terrible Ideas Work on all paths simultaneously Bidirectional pathfinding Cache failed start-end pairs Return partial paths if run out of time

64 Project 2: A* Pathfinding (due week 8) Absolute requirement: Draw the open list of quads as one color, the closed list of quads as another color, draw the final path, and have Tiny follow the path Grading (20%) Draw one step of A* each frame (use toggle) (15%) A path is always found if it exists (completeness) (15%) The path is optimal with a heuristic weight of 1.0 (15%) The path is optimal with a heuristic weight of 0.0, and the search grows in a circular pattern (5%) The path uses diagonals and doesn't run into corners (5%) Calculate heuristic using Euclidean, Octile, Chebyshev, and Manhattan methods (use toggle) (5%) Straightline optimization when possible (use toggle) (10%) Rubberband final path where possible (use toggle) (10%) Smooth using a Catmull-Rom spline (use toggle) (-10%) If it crashes at any time

65 JPS+ with Goal Bounding

66 Company of Heroes GDC 2007 Presentation