CS 4730 AI and Pathfinding CS 4730 – Computer Game Design Some slides courtesy Tiffany Barnes, NCSU.

Slides:



Advertisements
Similar presentations
Wall Building for RTS Games Patrick Schmid. Age of Empires.
Advertisements

AI Pathfinding Representing the Search Space
RL for Large State Spaces: Value Function Approximation
Oct 30, Fall 2006IAT 4101 AI in games Simple steering, Flocking Production rules FSMs, Probabilistic FSMs Path Planning, Search Unit Movement Formations.
Oct 6, Fall 2005Game Design1 AI in games Simple steering, Flocking Production rules FSMs, Probabilistic FSMs Path Planning, Search Unit Movement Formations.
Problem Solving Agents A problem solving agent is one which decides what actions and states to consider in completing a goal Examples: Finding the shortest.
Chapter 4 Search Methodologies.
CSE 380 – Computer Game Programming Pathfinding AI
CSC 423 ARTIFICIAL INTELLIGENCE
PATHFINDING WITH A* Presented by Joseph Siefers February 19 th, 2008.
Search in AI.
Search Strategies.  Tries – for word searchers, spell checking, spelling corrections  Digital Search Trees – for searching for frequent keys (in text,
Best-First Search: Agendas
Problem Solving and Search in AI Part I Search and Intelligence Search is one of the most powerful approaches to problem solving in AI Search is a universal.
Mahgul Gulzai Moomal Umer Rabail Hafeez
CS 4730 Game AI CS 4730 – Computer Game Design Some slides courtesy Tiffany Barnes, NCSU.
Review: Search problem formulation
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2004.
1 Chapter 4 Search Methodologies. 2 Chapter 4 Contents l Brute force search l Depth-first search l Breadth-first search l Properties of search methods.
MAE 552 – Heuristic Optimization Lecture 27 April 3, 2002
Intelligent Agents What is the basic framework we use to construct intelligent programs?
Pathfinding Algorithms Josh Palmer Rachael Beers.
Problem Solving and Search in AI Heuristic Search
5-Nov-2003 Heuristic Search Techniques What do you do when the search space is very large or infinite? We’ll study three more AI search algorithms: Backtracking.
Chapter 5.4 Artificial Intelligence: Pathfinding.
Heuristic Search Heuristic - a “rule of thumb” used to help guide search often, something learned experientially and recalled when needed Heuristic Function.
Dijkstra’s Algorithm and Heuristic Graph Search David Johnson.
Review: Search problem formulation Initial state Actions Transition model Goal state (or goal test) Path cost What is the optimal solution? What is the.
Chapter 5.4 Artificial Intelligence: Pathfinding.
Lab 3 How’d it go?.
Graphs II Robin Burke GAM 376. Admin Skip the Lua topic.
Vilalta&Eick: Informed Search Informed Search and Exploration Search Strategies Heuristic Functions Local Search Algorithms Vilalta&Eick: Informed Search.
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.
1 CO Games Development 1 Week 6 Introduction To Pathfinding + Crash and Turn + Breadth-first Search Gareth Bellaby.
WAES 3308 Numerical Methods for AI
How are things going? Core AI Problem Mobile robot path planning: identifying a trajectory that, when executed, will enable the robot to reach the goal.
Introduction to search Chapter 3. Why study search? §Search is a basis for all AI l search proposed as the basis of intelligence l all learning algorithms,
P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.
State-Space Searches. 2 State spaces A state space consists of A (possibly infinite) set of states The start state represents the initial problem Each.
AI in game (II) 권태경 Fall, outline Problem-solving agent Search.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
Informed Search Methods. Informed Search  Uninformed searches  easy  but very inefficient in most cases of huge search tree  Informed searches  uses.
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.
Lecture 3: Uninformed Search
CSCI 4310 Lecture 6: Adversarial Tree Search. Book Winston Chapter 6.
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Advanced Artificial Intelligence Lecture 2: Search.
Search (continued) CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
1 CO Games Development 1 Week 13 - Revision Lecture AI Revision Gareth Bellaby.
Graph Algorithms GAM 376 Robin Burke Fall Outline Graphs Theory Data structures Graph search Algorithms DFS BFS Project #1 Soccer Break Lab.
Heuristic Functions. A Heuristic is a function that, when applied to a state, returns a number that is an estimate of the merit of the state, with respect.
Search Techniques CS480/580 Fall Introduction Trees: – Root, parent, child, sibling, leaf node, node, edge – Single path from root to any node Graphs:
Game tree search Chapter 6 (6.1 to 6.3 and 6.6) cover games. 6.6 covers state of the art game players in particular. 6.5 covers games that involve uncertainty.
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.
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.
Artificial Intelligence Lecture No. 8 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science, COMSATS Institute of Information Technology.
Best-first search is a search algorithm which explores a graph by expanding the most promising node chosen according to a specified rule.
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.
Beard & McLain, “Small Unmanned Aircraft,” Princeton University Press, 2012, Chapter 12: Slide 1 Chapter 12 Path Planning.
1 CO Games Development 2 Week 13 Influence Maps Gareth Bellaby.
For Monday Read chapter 4 exercise 1 No homework.
Understanding AI of 2 Player Games. Motivation Not much experience in AI (first AI project) and no specific interests/passion that I wanted to explore.
Chapter 3 Solving problems by searching. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known.
Chapter 5.4 Artificial Intelligence: Pathfinding
Artificial Intelligence Problem solving by searching CSC 361
Motion Planning for a Point Robot (2/2)
CIS 488/588 Bruce R. Maxim UM-Dearborn
(1) Breadth-First Search  S Queue S
CSCE 552 Spring 2009 AI (III) By Jijun Tang.
Presentation transcript:

CS 4730 AI and Pathfinding CS 4730 – Computer Game Design Some slides courtesy Tiffany Barnes, NCSU

CS 4730 AI Strategies Reaction vs. Deliberation When having the NPC make a decision, how much thought goes into the next move? How is the AI different in: –Frozen Synapse –Kingdom Hearts –Civilization –Halo 2

CS 4730 AI Strategies Reaction-Based –Fast, but limited capabilities Implementations –Finite-State Machines –Rule-Based Systems –Set Pattern 3

CS 4730 AI Strategies Deliberation-Based –Much slower, but more adaptable Implementations –A* / Dijkstra –Roadmaps –Genetic Algorithms 4

CS 4730 Deliberation Goal is to emphasize making the best possible decision by searching across all possibilities Thus, deliberation tends to use various search algorithms across data structures that contain the option space 5

CS 4730 “Sense – Plan – Act” Sense (or perceive) a sufficiently complete model of the world Plan by searching over possible future situations that would result from taking various actions Act by executing the best course of action Each possible outcome is effectively scored by a “metric of success” that indicates whether the choice should be taken or not 6

CS 4730 Deliberative vs. Reactive These are NOT mutually exclusive! You can have reactive policies for immediate threats –Incoming PC fire –Environmental destruction And you can have deliberative policies for long- term planning –Build orders and positioning 7

CS 4730 Core Questions How do you represent knowledge about the current task, environment, PC, etc? How do you find actions that allow the goal to be met? 8

CS 4730 Knowledge Representation A decision tree is a common way to represent knowledge The root node is the current state of the game state WRT the NPC / AI Thus, deliberative AI techniques are effectively versions of search and shortest-path algorithms! 9

CS 4730 Tic-Tac-Toe What is the decision tree for Tic-Tac-Toe? 10

CS 4730 The Goal State The objective of the decision tree model is to move from the initial game state (root of the tree) to the goal state of the NPC –What might a goal state be? When searching through the decision tree space, which path do we take? 11

CS 4730 Cost and Reward Every choice has a cost –Ammo –Movement –Time –Increase vulnerability to attack Every choice has a reward –Opportunity to hit PC –Capture a strategic point –Gain new resources 12

CS 4730 Minimax Algorithm Find the path through the decision tree that yields the best outcome for one player, assuming the other player always makes a decision that would lead to the best outcome for themselves 13

CS 4730 Naïve Search Algorithms Breadth-First Search –At each depth, explore every option at the next depth Depth-First Search –Fully explore one possible path to its “conclusion”, then backtrack to check other options What are the problems with these techniques in gaming? 14

CS 4730 Breadth-First Search Expand Root node –Expand all Root node ’ s children Expand all Root node ’ s grandchildren Problem: Memory size Root Child1 Child2 Root Child1 Child2 GChild1 GChild2 GChild3 GChild4

CS 4730 Uniform Cost Search Modify Breadth-First by expanding cheapest nodes first Minimize g(n) cost of path so far Root Child1 Child2 GChild1 9 GChild2 5 GChild3 3 GChild4 8

CS 4730 Depth First Search Always expand the node that is deepest in the tree Root Child1 GChild1 GChild2 Root Child1 Root Child1 GChild1

CS 4730 Adding a Heuristic Simple definition: a heuristic is a “mental shortcut” to ignore non-useful states to limit the search space and make the decision tree more reasonable What metrics might we use to determine “the value” of a potential option? What metrics might we use to determine “the cost” of a potential option? 18

CS 4730 Adding a Heuristic Creating an AI heuristic forms the basis of how the NPCs will behave –Will they ignore enemies that are farther than X away? –Will they avoid water? –Will they always move in the straightest path to the PC? 19

CS 4730 Cheaper Distance First! 20

CS 4730 Greedy Search Expand the node that yields the minimum cost –Expand the node that is closest to target –Depth first –Minimize the function h(n) the heuristic cost function

CS 4730 Greedy Search 22

CS 4730 Greedy Search 23

CS 4730 Greedy Search Greedy gives us (often) a sub-optimal path, but it’s really cheap to calculate! How can we improve on this? Add another aspect to the function – the cost of the node + the heuristic distance 24

CS 4730 A* A best-first search (using heuristics) to find the least-cost path from the initial state to the goal state The algorithm follows the path of lowest expected cost, keeping a priority queue of alternate path segments along the way 25

CS 4730 A* Search Minimize sum of costs g(n) + h(n) –Cost so far + heuristic to goal Guaranteed to work –If h(n) does not overestimate cost Examples –Euclidean distance

CS 4730 A* 27

CS 4730 A* 28

CS 4730 A* 29

CS 4730 Navigation Grid 30

CS 4730 Pathfinding in “real life” These algorithms work great when the game is grid based –Square grid –Hex grid For more “open” games, like FPSs: –Path nodes are placed on the map that NPCs can reach –Navigation mesh layers are added over the terrain –Often done automatically in advanced engines 31

CS 4730 Navigation Mesh Instead of using discrete node locations, a node in this instance is a convex polygon Every point inside a valid polygon can be considered “fair game” to move into Navigation meshes can be auto generated by the engine, so easier to manage than nodes Can also handle different sized NPCs by checking collisions 32

CS 4730 Navigation Mesh 33

CS 4730 Groups Groups stay together –All units move at same speed –All units follow the same general path –Units arrive at the same time Obstruction Goal

CS 4730 Groups Need a hierarchical movement system Group structure –Manages its own priorities –Resolves its own collisions –Elects a commander that traces paths, etc Commander can be an explicit game feature

CS 4730 Formations Groups with unit layouts –Layouts designed in advance Additional States –Forming –Formed –Broken Only formed formations can move

CS 4730 Formations Schedule arrival into position –Start at the middle and work outwards –Move one unit at a time into position –Pick the next unit with Least collisions Least distance –Formed units have highest priority Forming units medium priority Unformed units lowest

CS 4730 Formations Not so good… Better…

CS 4730 Formations: Wheeling Only necessary for non-symmetric formations Break formation here Stop motion temporarily Set re-formation point here

CS 4730 Formations: Obstacles Scale formation layout to fit through gaps Subdivide formation around small obstacles

CS 4730 Formations Adopt a hierarchy of paths to simplify path- planning problems High-level path considers only large obstacles –Perhaps at lower resolution –Solves problem of gross formation movement –Paths around major terrain features

CS 4730 AI That Learns Imagine a player in Madden calls a particular play on offense over and over and over The heuristic values for certain states should change to reflect a more optimal strategy Now, the adjustment of heuristic values represents long-term strategy (to a degree) 42

CS 4730 AI That Evolves Neural networks add in a mutation mechanic Bayesian networks can also learn and add inferences How much processing power can we use for this? Is it better to truly have a “learning” AI, or should we just adjust some game parameters? 43