1 / 62

AI in games

AI in games. Simple steering, Flocking Production rules FSMs, Probabilistic FSMs Path Planning, Search Unit Movement Formations. AI in video games. 5-10% of CPU for Realtime 25-50% of CPU for Turn-based Chase/Escape behaviors Group behaviors Finite State machines Adaptation/Learning.

mtyree
Download Presentation

AI in games

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AI in games Simple steering, Flocking Production rules FSMs, Probabilistic FSMs Path Planning, Search Unit Movement Formations IAT 410

  2. AI in video games • 5-10% of CPU for Realtime • 25-50% of CPU for Turn-based • Chase/Escape behaviors • Group behaviors • Finite State machines • Adaptation/Learning IAT 410

  3. Learning/Adaptation • Increment aggressiveness if player is doing well • The Computer-Based SATs do this! • Levels are a pre-programmed version of adaptation • Tuning • Stability • How might adaptation make play Better or Worse? IAT 410

  4. What is good AI? • Perceived by user as challenging • Cruel, but fair! • User is surprised by the game • but later understands why • Feeling that reality will provide answers • able to make progress solving problem • What games have used AI effectively? IAT 410

  5. Chase/Evade • Algorithm for the predator? IAT 410

  6. Enhancements to Chase • Speed Control • Velocity, Acceleration max/min • Limited turning Radius • Randomness • Moves • Patterns IAT 410

  7. Enhancements to Chase • Anticipation • Build a model of user behavior IAT 410

  8. Steering Behaviors • Pursue • Evade • Wander • Obstacle Avoidance • Wall/Path following • Queuing • Combine behaviors with weights • What could go wrong? IAT 410

  9. Group Behaviors • Lots of background characters to create a feeling of motion • Make area appear interesting, rich, populated IAT 410

  10. Flocking -- (HalfLife, Unreal) • What might go wrong? Simple version: Compute trajectory to head towards centroid IAT 410

  11. Group Behaviors Craig Reynolds SIGGRAPH 1987 • Reaction to neighbors -- Spring Forces IAT 410

  12. What could go wrong? • Repulsive springs around obstacles • Does not handle changes in strategy Forces balance out in dead end Exactly aligned IAT 410

  13. “Perceptual” Models IAT 410

  14. Production Rules If( enemy in sight ) fire If( big enemy in sight ) run away If( --- ) ---- • Selecting among multiple valid rules • Priority weighting for rules or sensor events • Random selection • No state (in pure form) IAT 410

  15. Finite State Machines • States: Action to take • Chase • Random Walk • Patrol • Eat • Transitions: • Time • Events • Completion of action At woods Chopping Enough wood Take Wood to closest depot At depot Drop wood: Go back to woods IAT 410

  16. State Machine Problems • Predictable • Sometimes a good thing • If not, use fuzzy or probabilistic state machines • Simplistic • Use hierarchies of FSM’s (HalfLife) IAT 410

  17. Probabilistic State Machines • Personalities • Change probability that character will perform a given action under certain conditions IAT 410

  18. Probabilistic Example Enemy Within Hand- to-Hand Range 50% Fire At Enemy Enemy Within Hand- to-Hand Range 50% Run Away Far Enough to Take Shot Run out of Range IAT 410

  19. Probabilistic State Machines • Other aspects: • Sight • Memory • Curiosity • Fear • Anger • Sadness • Sociability • Modify probabilities on the fly? IAT 410

  20. Planning • Part of intelligence is the ability to plan • Move to a goal • A Goal State • Represent the world as a set of States • Each configuration is a separate state • Change state by applying Operators • An Operator changes configuration from one state to another state IAT 410

  21. Path Planning • States: • Location of Agent/NPC in space • Discretized space • Tiles in a tile-based game • Floor locations in 3D • Voxels • Operator • Move from one discrete location to next IAT 410

  22. Path Planning Algorithms • Must Search the state space to move NPC to goal state • Computational Issues: • Completeness • Will it find an answer if one exists? • Time complexity • Space complexity • Optimality • Will it find the best solution IAT 410

  23. Search Strategies • Blind search • No domain knowledge. • Only goal state is known • Heuristic search • Domain knowledge represented by heuristic rules • Heuristics drive low-level decisions IAT 410

  24. Breadth-First Search • Expand Root node • Expand all Root node’s children • Expand all Root node’s grandchildren • Problem: Memory size Root Root Root Child2 Child1 Child2 Child1 GChild2 GChild1 GChild4 GChild3 IAT 410

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

  26. Depth First Search • Always expand the node that is deepest in the tree Root Root Child1 Child1 Root GChild2 GChild1 Child1 GChild1 IAT 410

  27. Depth First Variants • Depth first with cutoff C • Don’t expand a node if the path to root > C • Iterative Deepening • Start the cutoff C=1 • Increment the cutoff after completing all depth first probes for C IAT 410

  28. Iterative Deepening Root Root Child2 Child1 Child1 Root Root Root Child1 Child2 Child1 GChild1 GChild4 GChild3 GChild2 GChild1 IAT 410

  29. Bidirectional Search • Start 2 Trees • Start one at start point • Start one at goal point IAT 410

  30. Avoid Repeating States • Mark states you have seen before • In path planning: • Mark minimum distance to this node IAT 410

  31. Heuristic Search • Apply approximate knowledge • Distance measurements to goal • Cost estimates to goal • Use the estimate to steer exploration IAT 410

  32. 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 • Not Complete! • Local Minima IAT 410

  33. 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 IAT 410

  34. A* Search • Fails when there is no solution • Avoid searching the whole space • Do bi-directional search • Iterative Deepening IAT 410

  35. Coordinated Movement • Somewhat more difficult than moving just one NPC • Disappearing goal • New obstacles in path • Collisions with other NPCs • Groups of units • Units in formation IAT 410

  36. Coordinated Elements • Collision detection • Detection of immediate collisions • Near future • Perform the usual collision detection optimizations • Spatial hierarchies • Simplified tests • Unit approximations IAT 410

  37. Collision Detection • Levels of collision • Hard radius (small) • Must not have 2 units overlap hard radius • Soft radius (large) • Soft overlap not preferred, but acceptable IAT 410

  38. Collision Detection • With movement, need to avoid problems with bad temporal samples • Sample frequently • Detect collisions with extruded units • Use a movement line • Detect distance from Line segment IAT 410

  39. Unit Line • Unit line follows path • Can implement minimum turn radius • Gives mechanism for position prediction • Connected line segments • Time stamps per segment • Orientation per segment • Acceleration per segment IAT 410

  40. Prediction line • Given prediction, use next prediction as move • Prediction must have dealt with collisions already IAT 410

  41. Collision Avoidance Planning • Don’t search a new path at each collision • Adopt a Priority Structure • Higher priority items move • Lower priority items wait or get out of the way • Case-based reasoning to perform local path reordering • Pairwise comparison IAT 410

  42. Collision Resolution Summary • Favor: • High priority NPCs over Low Priority • Moving over non-moving • Lower Priority NPCs • Back out of the way • Stop to allow others to pass • General • Resolve all high-priority collisions first IAT 410

  43. Avoidance • Case 1: Both units standing • Lower priority unit does nothing itself • Higher unit • Finds which unit will move • Tells that unit to resolve hard collision by shortest move IAT 410

  44. Avoidance • Case 2: I’m not moving, other unit is moving • Non-moving unit stays immobile IAT 410

  45. Avoidance • Case 3: I’m moving, other is not: • If lower priority immobile unit can get out of the way: • Lower unit gets out of way • Higher unit moves past lower to get to collision free point • Else If we can avoid other unit • Avoid it! IAT 410

  46. Avoidance • Case 3: I’m moving, other is not: • Else: Can higher unit push lower along • Push! • Else: Recompute paths! IAT 410

  47. Avoidance • Case 4: Both units moving • Lower unit does nothing • If hard collision inevitable and we are high unit • Tell lower unit to pause • Else: If we are high unit • Slow lower unit down and compute collision-free path IAT 410

  48. Storage • Store predictions in a circular buffer • If necessary, interpolate between movement steps IAT 410

  49. Planning • Prediction implies • A plan for future moves • Once a collision has been resolved • Record the decision that was made • Base future movement plans on this Blocking unit Get-To Point Predicted Position IAT 410

  50. Units, Groups, Formations • Unit • An individual moving NPC • Group • A collection of units • Formation • A group with position assignments per group member IAT 410

More Related