Artificial Intelligence in Gaming

Ryan Donnelly Department of Computer Science University of Wisconsin Platteville donnelry@uwplatt.edu

Abstract
Artificial intelligence (AI) in gaming is getting more and more realistic as we head well into the twentieth century. But will we ever be at a state where games replicate humans perfectly on a consistent basis and learn their instincts? Games are getting more complicated. This is due to the use of more advanced algorithms that are being used as well as the new hardware that allows more computations. Games wouldn’t be where they are today if it wasn’t for artificial intelligence. I will be discussing the importance of artificial intelligence in games such as RTS-type games, First Person Shooter-type (FPS-type) and sports games. I will also discuss the most popular algorithms used today for artificial intelligence in games such as A* algorithm, finite state machines, and artificial neural networks.

Introduction
AI in gaming refers to methods used to produce intelligence of non-player characters or computer players. The methods are usually created from existing methods in AI. There may be other methods used but it is a vastly different approach to common AI. In first person shooter (FPS) games the computer is basically cheating due to the fact that it has to know where you are at all times to try to achieve the most intelligent non-player character. In a lot of cases, the AI of the non-player character has to be lowered or tweaked to give the human player a sign of fairness and a chance to win. Programmers will want to stay away from cheating as much as possible. In a way this makes the game have an unrealistic challenge because it is not using intelligence. Cheating also draws away focus from programmers to program more human-like bots. AI can also be thought as to simulate thinking, or as representing intelligent behavior in an algorithmic way [3]. When creating AI for games, one thing should always be in the programming team’s head, “what would a human player do?” The obvious goal is to make games to have a realistic challenge for the human-players. This makes sure that the game does not get too boring and shoved under the shelf in a week.

Extensive work and time put into this game to try to maximize the accuracy of the AI.Many techniques are used to achieve human like behavior for computer players. These games had no AI in them but used some discrete logic because they were based on a competition between two human players. a world champion chess player [1]. and Gotcha [1]. Without these techniques AI wouldn’t be where it is today not only in games but in all other software trying to replicate human intelligence. a chess playing computer developed by IBM. different personalities for the enemy were introduced as well as fighting games such as Karate Champ in 1984 [1]. A big accomplishment for AI occurred in 1983 when a human player went down in defeat to a computer player in chess. The most popular techniques are the A* algorithm. Most games now have a difficulty level as well which allows the user to pick a difficulty level which matches their experience with the game. The enemy moved by the use of stored patterns. Galaxian was released and the AI in this game stepped it up a notch from Space Invaders in that it allowed for more complex and varied enemy movements [1]. Stored patterns are paths that never change. Sports games advanced game AI in the early 1990s with the use of expert systems [1]. This opened up many eyes in the software industry. When microprocessors came into play. Pac-Man debuted in 1980 and was the first popular game character. Pac-Man sold all kinds of memorabilia. Each contributes to the AI in different ways. and the computer-players follow the same paths that are stored in the game. it brought to the table distinct moving patterns. The AI of this game tried to mock the coaching or managerial style of John Madden himself. An even bigger accomplishment for AI occurred in 1997 when Deep Blue. The following year. An expert system is a program that contains knowledge on a subject of one or more human experts. . which is different from stored patterns in that there are different paths for the computer-player [1]. In the newer Madden games one can change the variables of the opponent to play how the user wants them to play. defeated Kasparov. An example would be the popular Madden Football series. History Videogames first entered the world in the 1960s and into the early 1970s with the likes of Spacewar!. and artificial neural networks. Artificial Intelligence began to get implemented into games in the 1970s with a single player mode to play against the computer enemies [1]. This event gave confidence to every AI developer to believe that anything can be done or programmed to what they want it to be or do. Pong. This was the first victory recorded for AI against a human player at anything. When the game Space Invaders was released in 1978. As the years went on. finite machines. the building of the AI became more complex due to the speed and amount of computation that the microprocessors allowed.

