+ All Categories
Home > Documents > 1 Artificial Intelligence in Games Week 5 Steve Rabin [email protected] TA: Chi-Hao Kuo...

1 Artificial Intelligence in Games Week 5 Steve Rabin [email protected] TA: Chi-Hao Kuo...

Date post: 13-Jan-2016
Category:
Upload: todd-collins
View: 215 times
Download: 0 times
Share this document with a friend
111
1 Artificial Intelligence in Games Week 5 Steve Rabin [email protected] www.aiwisdom.com/digipen TA: Chi-Hao Kuo ([email protected]) TA: Allan Deutsch ([email protected])
Transcript
Page 1: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

1

Artificial Intelligence in GamesWeek 5

Steve [email protected]

www.aiwisdom.com/digipen

TA: Chi-Hao Kuo ([email protected])TA: Allan Deutsch ([email protected])

Page 2: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

2

Project 1B: Behavior Trees How did it go? Thoughts?

If you didn’t turn it in… You must email it! One day late 50% penalty (up to 33 hours late –

3AM)

Page 3: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

3

Questions1. Group emergent behavior: The group behavior

emerges from what?2. Flocking: What are the individual agents called?3. Flocking: Name the 3 primary steering behaviors.4. Flocking: Name the other 3 helpful steering

behaviors.5. Flocking: How is the leader chosen?6. Name as many steering behaviors as you can.7. Formations: Describe the 2 levels of steering.

Page 4: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

4

Page 5: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

5

Swarm of Nano Quadroters!!!

http://www.youtube.com/watch?v=YQIMGV5vtd4

Page 6: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

6

News Flash!!!

Dateline: Thu Oct 1, 6:06 AM

http://ca.news.yahoo.com/s/afp/091001/oddities/

japan_auto_technology_offbeat

Page 7: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

7

"Cars may one day mimic fish to avoid collisions" TOKYO (AFP) - Engineers in

Japan say they are a step closer to developing technology they hope will cut the risk of car crashes -- by mimicking the behavior of fish.

The experts at Nissan Motor have been studying fish and the way they are able to swim in schools and avoid colliding with each other.

Page 8: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

8

Nissan:Welcome back to 1987!!!

Page 9: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

9

Cars may one day mimic fish to avoid collisions The result is a robot that can travel in a

group of up to seven, avoiding bumps by sharing information with its peers.

The firm hopes to use the technology in its vehicles in future.

The three-wheeled robot uses a laser range finder, which measures the distance to an obstacle, and radio communications to recreate the behavior of fish, which can change direction and travel side by side without colliding.

Page 10: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

10

Cars may one day mimic fish to avoid collisions Last year Nissan unveiled a similar robot inspired

by the bumblebee, which is also highly adept at avoiding collisions but travels solo.

"We, in a motorized world, have a lot to learn from the behavior of a school of fish in terms of each fish's degree of freedom and safety," said Toshiyuki Andou, the principal engineer in the project.

By sharing information, the group can travel safely, changing its shape as needed, Andou said.

Nissan will demonstrate the technology at the CEATEC electronics trade fair in Japan next week.

Page 11: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

11

Movement Two types

Reactive movement Planned movement

Page 12: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

12

Planned Movement Define a search space

representation Apply a search algorithm to find a

path Optional: Post-process path Agent follows path

Page 13: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

13

Search Space Representations Represent terrain with a data

structure What kind?

Search data structure to find a path from point A to point B

Let's brainstorm some types of graph data structures...

Page 14: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

14

Search Space Representations:Important Questions to Ask How does search space scale?

Larger search space = slower search

How does search space get made? Level Designer or Algorithm?

Does search space represent safe paths or safe walkable areas or both?

Page 15: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

15

Search Space Representations Regular grids Waypoint graphs Corner graphs Circle-based waypoint graphs Navigation meshes

Page 16: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

16

Search Space Representations:Regular Grid

Page 17: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

17

Search Space Representations:Regular Grid

Rectangular Grid vs Hex Grid Hex grids

How do you index them? Advantages? Disadvantages?

Page 18: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

18

Search Space Representations: Waypoint Graphs Must be hand-placed Common in FPS games

Page 19: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

19

Search Space Representations:Corner Graphs (Points of Visibility)

Page 20: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

20

Search Space Representations: Circle-based Waypoint Graphs Waypoints that only connect to overlapping

circles Characters can move freely within a circle Good for open terrain Bad for angular environments

Page 21: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

21

Search Space Representations: Navigation Meshes Types

Triangle mesh N-sided polygon mesh

