/
Artificial Intelligence Introduction to Artificial Intelligence (AI) Artificial Intelligence Introduction to Artificial Intelligence (AI)

Artificial Intelligence Introduction to Artificial Intelligence (AI) - PowerPoint Presentation

williams
williams . @williams
Follow
72 views
Uploaded On 2023-10-28

Artificial Intelligence Introduction to Artificial Intelligence (AI) - PPT Presentation

Many applications for AI Computer vision natural language processing speech recognition search But games are some of the more interesting apps Games need opponents that are challenging or allies that are helpful ID: 1026302

techniques state common game state techniques game common finite cost player breadth open node promising heuristic search list machines

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Artificial Intelligence Introduction to ..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1. Artificial Intelligence

2. Introduction to Artificial Intelligence (AI)Many applications for AIComputer vision, natural language processing, speech recognition, search …But games are some of the more interesting appsGames need opponents that are challenging, or allies that are helpfulIn general, any unit that is credited with acting on ownBut human-level intelligence still too hardBut under narrow circumstances can do pretty well (ex: chess and Deep Blue)Fortunately, for many games, circumstances often constrained (by game rules) Artificial Intelligence (around in CS for some time)

3. AI for CS different than AI for GamesMust be smart, but purposely flawedLoose in fun, challenging wayNo unintended weaknessesNo “golden path”, readily exploitable weakness to defeatMust not look “dumb”Must perform in real timeEven turn-based games have humans waitingOften, configurable by designersNot hard coded by programmer“Amount” and type of AI for game can varyRTS needs global strategy, FPS needs modeling of individual units at “footstep” levelRTS most demanding: 3 full-time AI programmersPuzzle, street fighting: 1 part-time AI programmer

4. Where to Learn AI at WPI?IMGD 3000Introduction to idea“Whirlwind” view of techniquesBasic pathfinding (A*)Finite State MachinesIMGD 4000Details on basic game AI commonly used in many gamesDecision treesHierarchical state machinesAdvanced game AI used in more sophisticated gamesAdvanced pathfindingBehavior treesIMGD 4100 (in 2014) “AI for Interactive Media and Games”Fuzzy logicGoal-driven agent behaviorCS 4341 “Artificial Intelligence”Machine learningPlanningNatural language understanding

5. OutlineIntroduction (done)Common AI Techniques (next)Promising AI TechniquesPathfinding (A*)Finite State Machines Summary

6. Common Game AI Techniques (1 of 4)Whirlwind tour of common techniquesFor each, provide idea and example (where appropriate)MovementFlockingMove groups of creatures in natural mannerEach creature follows three simple rulesSeparation – steer to avoid crowding flock matesAlignment – steer to average flock headingCohesion – steer to average positionExample – use for background creatures such as birds or fish. Modification can use for swarming enemyFormationsLike flocking, but units keep position relative to othersExample – military formation (archers in the back)http://processing.org/learning/topics/flocking.html

7. Common Game AI Techniques (2 of 4)Movement (continued)A* pathfindingCheapest path through environmentDirected search exploit knowledge about destination to intelligently guide searchFastest, widely usedCan provide information (i.e. virtual breadcrumbs) so can follow without recomputeDetails later!Obstacle avoidanceA* good for static terrain, but dynamic such as other players, choke points, etc., cause problemsExample – same path for 4 units, so get “clogged” in narrow opening. Instead, predict collisions so furthest back slow down, avoid narrow bridge, etc.

8. Common Game AI Techniques (3 of 4)Behavior organizationEmergent behaviorCreate simple rules result in complex interactionsExample: game of life, flockingCommand hierarchyDeal with AI decisions at different levelsModeled after military hierarchy (i.e. General does strategy, Foot Soldier does fighting/tactics)Example: Real-time or turn based strategy games - overall strategy, squad tactics, individual fightersManager task assignmentWhen individual units act individually, can perform poorlyInstead, have manager make tasks, prioritize, assign to unitsExample: baseball – 1st priority to field ball, 2nd cover first base, 3rd to backup fielder, 4th cover second base. All players try to get ball, then disaster! Manager determines best person for each. If hit towards 1st and 2nd, first baseman fields ball, pitcher covers first base, second basemen covers firsthttp://www.youtube.com/watch?v=XcuBvj0pw-E

9. Common Game AI Techniques (4 of 4)Influence map2d representation of “power” in gameBreak into cells, where units in each cell are summed upUnits have influence on neighbor cells (typically, decrease with range)Insight into location and influence of forcesExample – can be used to plan attacks to see where enemy is weak or to fortify defenses. SimCity used to show pollution coverage, etc.Level of Detail AIIn graphics, polygonal detail less if object far awaySame idea in AI – computation less if won’t be seenExample – vary update frequency of NPC based on position from player

10. OutlineIntroduction (done)Common AI Techniques (done)Promising AI Techniques (next)Pathfinding (A*)Finite State Machines Summary