After the tactic is picked. the lower-level module selects the best tactics for completing a task. As for an example. it would have only one event which would be “if enemy seen. For example. When using an event driven engine. the AI of the computer player determines the best approach for the situation. First person shooter-type games can be created using a layered artificial intelligence structure. if the tactic picked is to fight. some events with actions could be [3]: If enemy seen → Then attack with best weapon If wounded → Then run away or hide and find health If out of ammo → Then find ammo If you take a look at the first Doom game. Graphic cards also come out in the 90s and allow for more processor time to be spent on AI. in the game Dune II. When a behavior is decided.Finite state machines started to enter the gaming world in the 1990s as well as artificial neural networks. or run at the opponent and firing. AI in First Person Shooter (FPS-type) Games In first person shooter-type games the AI is in the opponents. The bottom layers take care of the trivial tasks such as determining the best path to the target. it is good idea to use leaking buckets. then attack. the approach could be to sneak up on the opponent. This allows for possibly a different action than a human player may expect. The first Real-Time Strategy games had notorious problems which included path finding problems. hide and wait for the opponent. and in the 1990s the first WarCraft game was the first game to ever implement path-finding algorithms at such a big scale for hundreds of units to engage in huge battles [2]. For instance. Battlecruiser 3000AD was the first game to use neural networks 1996 [2]. Hyper-threading processors came out in the early 2000s as well as just recently the core-duo processors which allow for even more of a complex AI engine to be built. An event driven engine can also be used where action is taken based on specific events that happen. teammates. For example. they attack in a bee line instead of attacking in random positions [1]. The RTS games did get better in the AI department and have gotten more popular. The leaking buckets theory is . and extra characters. What we are seeing now in the 21st century is that more games are successfully implementing artificial neural networks. one of the most popular games are the WarCraft series.” The same could probably be said for the new Doom games as well. That spawned the games Creatures and Black & White where computer-controlled characters’ learning was used for the first time. Real-time strategy and first-person shooter type games first entered the market in the 90s as well. and the top layers deal with reasoning and the behavior of the computer player [2]. real-time decisions and economic playing and many more. the enemy uses cheats and when the computer-players attack a human base.

Such games often use the inverted kinematics (IK) system. Most all first-person shooter games use some sort of path-finding system. The path finding is based on graphs describing the world where each vertex on the graph represents a location [2]. let’s say there exists the buckets flee. parameter calculations can be done for arm positioning animation so that the hand can grab an object off a shelf or the ground [2]. Basically it must be in sync with the AI system in the game. Different body parts should be able to play at different animation sequences such as for example a soldier running and aiming at the enemy then shooting and reloading while still running [2]. and restock. The script that gets ran is the script with the most filled bucket [3]. The A* algorithm is the most popular algorithm or technique used for path-finding. After an event occurs. remove 20% from flee and restock Lost 50% health in one hit → Add 50% to flee. It guarantees to find the shortest path between two points. In an IK animation system. When the computer player is ordered to get to a given point. which is the process of computing the pose of a human body from a set of constraints [4]. The location could be anything related to the game such as a room or a tower. add 20% to restock and remove 50% from fight. fight. the bucket with the most content in it gets ran. . The animation system or the computer player movement in first-person shooters has to play an appropriate sequence of animation at a chosen speed. So if the computerplayer sees an enemy and has 45% in its’ flee bucket and 30% in its’ fight bucket then the computer-player will flee instead of fight.where there are buckets that leak some of their contents over time. Events that occur fill the buckets to a different extent such as: Seen enemy → Add 5% to flee and 10% to fight Low ammo → Add 20% to restock Low health → Add 20% to flee and 10% to restock A lot of ammo and health → Add 50% to fight. For example. navigation is done by using the points that it should consecutively head towards to reach the specified location [2].

The units themselves are controlled by an event driven engine where action is taken based on events. Because there are numerous computer-controlled players on the map. this module must also handle collisions between the units so they don’t run into each other. A module is used to analyze the game map. The same module decides when cities should be built and how reinforcements should be placed. AI in Real Time Strategy (RTS-type) games Just like in first-person shooters. An example which shows the interaction between the event driven engine and the goal driven engine could be as follows: a building gets blown up by an air strike. It is also a good idea to use leaking buckets. This sparks the event based engine to give a new goal to the goal based engine to increase air defenses. . This module has to also analyze the terrain and a settlement can be built based on the evaluation of the terrain.Figure 1: Representation of the world in a FPS-type game with the red lines being a path. RTS-type games must implement a path-finding system. Path-finding is more important in RTS-type games in that some games require this module to have a solution for movement of hundreds of units on the map and it needs to be done in seconds. Smaller sub-goals are created as needed and are processed until the goal has been fulfilled [3]. The same rules apply here as they do in first-person shooters. Most maps are represented by a rectangular grid as shown in figure 2. This module uses a goal driven engine which works by taking the highest ranked goal and processing it.