Ideal for 3D games Can be extracted from level geometry

Page 22: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

22

Which Search Space Representation? Consider

Amount of designer intervention Amount of technology that must be developed Scalability Terrain type Local pathfinding

Grid representation Essentially 2D games Successful in RTS genre with 100’s to 1000’s of agents

Waypoint representation 3D FPS type environments with few agents Hand placement and local pathfinding limit viability with ever

increasing worlds Navigation Mesh

3D games with many complex terrain features (like pits) Can be automated

Page 23: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

23

Local Obstacles Characters, crates, etc not

represented in search space What can be done? What about pits?

Page 24: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

24

Ledges and Jumps How should this work? How should the path planning

algorithm deal with this?

Page 25: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

25

Doors and Elevators Elevator requires:

Hit button Wait for door to open Pass through door

Page 26: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

26

Intermission

Page 27: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

Origin of the word “Robot”

1920 Czech play:“Rossum’s Universal Robots”

27

Page 28: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

28

Page 29: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

29

Page 30: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

30

Page 31: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

31

Page 32: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

32

Page 33: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

33

Page 34: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

34

Page 35: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

FDA-approved SpineAssist spine-surgery robot Propelled by micro legs 1mm x 14mm

35

Page 36: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

36

Page 37: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

37

Page 38: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

38

Page 39: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

39

Page 40: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

Real Flying Robot Bugs Robotic insects make first controlled

flight https://www.youtube.com/watch?v=cyjKOJhIiuU

40

Page 41: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

41

Pathfinding

Planning your Pathwith Intelligent Search

Page 42: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

42

Pathfinding Goal is to find an optimal path if one exists

Optimal? Is that the shortest path? Search algorithms explore the search

space to find a path from the start to the goal

Many different search algorithms Random Bounce/Trace Breadth-First Best-First Dijkstra A*

Page 43: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

43

Criteria to Judge Pathfinding Algorithms Quality of path

Shortest, cheapest Resource requirements

CPU, memory, time Completeness

Will find a path if one exists

Page 44: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

44

Thinking about Algorithms:Sorting What’s the stupidest/worst

algorithm you could come up with for sorting?

Page 45: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

45

Thinking about Algorithms:Sorting Luckysort

Already sorted, O(0)

Bozosort Randomly swap two elements and test if sorted,

repeat

Bogosortfunction bogosort(array)

while !is_sorted(array)

array = random_permutation(array)

Page 46: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

46

Pathfinding Algorithms What’s the stupidest/worst

algorithm you could come up with for pathfinding?

Page 47: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

47

Random Bounce Search directly toward the goal If obstacle

Randomly move in a direction Repeat until goal reached

Page 48: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

48

Random Bounce Not a complete search algorithm Path found is likely not optimal Consumes very little memory

Page 49: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

49

Random Trace Search directly toward the goal If obstacle

Randomly trace clockwise or counter-clockwise around it

Repeat until goal reached

Page 50: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

50

Random Trace How will Random trace do on the

following maps?

Page 51: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

51

Random Trace Simple version not a complete

search algorithm With enough tweeking, maybe it can

be Path found is likely not optimal Consumes very little memory

Page 52: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

52

Working Toward A*:Terminology Search Space – connected graph to be explored Node – the individual locations of the search space Start Node – the place where the search will begin Goal Node – the goal location of the search

Heuristic – a function, h(n), that returns an estimate of the cheapest cost from a Node to the Goal Node

Admissible – if h(n) never overestimates the cost of getting to the Goal Node

Page 53: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

53

Working Toward A*:Open and Closed Lists Concept of Open and Closed Lists

Open List: Promising nodes not yet explored

Closed List: Nodes already explored

Page 54: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

54

Working Toward A*:General Structure of Algorithms

1. Push Start Node onto the Open List2. While (Open List not empty)

a. Pop a node from the Open List (parent node)b. If node is Goal Node, then path foundc. Find neighboring child nodes and add them to the Open Listd. Place parent node on the Closed List

Page 55: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

55

Working Toward A*:What Does a Node Look Like? Like this?

class PlannerNode

{

public:

PlannerNode *m_pParent;

int m_cellX, m_cellY;

...

};

Page 56: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

56

Breadth-First Explores the search space ply-by-

ply

Page 57: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

57

Breadth-First Characteristics It is a complete algorithm Exhaustive and systematic

but not very clever High Memory Consumption Finds the path with fewest nodes

Not the shortest or cheapest path!

Page 58: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

58

Best-First Uses problem specific knowledge Heads straight for the goal Computes estimated distance of node to

goal Heuristic, h(x), to order Open List

Page 59: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

59

Best-First:Problem Case

Page 60: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

60

Best-First Characteristics It is a complete algorithm Heuristic search Uses fewer resources than

Breadth-First Finds good paths

Doesn’t guarantee optimal path

Page 61: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

61

Dijkstra Uses accumulated distance to

order nodes on Open List Accumulated cost from Start Node

to current node is called given cost, g(x)

Note: not a heuristic search No estimation involved

Page 62: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

62

Dijkstra It is a complete algorithm

It is an exhaustive search Always finds the most optimal path About as resource intensive as

Breadth-First

Page 63: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

63

Intermission:Great Moments in Game Art History

Page 64: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

64

Intermission:Great Moments in Game Art History

Page 65: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

65

Intermission:Great Moments in Game Art History

Page 66: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

66

Intermission:Great Moments in Game Art History

Page 67: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

67

Intermission:Great Moments in Game Art History

Page 68: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

68

Intermission:Great Moments in Game Art History

Page 69: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

69

Intermission:Great Moments in Game Art History

Page 70: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

Intermission:Great Moments in Game Art History

70

Page 71: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

71

A* Combines Best-First and Dijkstra

Given cost and Heuristic cost

Open List sorted by: Final cost = Given cost + (Heuristic cost *

weight) f(x) = g(x) + (h(x) * weight) Consider what different weights do

like 0, 1, and 2

Page 72: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

72

A* Doesn’t fall into Best-First trap

Page 73: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

73

A* Characteristics It is a complete algorithm Heuristic search On average uses fewer resources than

Breadth-First and Dijkstra If admissible heuristic used, guarantees

optimal path Admissible – if h(n) never overestimates the

cost of getting to the Goal Node How do you not overestimate the cost? What happens if you do overestimate it?

Page 74: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

74

A* Algorithm:Walkthrough

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 75: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

75

A* Algorithm:Initial: Start/Goal Nodes, Lists empty

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 76: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

76

A* Algorithm:3 ways to exit

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 77: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

77

A* Algorithm:Prime the algorithm with the 1st node

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 78: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

78

A* Algorithm:While nodes still on Open List

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 79: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

79

A* Algorithm:No path found

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 80: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

80

A* Algorithm:Get next parent node to work with

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 81: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

81

A* Algorithm:Goal found?

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 82: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

82

A* Algorithm:Loop through child nodes

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 83: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

83

A* Algorithm:Compute child cost, f(x)

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 84: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

84

A* Algorithm:Put child node on Open List? (easy)

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 85: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

85

A* Algorithm:Put child node on Open List? (careful!)

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 86: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

86

A* Algorithm:Done with parent node

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 87: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

87

A* Algorithm:Aborting this frame (for single step)

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 88: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

88

A* Algorithm:3 ways to return

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 89: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

89

A* Algorithm:Walkthrough

Push Start Node onto the Open ListWhile (Open List is not empty) {

Pop cheapest node off Open List (parent node)If node is the Goal Node, then path found (RETURN “found”)For (all neighboring child nodes) {

Compute its cost, f(x) = g(x) + h(x)If child node isn’t on Open or Closed list, put it on Open List.If child node is on Open or Closed List, AND this new one is cheaper,

then take the old expensive one off both lists and put this new cheaper one on the Open List.

}Place parent node on the Closed List (we’re done with it)If taken too much time this frame (or in single step mode), abort

search for now and resume next frame (RETURN “working”)}Open List empty, thus no path possible (RETURN

“fail”)

Page 90: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

90

A* Worksheet

Page 91: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

91

A* DetailsNode data (for a given square)

parentRow; //Parent node (-1 is start node)parentCol; //Parent node (-1 is start node)

float cost; //Cost to get to this node, g(x)

float total; //Total cost, g(x) + h(x)

bool onOpen; //On Open Listbool onClosed; //On Closed List

Page 92: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

92

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

Page 93: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

93

Project 2:A* Pathfinding

Extra Credit (bells and whistles)

1 bell = 10% added to project grade

=

Page 94: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

94

Project 2:A* Pathfinding Extra Credit

Implement Roy-Floyd-Warshall algorithm (in addition to A*). Must offer on-screen button to toggle on/off.

Implement Goal Bounding. Must offer an on-screen toggle to switch between A* and Goal Bounding. Hook it up to the timing.

Page 95: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

95

Project 2:A* Pathfinding Extra Credit

Be in top 3 fastest class times on an A* search.

Beat 10 percent exe (Rabin)OR

Beat 15 percent exe (Fernando)OR