11. Promising AI Techniques (1 of 3)Bayesian networkA probabilistic graphical model with variables and probable influencesExample - calculate probability of patient having specific disease given symptomsExample – AI can infer if player has warplanes, etc. based on what it sees in production so farCan be good to give “human-like” intelligence without cheating or being too dumbDecision tree learningSeries of inputs (usually game state) mapped to output (usually thing want to predict)Example – health and ammo  predict bot survivalModify probabilities based on past behaviorExample – Black and White could stroke (reward) or slap (punish) creature. Creature learned what was good and bad.

12. Promising AI Techniques (2 of 3)Filtered randomnessWant randomness to provide unpredictability to AIBut even random can look odd sometimes (e.g. if 4 heads in a row, player will think something wrong. And, if flip coin 100 times, there likely will be streak of 8) E.g. spawn at same point 5 times in a row, then badCompare random result to past history and avoidFuzzy logicTraditional set, object belongs or notIn fuzzy, can have relative membership (e.g. hungry, not hungry. Or “in-kitchen” or “in-hall” but what if on edge?)Cannot be resolved by coin-flipCan be used in games – e.g. assess relative threat

13. Promising AI Techniques (3 of 3)Genetic algorithmsSearch and optimize based on evolutionary principlesGood when “right” answer not well-understoode.g. may not know best combination of AI settings. Use genetic algorithsm to try outOften expensive, so do offlineN-Gram statistical predictionPredict next value in sequence (e.g.- 1818180181 … next will probably be 8)Search backward n values (usually only 2 or 3)ExampleStreet fighting (punch, kick, low punch…)Player does low kick and then low punch. What is next?Uppercut 10 times (50%), low punch (7 times, 35%), sideswipe (3 times, 15%)Can predict uppercut or, proportionally pick next (e.g. roll dice)

14. OutlineIntroduction (done)Common AI Techniques (done)Promising AI Techniques (done)Pathfinding (A*) (next)Finite State Machines Summary

15. PathfindingOften seems obvious and natural in real lifeE.g. Get from point A to B  go around lakeFor computer controlled player, may be difficultE.g. Going from A to B goes through enemy base!Want to pick “best” pathNeed to do it in real-timeQ: why can’t just figure it out ahead of time (i.e. before game starts)?

16. Representing the SpaceSystem needs to understand the levelBut not full information, only relevant information (e.g. is it passable, not water vs. lava vs. tar…)Common representations2d GridEach cell passable or impassibleNeighbors automatic via indices (e.g. 8 neighbors)Waypoint graphConnect passable pointsNeighbors flexible (but needs to be stored)Good for arbitrary terrain (e.g. 3d)

17. Finding a PathPath – a list of cells, points or nodes that agent must traverse to get to from start to goalSome paths are better than others measure of qualityAlgorithms that guarantee path called completeSome algorithms guarantee optimal path (best quality)Others find no path (under some situations)

18. Consider Simple - Random TraceAgent moves towards goalIf goal reached, then doneIf obstacleTrace around obstacle clockwise or counterclockwise (pick randomly) until free path towards goalRepeat procedure until goal reached(Humans often do this in mazes)

19. Random Trace (continued)How will Random Trace do on following maps?Not a complete algorithmFound paths are unlikely to be optimalConsumes very little memory

20. Understanding A*Combines breadth-first, best-first, and Dijkstra(More on these next)These algorithms use nodes to represent candidate pathsm_pParent used to chain nodes sequentially together to represent pathList of absolute coordinates, instead of relative directionsclass PlannerNode {public:PlannerNode *m_pParent;int m_cellX, m_cellY;...};

21. Breadth-First (1 of 2)OverviewUse two lists: open and closedOpen list keeps track of promising nodesClosed list keeps nodes that are visited, but don’t correspond to goalWhen node examined from open listTake offCheck to see if reached goalIf not reach goalCreate additional nodesPlace on closed listOverall StructureCreate start point node – push onto open listWhile open list is not emptyA. Take node from open list (call it currentNode)B. If currentNode corresponds to goal  doneC. Create new nodes (successors nodes) for cells around currentNode and add them to open listD. Put currentNode onto closed list

22. Breadth-First (2 of 2)Search from centerGoal was ‘X’Open list  light greyHave not been processedClosed list  dark greyNot goal and have been processedArrows represent parent pointersPath appears in bold

23. Breadth-First in Actionhttp://www.youtube.com/watch?v=LKfql0uT2lY

24. Breadth-First CharacteristicsExhaustive searchSystematic, but not cleverConsumes substantial amount of CPU and memoryGuarantees to find paths that have fewest number of nodes in themComplete algorithmBut not necessarily shortest distance!