These sectors are used to build a graph describing the track and to acquire characteristics of the track in the vehicle’s closest vicinity [2]. Figure 2: Representation of the world in a RTS-type game with the red lines being a path AI in Role Playing Games (RPG) Artificial intelligence in RPGs has historically been scarce. in racing games. These games can have some fighting as well but it is usually kept to a minimum. Scripted behavior has some minor AI involved and is common in games where the story line is more important [3]. Some games implement a combination of both scripted behavior and random encounters AI in Sports Games A lot of the AI in sports games has some sort of cheating. They have mostly been dependent on random encounters or scripted behavior. The track is also split into sectors and each sector length is calculated. For example. two paths are marked on the track: the first represents the optimal driving path. There must also be co-operation . The AI system in racing games must also analyze the terrain to detect objects in the road so the computer-driver can go around it or hit it if preferred. In effect. The random encounters are mostly seen in the games where there is a lot of fighting and where moving up in levels is more important [3].The goal based engine responds by moving units that are capable of air defense into position [3]. the second represents the path used when passing opponents. Basically it is the same as stored patterns. the computer-driver knows when to slow down if a curve is near because it knows what sectors are approaching.

. The physics module provides information such as when the car is skidding and the AI system needs to react immediately to get the vehicle under control. Cheating can be found in other sports games as well.between the AI system and the physics module [2]. one can design a simple AI system for simple FPS or RTS-type games. dashed pink represents passing path. Another algorithm is the finite state machine which prepares behavior scenarios for the computer players [2]. One becoming more popular due to better technology is artificial neural networks. The A* Algorithm A key problem in most games is finding a path from two points on a map. the A* algorithm has become a standard in games where path-finding is a huge part of the computer-player movement. A lot of times. Not only does the A* algorithm find a path between two points. but it finds the shortest path between two points. Figure 3: Segmentation and driving paths of the track. The computer game world has thoroughly evaluated the issue of path-finding and to this date. One of the algorithms is the A-Star (A*) algorithm which is used for finding optimal paths. This is not realistic AI and should be avoided. Popular AI Algorithms Used In Computer Games By having knowledge of a couple of algorithms. Blue represents optimal path. The computer-player should evaluate the human-player’s move before deciding a move of its own. the computer-player’s behavior or move is decided before the beginning of its turn.

The tracing out of the path is not completed ahead of time so you cannot really know this score. but it takes time and resources. a method is used to estimate this distance. If it is an overestimate it may run slightly faster and a path will still be found. angle of turns. The map can be divided into squares with each square containing a value. Each node in the open and closed lists has a G score. There must be a graph or a map of the game world. Algorithm The algorithm can be a bit confusing at first. we will also need a closed list. number of enemies in area. Optimal does not always mean the shortest. that is. The open list contains the nodes that need to be considered as possible starts for future growth of the path [5]. The H score is like the G score except it represents the distance from the current node to the endpoint [5]. and in today’s games. the heuristic is the estimated cost of getting to the destination or target. but it won’t necessarily be the shortest path. A* minimizes areas of the map to be examined by orienting the search towards the target and guaranteeing to find the shortest path. As discussed before. The start node is typically placed into this list at the beginning. One concept is an open list.Prerequisites Two prerequisites are needed for A* to work. and others depending on the game [2]. Once there is a basic understanding of a few concepts the algorithm uses. Now that we have an open list. The G score indicates the distance or weight of the path leading to the node from the start node [5]. it is not as trivial. It is faster and guarantees to find the shortest. Additional factors need to be taken account such as the terrain. Some games may have the algorithm avoid certain areas or situations occurring on the map. If it overestimates the distance it will slightly run faster and still find a path. This heuristic must underestimate the distance to ensure the algorithm will find the shortest path. This is the main advantage of A*. but it doesn’t guarantee that it will be the shortest or optimal path. The closed list contains the nodes that have had all of their neighbors added to the open list [5]. Typically. Method How about try all paths. For example if there is a battle or firing of a weapon you may want to keep distance from teammates or friendly units. A method also needs to be developed to estimate the distance between two points. the distance from the current point being examined to the target or destination. and then choose the shortest? This will work. There is also an H score which is the heuristic that is used. The algorithm uses some heuristic to help orient the search towards the target. we can’t go with out it. This is the heuristic of the algorithm. The heuristic must be an underestimate of the actual cost. most optimal path. Each square will have eight neighbors unless it is located on the edge of the map or near an obstacle. . This is where A* comes in to play.

