Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 Introduction to Game AI April 11, 2013 1.

Similar presentations


Presentation on theme: "Chapter 1 Introduction to Game AI April 11, 2013 1."— Presentation transcript:

1 Chapter 1 Introduction to Game AI April 11, 2013 1

2 Defining AI “The ability of a computer or other machine to perform those activities that are normally thought to require intelligence”. Game AI techniques : deterministic and nondeterministic –Deterministic behavior or performance is specified and predictable –Nondeterministic behavior is the opposite of deterministic behavior. Behavior has a degree of uncertainty and is somewhat unpredictable 2

3 Established Game AI Cheating Finite state machines Fuzzy logic Effective and efficient pathfinding Scripting, rules-based system 3

4 The future The game should evolve, learn, and adapt the more it's played Decision trees, neural networks, genetic algorithms, and probabilistic methods 4

5 Chapter 2 Chasing and Evading 5

6 Application A spaceship shooter, a strategy simulation, or a role-playing game, video. Make your game's non-player characters (NPC) either chase down or run from your player character 6

7 Outline Basic Chasing and Evading Line-of-Sight Chasing Line-of-Sight Chasing in Tiled Environments Line-of-Sight Chasing in Continuous Environments Intercepting 7

8 Basic Chasing if (predatorX > preyX) predatorX--; else if (predatorX < preyX) predatorX++; if (predatorY > preyY) predatorY--; else if (predatorY < preyY) predatorY++; 8

9 Basic Evading if (predatorX > preyX) predatorX++; else if (predatorX < preyX) predatorX--; if (predatorY > preyY) predatorY++; else if (predatorY < preyY) predatorY--; 9

10 Basic tile-based chase example if (predatorCol > preyCol) predatorCol--; else if (predatorCol < preyCol) predatorCol++; if (predatorRow> preyRow) predatorRow--; else if (predatorRow<preyRow) predatorRow++; 10

11 Basic tile-based chase 11

12 Line-of-Sight Chasing 12

13 Bresenham's algorithm One of the more efficient methods for drawing a line in a pixel-based environment 13

14 14