25. Best-First (1 of 2)Uses problem specific knowledge to speed up search processNot an exhaustive search, but a heuristic searchHead straight for goalComputes distance of every node to goalAlgorithm same as breadth firstBut use distance as priority valuePick node with shortest distance as node to visit

26. Best-First in ActionLooks pretty good! But perfect?http://www.youtube.com/watch?v=SyWFezdOImI

27. Best-First (2 of 2)(Sub-optimal paths)

28. Best-First CharacteristicsHeuristic searchUses fewer resources than breadth-firstOn average, much faster than breadth-first searchTends to find good pathsNo guarantee to find most optimal pathComplete algorithm

29. Dijkstra’s AlgorithmDisregards distance to goalKeeps track of cost of every pathUnlike best-first, no heuristic guessingComputes accumulated cost paid to reach a node from startUses cost (called “given cost”) as priority value to determine next node in open listUse of cost allows it to handle other terrainE.g. mud that “slows” or “downhill”

30. Dijkstra CharacteristicsExhaustive searchAt least as resource intensive as Breadth-FirstAlways finds the optimal pathNo algorithm can do betterComplete algorithm

31. A*Use best of Djikstra and Best-FirstBoth heuristic cost (estimate) and given cost (actual) to pick next node from open listFinal Cost = Given Cost + (Heuristic Cost * Heuristic Weight)(Avoids Best-First trap!)

32. A* Internals (1 of 3)Green: startRed: goalBlue: barrierG: 10 for ver/horiz, 14 for diagH: “manhattan distance” to dest * 10F: Estimated “cost” (G+H)

33. A* Internals (2 of 3)Now check for the lowest F value in OPENIn this case NE, SE both 54, so randomly choose SEGoing directly to SE is cheaper than E->SELeave start as the parent of SE, and iterate

34. A* Internals (3 of 3)Keep iterating until reach goal and OPEN is emptyFollow parent links to get short path

35. A* Demohttp://www.antimodal.com/astar/

36. A* CharacteristicsOn average, uses fewer resources than Dijkstra and Breadth-FirstHeuristic search“Weight” can control how much to value heuristic (H)If 0 then like DijkstraIf large then like Best-First“Good” heuristic guarantees it will find optimal path“Good” as long as doesn’t overestimate actual costFor maps, good is “as a bird flies” distance (best-case)Complete algorithm

37. OutlineIntroduction (done)Common AI Techniques (done)Promising AI Techniques (done)Pathfinding (A*) (done)Finite State Machines (next)Summary

38. Finite State MachinesOften AI as agents: sense, think, then actBut many different rules for agentsEx: sensing, thinking and acting when fighting, running, exploring…Can be difficult to keep rules consistent!Try Finite State MachineProbably most common game AI software patternNatural correspondence between states and behaviorsEasy: to diagram, program, debugGeneral to any problemSee AI Depot - FSM For each situation, choose appropriate stateNumber of rules for each state is small

39. Finite State MachinesAbstract model of computationFormally:Set of statesA starting stateAn input vocabularyA transition function that maps inputs and current state to next state(Detailedexample nextslide)

40. Finite State Machines – Example (1 of 2)Game where raid Egyptian TombMummies! BehaviorSpend all of eternity wandering in tombWhen player is close, search When see player, chaseMake separate statesDefine behavior in each stateWander – move slowly, randomlySearch – move faster, in linesChasing – direct to playerDefine transitionsClose is 100 meters (smell/sense)Visible is line of sightWanderingSearchingChasingClose byVisibleFar awayHidden

41. Finite State Machines – Example (2 of 2)Can be extended easilyEx: Add magical scarab (amulet)When player gets scarab, Mummy is afraid. Runs.BehaviorMove away from player fastTransitionWhen player gets scarabWhen timer expiresCan have sub-statesSame transitions, but different actionsie- range attack versus melee attackWanderingSearchingChasingClose byVisibleFar awayHiddenAfraidScarabScarabScarabTimerExpires

42. Finite State Machines SummaryProsSimplicity  low entry levelPredictability  allows for easy testingSimplicity  quick to design, implement and executeWell-proven technique with lots of examplesFlexible  many ways to implementEasy to transfer from abstract representation to coded implementationLow processor overhead  only the code for the current state needs to run, well suited to gamesEasy to tell reachability of stateConsPredictability  can make for easy-to-exploit opponentLarge FSMs difficult to manage and maintain ("spaghettifactor“)All states, transitions and conditions need to be known up front and be well definedInflexible  conditions for transitions are ridged

43. SummaryAI for games different than other fieldsIntelligent opponents, allies and neutral’s but fun (lose in challenging way)Still, can draw upon broader AI techniquesFinite State Machines flexible, popularBut don’t scale to complicated AIDozens of techniques to choose from, with promising techniques on the horizonAI is the next great “frontier” in gamesTwo key aspects of pathfinding:Representing the search spaceSearching for a pathA* combines actual cost with estimated heuristic in searching