Game Engine Architecture

Slides:



Advertisements
Similar presentations
Problem solving with graph search
Advertisements

AI Pathfinding Representing the Search Space
CSE 380 – Computer Game Programming Pathfinding AI
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Spanning Trees.
Pathfinding Algorithms Josh Palmer Rachael Beers.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Chapter 5.4 Artificial Intelligence: Pathfinding.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
Graphs. Made up of vertices and arcs Digraph (directed graph) –All arcs have arrows that give direction –You can only traverse the graph in the direction.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
Dijkstra’s Algorithm: single source shortest paths David Kauchak cs62 Spring 2010.
Graphs – Part II CS 367 – Introduction to Data Structures.
Lecture 3: Uninformed Search
Toward More Realistic Pathfinding Authored by: Marco Pinter Presentation Date: 11/17/03 Presented by: Ricky Uy.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
Breadth First Search and Depth First Search. Greatest problem in Computer Science Has lead to a lot of new ideas and data structures Search engines before.
A* Reference: “Artificial Intelligence for Games”, Ian Millington.
4: Network Layer4-1 Chapter 4: Network Layer Last time: r Chapter Goals m Understand network layer principles and Internet implementation r Started routing.
Graphs + Shortest Paths David Kauchak cs302 Spring 2013.
CS 6401 Intra-domain Routing Outline Introduction to Routing Distance Vector Algorithm.
CS 367 Introduction to Data Structures Lecture 13.
Beard & McLain, “Small Unmanned Aircraft,” Princeton University Press, 2012, Chapter 12: Slide 1 Chapter 12 Path Planning.
A* Reference: “Artificial Intelligence for Games”, Ian Millington.
Graphs – Part III CS 367 – Introduction to Data Structures.
Graphs - II CS 2110, Spring Where did David leave that book? 2.
Chapter 3 Solving problems by searching. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known.
Data Structures and Algorithms I
Chapter 5.4 Artificial Intelligence: Pathfinding
Graphs Chapter 15 introduces graphs which are probably the most general and commonly-used data structure. This lecture introduces heaps, which are used.
Heaps and Priority Queues
Depth First Seach: Output Fix
May 12th – Minimum Spanning Trees
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
Programming Abstractions
Minimum Spanning Trees
Cse 373 May 8th – Dijkstras.
Lesson Objectives Aims Understand the following “standard algorithms”:
Week 11 - Friday CS221.
Single-Source Shortest Paths
Minimum Spanning Trees and Shortest Paths
Maze Implementation, Analysis and Design to find Shortest Paths
ECE 544 Protocol Design Project 2016
Programming Abstractions
Programming Abstractions
Crowd Simulation (INFOMCRWS) - A* Search
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Intradomain Routing Outline Introduction to Routing
A* Path Finding Ref: A-star tutorial.
Spanning Trees.
Outline This topic covers Prim’s algorithm:
Reference: “Artificial Intelligence for Games”, Ian Millington.
CS Fall 2016 (Shavlik©), Lecture 10, Week 6
Chapter 11 Graphs.
Yan Shi CS/SE 2630 Lecture Notes
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Workshop: A* Search.
CSE 373 Data Structures and Algorithms
Informed Search Idea: be smart about what paths to try.
Dijkstra's Shortest Path Algorithm
Implementation of Dijkstra’s Algorithm
Graphs: Shortest path and mst
Informed Search Idea: be smart about what paths to try.
Data Structures and Algorithms I
Presentation transcript:

Game Engine Architecture CS 134 Pathfinding Game Engine Architecture Chapter 14

Today in Video Games

Navigation Graph To do navigation, you need a graph representing the navigable positions Put this intelligence into the world! For a small game, hand-generate this

Navigation Graph // Describes all connections between nodes ArrayList<GraphNode> graph; // A specific node in the graph class GraphNode { public NodeLink[] links; // Other data the AI cares about } // A connection from one node to another class NodeLink { // Index into graph public int destNode; // How far apart the nodes are public float cost; // How you move between nodes, e.g. // “WalkLeft”, “WalkRight”, “JumpLeft”, etc NodeLinkType type;

Navigation Graph Flat top down levels don't need a separate graph Tile grid already has navigation and collision Assume links go in eight directions, so long as not blocked

Navigation Graph Any level with jumping will need to know how to move GraphLinkType WalkLeft, WalkRight JumpLeft, JumpRight, JumpUp HighJumpLeft, HighJumpRight, HighJumpUp etc.

Navigation Graph The key concept: An AI must be able to figure out exactly what moves to do to follow a collection of links. Every type of motion possible should be in the links.

Navigation – Dijkstra's Algorithm Visit all reachable nodes from closest to furthest For each visited node, remember where you came from

Navigation – Dijkstra's Algorithm Create a priority queue of all nodes Mark S as distance 0, all other nodes as infinity While the cheapest node has non-infinite distance: If node is D, found, follow path back! Remove node from priority queue For each neighbor, update distance and prev node

Navigation – Dijkstra's Algorithm

Navigation – Dijkstra's Algorithm Performance Concerns: You end up visiting a lot of irrelevant nodes Worst case you have to visit every single node DO NOT CALL EVERY FRAME

Navigation – A* Algorithm Visit nodes in order of “total estimated cost” = time to get to node + estimated time to get to destination For each node, remember parent

Navigation – A* Algorithm NOTE: You will commonly find discussion of an “open” and “closed” list in implementations of the A* algorithm. This is an optimization and not strictly necessary.

Navigation – A* Algorithm F = total expected cost (G + H) G = cost to get to current node H = estimated cost to get to node Visit nodes in F order (Dijsktra's Algorithm visits nodes purely in G order)

Navigation – A* Algorithm Create a priority queue of all nodes Calculate H for all nodes Mark S with G=0, all other nodes as infinity While the cheapest node has non-infinite distance: If node is D, found, follow path back! Remove node from priority queue For each neighbor, update G and prev node

Navigation – A* Algorithm About those Open and Closed sets... They just makes finding the cheapest node faster The Open Set is all nodes that have non-infinite F, so a G has been calculated The Closed Set is all nodes that have been removed from the priority queue.

Navigation – A* Algorithm

Navigation Use A* when you know where to go, but you don't know how to get there Use Dijkstra's when you don't know where to go or how to get there And there will be a bonus algorithm next class!

Navigation – Game Loop Runtime performance of pathfinding is SPIKEY Very slow, but not usually needed May end up with multiple pathfinds needed in a single frame. Do as much as you can each frame, but don't go over some ms budget Check time after every pathfind, and if you've gone over budget, stop pathfinding until the next frame