Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Artificial Intelligence in Games Ryan Donnelly

Similar presentations


Presentation on theme: "1 Artificial Intelligence in Games Ryan Donnelly"— Presentation transcript:

1 1 Artificial Intelligence in Games Ryan Donnelly

2 2 What is AI in Games? Techniques used in computer and video games to produce the illusion of intelligence in the behavior of non-player characters Techniques used in computer and video games to produce the illusion of intelligence in the behavior of non-player characters A game must ‘feel’ natural A game must ‘feel’ natural –Obey laws of the game –Characters aware of the environment –Path finding (A*) –Decision making –Planning Game ‘bookkeeping’, scoring Game ‘bookkeeping’, scoring ~50% of project ~50% of project time building AI

3 3 Computer Game Types Strategy games Strategy games – Real Time Strategy (RTS) – Helicopter view Role Playing Games (RPG) Role Playing Games (RPG) Action games Action games – First person shooter (FPS) – Sports games

4 4 Goals of Game AI Be ‘fun’ Be ‘fun’ –Reasonable challenge with natural behavior No Cheating! No Cheating! –AI has bonuses over human players such as: Giving more damage Giving more damage Having more health Having more health Driving faster Driving faster Etc. Etc. –Used to increase difficulty –Draws away focus to program more human-like bots. Run fast Run fast Use minimal memory Use minimal memory

5 5 Game AI History ’s 1960’s –First computer games (SpaceWar) –Board games against the computer (Chess) 1970’s 1970’s –Atari (1972) Nolan Bushnell Nolan Bushnell Pong Pong –First AI implemented into games Stored patterns Stored patterns Space Invaders (1978) Space Invaders (1978) –Distinct moving patterns Galaxian (1979) Galaxian (1979) –More complex and varied enemy movements –1-2% of CPU time spent on AI

6 6 Game AI History ’s 1980’s –Fighting games Karate Champ (1984) Karate Champ (1984) –AI defeated a human player in chess for the first time (1983) –Pac-Man (1980)

7 7 Game AI History ’s 1990’s –Sports games Madden Football Madden Football –FPS and RTS games RTS games had problems RTS games had problems –Path finding –Decisions –Many more –Dune II: Enemy attacked in a bee line and used cheats RTS games did get better RTS games did get better –WarCraft First game to implement First game to implement path-finding at such a large scale

8 8 Game AI History ’s (cont.) 1990’s (cont.) –Finite state machines –Neural networks Battlecruiser 3000AD (1996) Battlecruiser 3000AD (1996) –Deep Blue defeats chess champ Gary Kasparov (1997) Chess playing computer developed by IBM Chess playing computer developed by IBM Inspires AI developers Inspires AI developers ml ml ml ml –Graphic cards allowing for more CPU time –10-35% of CPU time spent on AI

9 9 Game AI History ’s 2000’s –More games using neural networks Black & White (2001) Black & White (2001) Collin McRae Rally 2 (2001) Collin McRae Rally 2 (2001) –Hyperthreading More sophisticated AI engines while simultaneously creating a more realistic 3D environment More sophisticated AI engines while simultaneously creating a more realistic 3D environment –Core Duo Even more complex AI engines Even more complex AI engines

10 10 AI in Different Game Types FPS & RPG FPS & RPG –AI is in opponents, teammates, and extra characters RTS RTS –AI on all sides Sports Games Sports Games –AI is in opponents and teammates

11 11 AI in FPS-type Games Layered AI Structure Layered AI Structure –Bottom layers = trivial Determine paths Determine paths –Top layers = non-trivial Reasoning and behavior Reasoning and behavior Event Driven Engine Event Driven Engine –Action based on events –Good Idea to use leaking buckets to make more flexible Leaking Buckets Leaking Buckets –Buckets leak contents over time –Script with the most filled bucket gets executed

12 12 AI in FPS-type Games Cont. Path-Finding Path-Finding –Based on graphs describing the world A(*) A(*) –Most commonly used –Guaranteed to find shortest path Animation System Animation System –Play appropriate sequence of animation at the chosen speed –Play different animation sequences for different body parts (i.e. run and aim, and shoot and reload weapon while still running) –Inverted kinematics Process of computing the pose of a human body from a set of constraints Process of computing the pose of a human body from a set of constraints –i.e. An IK animation system can appropriately calculate the parameters of arm positioning animation so that the hand can grab an object located on a table or shelf

13 13 Representation of the World in an FPS-type Game

14 14 AI in RTS-type Games Path-Finding Path-Finding –Handle collisions –A(*) Event Driven Engine Event Driven Engine Maps Represented by a Rectangular Grid Maps Represented by a Rectangular Grid –Module that analyzes the game map uses a goal driven engine Take highest rank goal and process it. Take highest rank goal and process it. Smaller sub-goals are created as needed and are processed until the goal has been fulfilled. Smaller sub-goals are created as needed and are processed until the goal has been fulfilled. Analyzes terrain and a settlement is built based on evaluation of the terrain Analyzes terrain and a settlement is built based on evaluation of the terrain Decides when cities should be built and how reinforcements should be placed Decides when cities should be built and how reinforcements should be placed

15 15 AI in RTS-type Games Cont. Interaction between event driven and goal driven engine example: Interaction between event driven and goal driven engine example: –A building gets blown up by an air strike –This sparks the event based engine to give a new goal to the goal based engine to increase air defenses –The goal based engine responds by moving units that are capable of air defense into position.

16 16 Representation of the World in an RTS-type Game

17 17 AI in RPG-type Games Little AI Little AI –Random encounters More common in games where fighting and gaining levels is more important More common in games where fighting and gaining levels is more important –Scripted behavior Often coupled with some minor AI Often coupled with some minor AI Common in games depending more on their story line than other things Common in games depending more on their story line than other things –Often a combination of both

18 18 AI in Sports Games Cheating Cheating Racing games Racing games –Segmentation Track gets split into small sectors. Track gets split into small sectors. Each element gets its length calculated Each element gets its length calculated Fragments used to obtain characteristics of the road in the vehicle’s closest vicinity Fragments used to obtain characteristics of the road in the vehicle’s closest vicinity In effect, the computer knows it should slow down because it’s approaching a curve or an intersection In effect, the computer knows it should slow down because it’s approaching a curve or an intersection –Optimization Two curves are marked on the track Two curves are marked on the track First represents the optimal driving track First represents the optimal driving track Second represents the track used when overtaking opponents Second represents the track used when overtaking opponents –AI system must analyze terrain Detect obstacles lying on the road Detect obstacles lying on the road

19 19 AI in Sports Games Cont. Racing games (cont.) Racing games (cont.) –Strict co-operation with physics module Physics module provides information such as when the car is skidding Physics module provides information such as when the car is skidding The AI system, having received the information that the car is skidding, should react appropriately and try to get the vehicle’s traction back under control The AI system, having received the information that the car is skidding, should react appropriately and try to get the vehicle’s traction back under control

20 20 Popular AI Algorithms Used In Computer Games A(*) A(*) Finite State Machines Finite State Machines Artificial Neural Networks Artificial Neural Networks

21 21 A(*) Algorithm Goal: Find shortest path Goal: Find shortest path Prerequisites Prerequisites –Graph –Method to estimate distance between points (heuristic) Basic Method Basic Method –Try all paths? Takes time Takes time –Orient search towards target Minimizes areas of the map to be examined Minimizes areas of the map to be examined Uses heuristics that indicate the estimated cost of getting to the destination Uses heuristics that indicate the estimated cost of getting to the destination Main advantage Main advantage

22 22 A(*) Algorithm Algorithm Algorithm –Open list Nodes that need to be considered as possible starts for further extensions of the path Nodes that need to be considered as possible starts for further extensions of the path –Closed list Nodes that have had all their neighbors added to the open list Nodes that have had all their neighbors added to the open list –G score Contains the length or weight of the path from the current node to the start node Contains the length or weight of the path from the current node to the start node Low lengths are better Low lengths are better Every node has a G score Every node has a G score –H score Heuristic Heuristic Resembles G score except it represents an estimate of the distance from the current node to the endpoint Resembles G score except it represents an estimate of the distance from the current node to the endpoint To find shortest path, this score must underestimate the distance To find shortest path, this score must underestimate the distance

23 23 A(*) Algorithm Algorithm (cont.) Algorithm (cont.) –Start with an empty closed list and just the starting point in the open list –Every node has a G score and the node that was used to arrive at this node (Parent node)

24 24 A(*) Algorithm Algorithm (cont.) Algorithm (cont.) –Extend the path Calculate the H scores of the nodes in the open list using a heuristic method. Calculate the H scores of the nodes in the open list using a heuristic method. Pick the node (P) in the open list for which the sum of the G and H scores is the lowest. Note: If the open list is empty then no path Pick the node (P) in the open list for which the sum of the G and H scores is the lowest. Note: If the open list is empty then no path For every point adjacent to P not in the closed or open list, add it to the open list. The previous nodes for these new nodes is P, and their G score is the G score of P plus the distance between the new node and P. If it was already in the open list, check it’s current G score, and if the new G score would be less than the current one update the G score and previous node, otherwise leave it alone. For every point adjacent to P not in the closed or open list, add it to the open list. The previous nodes for these new nodes is P, and their G score is the G score of P plus the distance between the new node and P. If it was already in the open list, check it’s current G score, and if the new G score would be less than the current one update the G score and previous node, otherwise leave it alone. If the new point is the destination point, you have found your path. If the new point is the destination point, you have found your path. Move P to the closed list and start over Move P to the closed list and start over

25 25 A(*) Algorithm Example: Example: –Manhattan method Calculate total # of squares moved horizontally and vertically to reach target, ignoring diagonal movement and obstacles. Calculate total # of squares moved horizontally and vertically to reach target, ignoring diagonal movement and obstacles.

26 26 A(*) Algorithm Example (cont.): Example (cont.):

27 27 A(*) Algorithm Example (cont.): Notice: 2 squares = 54 Example (cont.): Notice: 2 squares = 54 –Can be faster to choose last one added to the open list This biases the search in favor of squares that get found later on in the search, when you have gotten closer to the target This biases the search in favor of squares that get found later on in the search, when you have gotten closer to the target

28 28 A(*) Algorithm Example (cont.): Example (cont.):

29 29 A(*) Algorithm Example (cont.): Example (cont.):

30 30 A(*) Algorithm Example (cont.): Example (cont.):

31 31 Finite State Machines Each object in a game can have a number of states during its life. Each object in a game can have a number of states during its life. –i.e. patrolling, attacking, resting, etc. Model of behavior composed of: Model of behavior composed of: –States Stores information about the past, i.e. it reflects the input changes from the system start to the present moment Stores information about the past, i.e. it reflects the input changes from the system start to the present moment –Transitions Indicates a state change and is described by a condition that would need to be fulfilled to enable the transition Indicates a state change and is described by a condition that would need to be fulfilled to enable the transition –Actions Entry action Entry action –executed when entering the state Exit action Exit action –executed when exiting the state Input action Input action –executed depending on present state and input conditions Transition action Transition action –executed when performing a certain transition

32 32 Finite State Machines Cont. Advantage: Can divide implementation of each games object’s behavior into smaller fragments Advantage: Can divide implementation of each games object’s behavior into smaller fragments –Easier to debug and extend

33 33 Finite State Machines State Diagram State Diagram

34 34 Finite State Machines Example: Pacman Ghost

35 35 Artificial Neural Networks Brain Brain –Receives input –Processes input –Communicates the output Relies on the cooperation of the individual neurons within the network to operate Relies on the cooperation of the individual neurons within the network to operate –If some neurons are not functioning, the network can still perform its overall function Trainable Trainable –Learn to solve complex problems from a set of examples –Generalizes the “acquired knowledge” to solve unforseen problems

36 36 Artificial Neural Networks

37 37 Artificial Neural Networks Neural Networks in Games? Neural Networks in Games? –Trendy topic in the late 90’s into 00’s Huge potential in computer games Huge potential in computer games –Collin McRae Rally 2 (2001) Total success Total success The trained artificial neural network is responsible for keeping the computer player’s car on the track while letting it negotiate the track as quickly as possible The trained artificial neural network is responsible for keeping the computer player’s car on the track while letting it negotiate the track as quickly as possible Input parameters: curvature of the road’s bend, distance from the bend, type of surface, speed, or the vehicles properties Input parameters: curvature of the road’s bend, distance from the bend, type of surface, speed, or the vehicles properties Output: selected in a way so that the car travels and negotiates obstacles or curves at a speed optimal for the given conditions. Output: selected in a way so that the car travels and negotiates obstacles or curves at a speed optimal for the given conditions.

38 38 Artificial Neural Networks Obstacles Limiting Neural Networks’ Application in Games Obstacles Limiting Neural Networks’ Application in Games –Problems choosing appropriate input –Neural network’s sensitivity to changes in a game’s action logic, and the need for re-training the network whenever such a situation occurs –Rather complicated theory, and difficulties with debugging in case of problems –Time-consuming and complicated process of training the network

39 39 Artificial Neural Networks How to take advantage of an artificial neural network in a simple game? How to take advantage of an artificial neural network in a simple game? –Need to know what kinds of information the neural network should provide to help solve the problem –Choose input parameters Choose in a way that its different combinations will let the neural network learn to solve problems which haven’t appeared in the example set of signals Choose in a way that its different combinations will let the neural network learn to solve problems which haven’t appeared in the example set of signals Should represent as much information about the game world as possible Should represent as much information about the game world as possible –i.e. vectors of relative positions of the nearest obstacle or opponent, the enemies strength, etc. –Acquire set of input data for training Significant effort Significant effort –Train the neural network Mixed with simultaneous testing to make sure the game is not too difficult, or if too easy and in need of further training Mixed with simultaneous testing to make sure the game is not too difficult, or if too easy and in need of further training

40 40 Artificial Neural Networks Fuzzy logic Fuzzy logic –Often used with neural networks –Conversion from computer’s reasoning into something more strongly resembling the way a human thinks –Usually in the form: IF variable IS set THEN action IF variable IS set THEN action –i.e. IF road IS dry THEN maintain normal speed IF road IS dry THEN maintain normal speed IF road IS wet THEN slow down IF road IS wet THEN slow down

41 41 Conclusion Games With No AI? Games With No AI? –Not possible! –Every game with computer controlled characters/opponents uses some sore of AI Game AI has come a long way since the 1970s Game AI has come a long way since the 1970s Future looks bright Future looks bright –Neural networks are the future of computer games and a future that is not that distant anymore

42 42 References 1) Grzyb, Janusz. Artificial Intelligence in Games. Software Developer’s Journal. June ) Game Artificial Intelligence. Wikipedia Ecyclopedia. September 7, ) Petersson, Anders. Artificial Intelligence in Games. WorldForge Newsletter. August SECTION SECTION SECTION ) Popovic, Zoran; Martin, Steven; Hertzmann, Aaron; Grochow, Keith. Style-Based Inverse Kinematics ) A*. The Game Programming Wiki. September 15,


Download ppt "1 Artificial Intelligence in Games Ryan Donnelly"

Similar presentations


Ads by Google