ai and pathfinding
play

AI and Pathfinding CS 4730 Computer Game Design - PowerPoint PPT Presentation

AI and Pathfinding CS 4730 Computer Game Design Some slides courtesy Tiffany Barnes, NCSU CS 4730 AI Strategies ReacAon vs. DeliberaAon


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

  2. AI ¡Strategies ¡ • ReacAon ¡vs. ¡DeliberaAon ¡ • 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 ¡ – CivilizaAon ¡ – Halo ¡ CS ¡4730 ¡ 2

  3. AI ¡Strategies ¡ • ReacAon-­‑Based ¡ – Fast, ¡but ¡limited ¡capabiliAes ¡ • ImplementaAons ¡ – Finite-­‑State ¡Machines ¡ – Rule-­‑Based ¡Systems ¡ – Set ¡PaVern ¡ CS ¡4730 ¡ 3

  4. AI ¡Strategies ¡ • DeliberaAon-­‑Based ¡ – Much ¡slower, ¡but ¡more ¡adaptable ¡ • ImplementaAons ¡ – A* ¡/ ¡Dijkstra ¡ – Roadmaps ¡ – GeneAc ¡Algorithms ¡ CS ¡4730 ¡ 4

  5. DeliberaAon ¡ • Goal ¡is ¡to ¡emphasize ¡making ¡the ¡best ¡possible ¡ decision ¡by ¡searching ¡across ¡all ¡possibiliAes ¡ • Thus, ¡deliberaAon ¡tends ¡to ¡use ¡various ¡search ¡ algorithms ¡across ¡data ¡structures ¡that ¡contain ¡ the ¡opAon ¡space ¡ CS ¡4730 ¡ 5

  6. “Sense ¡– ¡Plan ¡– ¡Act” ¡ • Sense ¡(or ¡perceive) ¡a ¡sufficiently ¡complete ¡ model ¡of ¡the ¡world ¡ • Plan ¡by ¡searching ¡over ¡possible ¡future ¡ situaAons ¡that ¡would ¡result ¡from ¡taking ¡various ¡ acAons ¡ • Act ¡by ¡execuAng ¡the ¡best ¡course ¡of ¡acAon ¡ • Each ¡possible ¡outcome ¡is ¡effecAvely ¡scored ¡by ¡ a ¡“metric ¡of ¡success” ¡that ¡indicates ¡whether ¡ the ¡choice ¡should ¡be ¡taken ¡or ¡not ¡ CS ¡4730 ¡ 6

  7. DeliberaAve ¡vs. ¡ReacAve ¡ • These ¡are ¡NOT ¡mutually ¡exclusive! ¡ • You ¡can ¡have ¡reacAve ¡policies ¡for ¡immediate ¡ threats ¡ ¡ – Incoming ¡PC ¡fire ¡ – Environmental ¡destrucAon ¡ • And ¡you ¡can ¡have ¡deliberaAve ¡policies ¡for ¡long-­‑ term ¡planning ¡ – Build ¡orders ¡and ¡posiAoning ¡ CS ¡4730 ¡ 7

  8. Core ¡QuesAons ¡ • How ¡do ¡you ¡represent ¡knowledge ¡about ¡the ¡ current ¡task, ¡environment, ¡PC, ¡etc? ¡ • How ¡do ¡you ¡find ¡acAons ¡that ¡allow ¡the ¡goal ¡to ¡ be ¡met? ¡ CS ¡4730 ¡ 8

  9. Knowledge ¡RepresentaAon ¡ • 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, ¡deliberaAve ¡AI ¡techniques ¡are ¡effecAvely ¡ versions ¡of ¡search ¡and ¡shortest-­‑path ¡ algorithms! ¡ CS ¡4730 ¡ 9

  10. Tic-­‑Tac-­‑Toe ¡ • What ¡is ¡the ¡decision ¡tree ¡for ¡Tic-­‑Tac-­‑Toe? ¡ CS ¡4730 ¡ 10

  11. The ¡Goal ¡State ¡ • The ¡objecAve ¡of ¡the ¡decision ¡tree ¡model ¡is ¡to ¡ move ¡from ¡the ¡iniAal ¡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? ¡ CS ¡4730 ¡ 11

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

  13. 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 ¡ CS ¡4730 ¡ 13

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

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

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

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

  18. Adding ¡a ¡HeurisAc ¡ • Simple ¡definiAon: ¡a ¡heurisAc ¡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 ¡potenAal ¡opAon? ¡ • What ¡metrics ¡might ¡we ¡use ¡to ¡determine ¡“the ¡ cost” ¡of ¡a ¡potenAal ¡opAon? ¡ CS ¡4730 ¡ 18

  19. Adding ¡a ¡HeurisAc ¡ • CreaAng ¡an ¡AI ¡heurisAc ¡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? ¡ CS ¡4730 ¡ 19

  20. Cheaper ¡Distance ¡First! ¡ CS ¡4730 ¡ 20

  21. Greedy ¡Search ¡ • Expand ¡the ¡node ¡that ¡yields ¡the ¡minimum ¡cost ¡ ¡ – Expand ¡the ¡node ¡that ¡is ¡closest ¡to ¡target ¡ – Depth ¡first ¡ – Minimize ¡the ¡funcAon ¡ h(n) ¡the ¡heurisAc ¡cost ¡ funcAon ¡ CS ¡4730 ¡

  22. Greedy ¡Search ¡ CS ¡4730 ¡ 22

  23. Greedy ¡Search ¡ CS ¡4730 ¡ 23

  24. Greedy ¡Search ¡ • Greedy ¡gives ¡us ¡(ojen) ¡a ¡sub-­‑opAmal ¡path, ¡but ¡ it’s ¡really ¡cheap ¡to ¡calculate! ¡ • How ¡can ¡we ¡improve ¡on ¡this? ¡ • Add ¡another ¡aspect ¡to ¡the ¡funcAon ¡– ¡the ¡cost ¡ of ¡the ¡node ¡+ ¡the ¡heurisAc ¡distance ¡ CS ¡4730 ¡ 24

  25. A* ¡ • A ¡best-­‑first ¡search ¡(using ¡heurisAcs) ¡to ¡find ¡the ¡ least-­‑cost ¡path ¡from ¡the ¡iniAal ¡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 ¡ CS ¡4730 ¡ 25

  26. A* ¡Search ¡ • Minimize ¡sum ¡of ¡costs ¡ • g(n) ¡+ ¡h(n) ¡ – Cost ¡so ¡far ¡ + ¡heurisAc ¡to ¡goal ¡ • Guaranteed ¡to ¡work ¡ – If ¡ h(n) ¡does ¡ not ¡overesBmate ¡cost ¡ • Examples ¡ – Euclidean ¡distance ¡ CS ¡4730 ¡

  27. A* ¡ CS ¡4730 ¡ 27

  28. A* ¡ CS ¡4730 ¡ 28

  29. A* ¡ CS ¡4730 ¡ 29

  30. NavigaAon ¡Grid ¡ CS ¡4730 ¡ 30

  31. 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 ¡ – NavigaAon ¡mesh ¡layers ¡are ¡added ¡over ¡the ¡terrain ¡ – Ojen ¡done ¡automaAcally ¡in ¡advanced ¡engines ¡ CS ¡4730 ¡ 31

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend