Slide 1

Slide 1 text

Pathfinding Peril Chris Parsons

Slide 2

Slide 2 text

Huh? What is it all good for... Absolutely nothing?

Slide 3

Slide 3 text

Games

Slide 4

Slide 4 text

Workshop Plan Introduction Graph Theory Pathfinding Algorithms The Maze Contest

Slide 5

Slide 5 text

Graph Theory A B D C E F G

Slide 6

Slide 6 text

What is it all good for... Graphs can model internet networks, data organisation, computation flow, neural networks, the web, wikis, molecular structures, linguistics, social networks, biological habitats, transport networks, etc.

Slide 7

Slide 7 text

Shortest route from B to C A B D C E F G

Slide 8

Slide 8 text

“Brute force” A B D C E F G

Slide 9

Slide 9 text

“Brute force” A B D C E F G

Slide 10

Slide 10 text

“Brute force” A B D C E F G

Slide 11

Slide 11 text

Weighted graphs A B D E F G 3 3 17 2 2 3 22 1 C

Slide 12

Slide 12 text

B - E - C will cost 19 A B D E F G 3 3 17 2 2 3 22 1 C

Slide 13

Slide 13 text

...but B-A-G-D-C is only 9 A B D E F G 3 3 17 2 2 3 22 1 C

Slide 14

Slide 14 text

Dijkstra's Algorithm Published 1959 Uses an ordered set of open nodes, tracking minimum cost to each

Slide 15

Slide 15 text

Shortest route from B to C A B D E F G 3 3 17 2 2 3 22 1 C

Slide 16

Slide 16 text

Visit B Node Cost B 0 A (from B) 3 F (from B) 3 E (from B) 17 A B D E F G 3 3 17 2 2 3 22 1 C

Slide 17

Slide 17 text

Visit A Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 E (from B) 17 A B D E F G 3 3 17 2 2 3 22 1 C

Slide 18

Slide 18 text

Visit F Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 E (from B) 17 (25 is bigger) A B D E F G 3 3 17 2 2 3 22 1 C

Slide 19

Slide 19 text

Visit G Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 D (from G) 8 E (from B) 17 A B D E F G 3 3 17 2 2 3 22 1 C

Slide 20

Slide 20 text

Visit D Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 D (from G) 8 C (from D) 9 E (from B) 17 A B D E F G 3 3 17 2 2 3 22 1 C

Slide 21

Slide 21 text

Visit C - we’re done! Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 D (from G) 8 C (from D) 9 E (from B) 17 A B D E F G 3 3 17 2 2 3 22 1 C

Slide 22

Slide 22 text

Updated weights A B D E F G 3 3 17 2 2 3 3 1 C

Slide 23

Slide 23 text

Visit B Node Cost B 0 A (from B) 3 F (from B) 3 E (from B) 17 A B D E F G 3 3 17 2 2 3 3 1 C

Slide 24

Slide 24 text

Visit A Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 E (from B) 17 A B D E F G 3 3 17 2 2 3 3 1 C

Slide 25

Slide 25 text

Visit F Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 E (from F) 6 A B D E F G 3 3 17 2 2 3 3 1 C

Slide 26

Slide 26 text

Visit G Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 E (from F) 6 D (from G) 8 A B D E F G 3 3 17 2 2 3 3 1 C

Slide 27

Slide 27 text

Visit E Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 E (from F) 6 C (from E) 8 D (from G) 8 A B D E F G 3 3 17 2 2 3 3 1 C

Slide 28

Slide 28 text

Visit C - we’re done! Node Cost B 0 A (from B) 3 F (from B) 3 G (from A) 6 E (from F) 6 C (from E) 8 D (from G) 8 A B D E F G 3 3 17 2 2 3 3 1 C

Slide 29

Slide 29 text

A* algorithm Published 1968 Variation on Dijkstra, using a heuristic to cut down on nodes to visit

Slide 30

Slide 30 text

Distance Heuristic A 23 B 10 D 12 E 13 F 18 G 20 3 3 17 2 2 3 22 1 C 0

Slide 31

Slide 31 text

Visit B Node Cost Order B 0 10 (0+10) F 3 21 (3+18) A 3 26 (3+23) E 17 30 (17+13) A 23 B 10 D 12 E 13 F 18 G 20 3 3 17 2 2 3 22 1 C 0

Slide 32

Slide 32 text

Visit F Node Cost Order B 0 10 (0+10) F 3 21 (3+18) A 3 26 (3+23) E 17 30 (17+13) A 23 B 10 D 12 E 13 F 18 G 20 3 3 17 2 2 3 22 1 C 0

Slide 33

Slide 33 text

Visit A Node Cost Order B 0 10 (0+10) F 3 21 (3+18) A 3 26 (3+23) G 6 26 (6+20) E 17 30 (17+13) A 23 B 10 D 12 E 13 F 18 G 20 3 3 17 2 2 3 22 1 C 0

Slide 34

Slide 34 text

Visit G Node Cost Order B 0 10 (0+10) F 3 21 (3+18) A 3 26 (3+23) G 6 26 (6+20) D 8 20 (8+12) E 17 30 (17+13) A 23 B 10 D 12 E 13 F 18 G 20 3 3 17 2 2 3 22 1 C 0

Slide 35

Slide 35 text

Visit D Node Cost Order B 0 10 (0+10) F 3 21 (3+18) A 3 26 (3+23) G 6 26 (6+20) D 8 20 (8+12) C 9 9 (9 +0) E 17 30 (17+13) A 23 B 10 D 12 E 13 F 18 G 20 3 3 17 2 2 3 22 1 C 0

Slide 36

Slide 36 text

Visit C - we’re done! Node Cost Order B 0 10 (0+10) F 3 21 (3+18) A 3 26 (3+23) G 6 26 (6+20) D 8 20 (8+12) C 9 9 (9 +0) E 17 30 (17+13) A 23 B 10 D 12 E 13 F 18 G 20 3 3 17 2 2 3 22 1 C 0

Slide 37

Slide 37 text

Non-admissible Heuristic A 23 B 10 D 12 E 13 F 18 G 20 3 3 17 2 2 3 22 1 C 0

Slide 38

Slide 38 text

Different Heuristics Dijkstra no heuristic A* exact distance (admissible) http://en.wikipedia.org/wiki/A*_search_algorithm http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm A* over-egging distance (non-admissible)

Slide 39

Slide 39 text

Summary Brute force approach: O(n²) (ouch!) Dijkstra: guarantees best path but still can be slow A*: depending on Heuristic can trade speed for best path Admissible Heuristics (never overestimating cost) is the sweet spot for A*

Slide 40

Slide 40 text

Your turn Wifi: BCSGuest Password: xxxx Visit http://10.30.22.125:3000/rules

Slide 41

Slide 41 text

Slides + tournament online https://speakerdeck.com/chrismdp/pathfinding-peril- spa-2016 github.com/chrismdp/pathfinding-peril

Slide 42

Slide 42 text

Sol Trader I’m a web programmer moved back into Games http://soltrader.net

Slide 43

Slide 43 text

Thanks! Chris Parsons @chrismdp - http://pa.rsons.org Sol Trader @soltdr - http://soltrader.net