Beat 20 percent exe (Trent Reed)

Page 96: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

96

Project 2:A* Pathfinding Watching the search

Escape after each time through search loop

Use quads to mark search Open list Closed list

Draw final path with line segments Waypoint to waypoint

Page 97: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

97

Tiny Pathfinding Demo

Page 98: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

98

Roy-Floyd-WarshallAll-Pairs Shortest Path Pre-compute ALL paths Just look up answer in a table!

1959 Bernard Roy 1962 Robert Floyd 1962 Stephen Warshall

Page 99: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

99

Roy-Floyd-Warshall All-Pairs Shortest Path Table

A

4

A B C D E

A

B

C

D

E

B

CD

E

2

10

3

45

Page 100: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

100

Roy-Floyd-Warshall All-Pairs Shortest Path O(n3)

int path[][]; //initialize to starting costs

void FloydWarshall() { for (k = 1 to n) { for each (i,j) in (1..n) { path[i][j] = min ( path[i][j], path[i][k] + path[k][j] ); } }}

Page 101: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

101

Roy-Floyd-Warshall All-Pairs Shortest Path Table

A

4

A B C D E

A 0

B 0

C 0

D 0

E 0

B

CD

E

2

10

3

45

Page 102: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

102

Roy-Floyd-Warshall All-Pairs Shortest Path Table

A

4

A B C D E

A 2 4

B 3

C 4 10

D 3 10 4

E 5

B

CD

E

2

10

3

45

Page 103: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

103

Roy-Floyd-Warshall All-Pairs Shortest Path Table

A

4

A B C D E

A 0 2 4

B 0 3

C 4 0 10

D 3 10 0 4

E 5 0

B

CD

E

2

10

3

45

Page 104: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

104

Roy-Floyd-Warshall All-Pairs Shortest Path Table

A

4

A B C D E

A 0 2 4 ∞ ∞

B ∞ 0 ∞ 3 ∞

C 4 ∞ 0 10 ∞

D ∞ 3 10 0 4

E ∞ ∞ 5 ∞ 0

B

CD

E

2

10

3

45

Page 105: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

105

Roy-Floyd-Warshall All-Pairs Shortest Path Table

A

4

A B C D E

A 0 2 4 ∞ ∞

B ∞ 0 ∞ 3 ∞

B

CD

E

2

10

3

45

for (k = 1 to n) { for each (i,j) in (1..n) { path[i][j] = min (path[i][j], path[i][k] + path[k][j]); }}

Page 106: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

106

Roy-Floyd-Warshall All-Pairs Shortest Path Table

A

4

A B C D E

A 0 2 4 ∞ ∞

B ∞ 0 ∞ 3 ∞

B

CD

E

2

10

3

45

for (k = 1 to n) { for each (i,j) in (1..n) { //example i=A, j=D, k=B path[i][j] = min (path[i][j], path[i][k] + path[k][j]); }}

Page 107: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

107

Roy-Floyd-Warshall All-Pairs Shortest Path Table

A

4

A B C D E

A 0 2 4 5 ∞

B ∞ 0 ∞ 3 ∞

B

CD

E

2

10

3

45

for (k = 1 to n) { for each (i,j) in (1..n) { //example i=A, j=D, k=B path[i][j] = min (path[i][j], path[i][k] + path[k][j]); }}

Page 108: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

108

Roy-Floyd-Warshall All-Pairs Shortest Path Table

A

4

A B C D E

A 0 2 4 5 9

B 16 0 12 3 7

C 4 6 0 9 13

D 13 3 9 0 4

E 9 11 5 14 0

B

CD

E

2

10

3

45

Page 109: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

109

Roy-Floyd-Warshall (Represents ideal heuristic)

A

4

A B C D E

A 0 2 4 5 9

B 16 0 12 3 7

C 4 6 0 9 13

D 13 3 9 0 4

E 9 11 5 14 0

B

CD

E

2

10

3

45

Page 110: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

110

Roy-Floyd-Warshall Inspired Next Node Look-up Table

A

4

A B C D E

A A B C B B

B D B D D D

C A A C A A

D E B E D E

E C C C C E

B

CD

E

2

10

3

45

Page 111: 1 Artificial Intelligence in Games Week 5 Steve Rabin steve.rabin@gmail.com  TA: Chi-Hao Kuo (chihao.kuo@digipen.edu) TA: Allan.

111

Roy-Floyd-Warshall Inspired Next Node Look-up Table Speed of search? Cost to compute? What's the downside during

runtime? Which search space

representations does it work on?


Recommended