15 Line-of-Sight Chasing in Continuous Environments game entities—airplanes, spaceships, hovercraft, etc.—are driven by applied forces and torques. Physics for Game Developers (O'Reilly). The player controls his vehicle by applying thrust for forward motion and steering forces for turning. 15

16 u = VRotate2D(-Predator.fOrientation, (Prey.vPosition - Predator.vPosition)); u.Normalize(); if (u.x < -_TOL) left = true; else if (u.x > _TOL) right = true; Predator.SetThrusters(left, right); 16

17 Global & Local Coordinate Systems 17

18 Steering force test 18

19 Intercepting 19

20 DoIntercept Vr = Prey.vVelocity - Predator.vVelocity; Sr = Prey.vPosition - Predator.vPosition; tc = Sr.Magnitude() / Vr.Magnitude(); St = Prey.vPosition + (Prey.vVelocity * tc); 20

21 21

22 22

23 General Considerations This function should be called every time through the game loop or physics engine loop so that the predator constantly updates the predicted interception point and its own trajectory 23

24 General Considerations Sometimes interceptions are not possible For example, if the predator is slower than the prey and if the predator somehow ends up behind the prey 24

25 3. Pattern Movement 25

26 Pattern Movement The NPCs move according to some predefined pattern that makes it appear as though they are performing complex Takes the desired pattern and encodes the control data into an array or set of arrays 26

27 Control instructions ControlData { double turnRight; double turnLeft; double stepForward; double stepBackward; }; 27

28 Pattern initialization Pattern[0].turnRight = 0; Pattern[0].turnLeft = 0; Pattern[0].stepForward = 2; Pattern[0].stepBackward = 0; Pattern[1].turnRight = 0; Pattern[1].turnLeft = 0; Pattern[1].stepForward = 2; Pattern[1].stepBackward = 0; Pattern[2].turnRight = 10; Pattern[2].turnLeft = 0; Pattern[2].stepForward = 0; Pattern[2].stepBackward = 0; Pattern[3].turnRight = 10; Pattern[3].turnLeft = 0; Pattern[3].stepForward = 0; Pattern[3].stepBackward = 0; Pattern[4].turnRight = 0; Pattern[4].turnLeft = 0; Pattern[4].stepForward = 2; Pattern[4].stepBackward = 0; Pattern[5].turnRight = 0; Pattern[5].turnLeft = 0; Pattern[5].stepForward = 2; Pattern[5].stepBackward = 0; Pattern[6].turnRight = 0; Pattern[6].turnLeft = 10; Pattern[6].stepForward = 0; Pattern[6].stepBackward = 0; … 28

29 Pattern Movement in Tiled Environments Paths will be made up of line segments. Each new segment will begin where the previous one ended. 29

30 Rectangular pattern movement 30

31 entityList[1].InitializePathArrays(); entityList[1].BuildPathSegment(10, 3, 18, 3); entityList[1].BuildPathSegment(18, 3, 18, 12); entityList[1].BuildPathSegment(18, 12, 10, 12); entityList[1].BuildPathSegment(10, 12, 10, 3); entityList[1].NormalizePattern(); entityList[1].patternRowOffset = 5; entityList[1].patternColOffset = 2; 31

32 Complex tile pattern movement 32

33 Track pattern movement (add random factor) 33

34 Pattern Movement in Physically Simulated Environments Isn't conducive to forcing a physically simulated object to follow a specific pattern of movement Apply appropriate control forces to the object to coax it Your input in the form of steering forces and thrust modulation, for example, is processed by the physics engine 34

35 Control Structures struct ControlData { bool PThrusterActive; bool SThrusterActive; double dHeadingLimit; double dPositionLimit; bool LimitHeadingChange; bool LimitPositionChange; }; 35

36 Square path 36

37 Zigzag path 37

38 4. Flocking 38

39 Flocking Often in video games, NPC must move in cohesive groups rather than independently. Craig Reynolds,1987, "Flocks, Herds, and Schools: A Distributed Behavioral Model." Collective Intelligence 39

40 Classic Flocking Cohesion –Have each unit steer toward the average position of its neighbors. Alignment –Have each unit steer so as to align itself to the average heading of its neighbors. Separation –Have each unit steer to avoid hitting its neighbors. 40

41 Aware of neighbors Each unit is aware of its local surroundings It knows the average location, heading, and separation between it and the other units in the group in its immediate vicinity. 41

42 Neighbors 42

43 Wide versus narrow field-of-view flock formations 43

44 Flocking Example we're going to treat each unit as a rigid body and apply a net steering force at the front end of the unit. This net steering force will point in either the starboard or port direction relative to the unit Will be the accumulation of steering forces determined by application of each flocking rule 44

45 Cohesion 45

46 Alignment each unit should steer so as to try to assume a heading equal to the average heading of its neighbors 46

47 Separation 47

48 Obstacle Avoidance The units to see ahead of them and then apply appropriate steering forces to avoid obstacles in their paths 48

49 Follow the Leader Follow-the-leader rule Let some simple rules sort out who should be or could be a leader Not leaving the flock leaderless in the event the leader gets destroyed or somehow separated from his flock Add other AI to the leaders to make their leading even more intelligent 49

50 5. Potential Function-Based Movement 50

51 How Can You Use Potential Functions for Game AI? Calculate the force between the two units—the computer-controlled unit and the player in this case Then apply that force to the front end of the computer-controlled unit, where it essentially acts as a steering force 51

52 Lenard-Jones Potential Function 52

53 Chasing/Evading Use the potential function to calculate the force of attraction (or repulsion) between the two units, applying the result as a steering force to the computer-controlled unit 53

54 Potential chase and evade (A) (B) A  (C) A  (D) B  54

55 Obstacle Avoidance we set the A parameter, the attraction strength, to 0 to leave only the repulsion component. We then can play with the B parameter to adjust the strength of the repulsive force and the m exponent to adjust the attenuation 55

56 Obstacle Avoidance 56

57 Swarming calculate the Lenard-Jones force between each unit in the swarm 57

58 Optimization Suggestions Complexity: N 2 not perform the force calculation for objects that are too far away from the unit to have any influence on it divide your game domain into a grid containing cells of some prescribed size. –perform calculations only between the unit and those obstacles contained within that cell and the immediately adjacent cells 58

59 6. Basic Pathfinding and Waypoints 59

60 Basic Pathfinding Chapter 2 60

61 Obstacle Avoidance Random Movement Obstacle Avoidance –works particularly well in an environment with relatively few obstacles 61

62 6.2.2 Tracing Around Obstacles 62

63 63

64 6.2 Breadcrumb Pathfinding 64

65 65

66 66

67 6.3 Path Following 67

68 68

69 69

70 6.4 Wall Tracing 70

71 71

72 6.5 Waypoint Navigation 72

73 73

74 74

75 75


Download ppt "Chapter 1 Introduction to Game AI April 11, 2013 1."

Similar presentations


Ads by Google