The previous or parent node for the new nodes is T. If a node was already in the open list that is adjacent to T. the closed list is empty and the starting point is in the open list. patrolling. Entry action is an action that occurs when entering a state [6]. Input action is an action that occurs depending on input and present state [6]. If the new point is the target point. exit action. States store information about the past [6]. Each node holds its G score and the node that was used to get to the current node for backtracking [5]. check if the new G score is less than the current one and if it is. a soldier can be arming himself. Exit action is an action that occurs when exiting a state [6]. If the open list is empty. otherwise do nothing [5]. they are one of the least complicated. Each object in a game can have a number of states in its life. There are four types of actions: entry action. If it is in the open list already then don’t add it again. At the same time. . For instance. T is moved to the closed list and the process is started over [5]. Typically these nodes are referred to as parent and children nodes. update it as well as the previous pointer. then there is no path from the starting point to the end point. Typically a transition condition needs to be fulfilled to complete the transition [6]. and transition action. A simple diagram that illustrates this is shown below in figure 4. A finite state machine is a model composed of states. transitions. The G scores of the new nodes in the open list are the G score of T plus the distance between the new node and T [5]. Transitions indicate a state change. Transition action is an action that occurs when performing a transition [6]. Finite State Machines A finite state machine is one of the most effective and used methods of programming AI. then the optimal path is found.Starting out. and actions. The advantage of this method allows us to divide the implementation of each object’s behavior into smaller pieces. The path needs to be extended until the target destination is reached. Objects respond in different ways depending what state they are in. or attacking. Let’s call the point picked T. input action. This occurs by calculating the h score for all of the nodes in the open list and then picking the node in the open list with the lowest sum of the G and H scores [5]. which makes debugging and extension easier [2]. Every point that is adjacent to T and not in the closed list gets added to the open list [5].

processing the input. .Figure 4: Finite State Machine Artificial Neural Networks An artificial neural network is a software representation of the human brain. and communicating an output. that is. Successful artificial neural networks must be trainable. learn to solve problems from examples and use the “acquired knowledge” to solve unseen problems. The input is processed in hidden layers as seen in figure 5. It works by receiving input.

Several hundred samples for most games today is normal. This output is then passed to the physical layer module. Simultaneous testing should be occurring with the training process to ensure that the game doesn’t get too difficult or too easy and in need of further training [2]. The parameters need to be chosen in a way that will let the network learn to solve situations that have not appeared [2]. From receiving this input. Collin McRae Rally 2 was one of the first games to implement an artificial neural network successfully in 2001. A set of input data is needed for training the network. or the car’s properties [2]. The last step is to train the neural network. For example. This process usually requires a significant amount of effort and time from the developers. When the simultaneous use of fuzzy logic and neural networks is successful. distance from the corner. if road is dry then maintain normal speed or if road is wet then slow down. Fuzzy logic allows for more human like reasoning [2]. It is not possible . The input to the neural network could be the curvature of the road.Figure 5: Artificial neural network representation There was a debate of how to get artificial neural networks implemented into computer games. Conclusion Where would the game world be today if it weren’t for artificial intelligence? I can guarantee it wouldn’t be where it is today with out artificial intelligence. speed of car. The neural network’s application is limited in games due to a few problems such as [2]: • • • • Choosing appropriate input for neural networks Need for re-training the network when changes occur in the game Complicated theory and debugging Training the network takes time and is complicated Choosing the network’s input parameters can be a serious problem. Fuzzy logic is often used with neural networks. the results are incomparable with what can be achieved by using rules hard-coded into the code with traditional logic [2]. It is usually in the form: if variable is set then action. the neural network can generate an output which is optimal for the given conditions. A general rule of thumb is to have the input data represent as much information about the game world as possible. the type of road. It has been said that artificial neural networks have huge potential in computer games. The trained neural network in this game is responsible for keeping the computer player’s car on the track while trying to go around the track as fast as possible [2]. It has been a trendy topic as of late.

cs. September 7. A*.php/A_star [6] Finite State Machine. http://gpwiki.org/wiki/Game_artificial_intelligence [2] Grzyb.to create a game with out AI in today’s world. [3] Petersson. WorldForge Newsletter. Wikipedia Encyclopedia. and artificial neural networks provide games with the most human like computer player possible. References [1] Game Artificial Intelligence.org/project/newsletters/August2001/AI/#SECTION000200000000000000 00 [4] Popovic. 2006. Artificial Intelligence in Games.wikipedia.wikipedia. Keith. Tremendous accomplishments keep occurring such as neural networks just recently being implemented into a game for the first time. Martin. http://worldforge.pdf [5] A*. Hertzmann. November 1.org/index. Style-Based Inverse Kinematics. Aaron. http://en. Zoran. Anders. August 2001. Software Developer’s Journal. Janusz. Wikipedia Encyclopedia. We are slowly moving towards having artificial neural networks and fuzzy logic being a standard in games like the A* algorithm is now.washington. The Game Programming Wiki.edu/projects/styleik/styleik. June 2005. Grochow. http://en. With out AI in a game is like the Earth without the sun. 2004. finite state machines. AI in gaming has come a long way since the 1970s. Steven. Luckily for gamers. 2006.org/wiki/Finite_state_machine . September 15. 2006. Artificial Intelligence in Games. that day is soon here. http://grail.

Sign up to vote on this title
UsefulNot useful