Chapter 8: Artificial Intelligence - Adding the Competition


Up to this point, our game engine has concentrated on the visual aspects of playing a game. A game is more than just the images on the screen, though. In order for a game to be exciting and have any chance at being popular, there must be a challenge to playing it. Although some people may find it interesting (for a short period of time) to move a dune buggy around in a desert, this provides no real challenge to keep players coming back to the game. The challenge in most games comes in the form of competition. Although that competition could be against their own past performance (as in such games as Solitaire), it usually comes in the form of opponents. If the game supports networking, these could be other humans playing in a networked game. Not everyone is in a position to network with other people in order to play, however. Those without the network option need a computerized opponent to play against, and this is where artificial intelligence comes into play.

For many people, the term artificial intelligence conjures up images of lifelike robots and machines that think as well as humans. So far this is only found in science fiction . Universities that have computer science departments doing research in the subject have large complex programs that can learn and make some decisions based on data presented to them. While these programs can go a long way at mimicking what we consider intelligence, they are far too large and slow to be used in a game engine. Instead, game engines concentrate on providing as realistically as possible the illusion of intelligence by the computer opponents. This chapter presents a look at the different technologies typically used within a game engine as well as the approach chosen for our sample game engine.

Looking at Our AI Options

There are a number of approaches to game artificial intelligence (AI) that vary in both complexity and performance in terms of the level of intelligence provided. All of these systems have several features in common. The first and most common feature is the ability to cause an opponent to move. The intelligence behind the movement and the opponent s reactions to outside stimulation vary from approach to approach, as you will see later in this section. Second, the opponent must interact with the player and preferably other computercontrolled objects. The opponents are just window dressing in the scene if they do not react and interact with the player. Finally, we would like the opponents to learn or improve as we play. This way the game remains challenging even as players become more skilled in the game. However, not all game AI approaches support this particular ability. It is also a plus if the system can save this acquired knowledge for use the next time the game is started so that the opponents are not forced to relearn the game each time it is played .

Scripted Action

The opponents in early games did not have anything approaching artificial intelligence driving them. Instead, they relied on heavily scripted action with the possibility of a few hard-coded reactions built in. One example of this approach is the Pac-Man series of games. The path followed by each ghost is predetermined for each level of the game. Each ghost has some low-level, hardcoded approach/flee logic, but other than that there is no intelligence in the movement or reactions of the ghosts. Another even more drastic version of this approach was the original, two-dimensional version of the game Dragon s Lair. In this game, all action was prerendered with multiple paths through each scene based on player actions. In this case, the scripted action was entirely done through the prerendered scenes and path switching logic. This approach is rarely acceptable in today s games. Players are looking for opponents that do the unexpected.

Hard-Coded Rules

The next most powerful approach is hard-coded logic. Given enough If/Else statements, we can create a strong appearance of intelligence in our computercontrolled opponents. This approach is also quite straightforward to develop. Regardless of what we want the opponents to do, it is just a matter of coding the logic within the game. Although this approach is quite powerful and was used for many years , it does have several drawbacks. Making changes to the opponent s logic requires a code change and a recompile. This might not be too bad if you are a one-person game studio and are both the programmer and the game designer. In a larger shop where these functions are distributed among a number of people, this can become a major issue. Every time someone modifies a line of code, he or she risks introducing bugs into software that had been working. This also makes it difficult to change the logic from level to level in a game or for multiple games that share the same game engine. If we wish the logic to change from level to level, we must include all of this logic in the program and switch between the sections depending on the level. Not a very flexible system.

Neural Networks

One technology that has been evolving over the last few years is neural networks. Neural networks are strong in the learning ability side of artificial intelligence. In fact, this strength is also a major weakness when it comes to using neural networks in games. Neural networks are not programmed in the traditional sense. They are trained by providing each input as well as the desired output. A neural network adjusts itself until it automatically gives the correct output when it sees a particular input signal again. Although this system can learn and adjust itself to changing situations, it can be difficult to guarantee deterministic behavior. This system can also consume much of your CPU. The power of the neural network is a function of the size of the network. Unfortunately, the amount of processing required to run the network goes up as well with this system.

Inference Engines

The solution to these various shortcomings is a technique I refer to as an inference engine. This is a knowledge- and logic-based approach that provides all of the power of the hard-coded system without the logic being programmed as part of the game engine software. Instead, the logic is held in a file that is loaded and processed by the inference engine code within the game engine. A truly powerful inference engine would employ a common scripting language and an interpreter for that language. The Python language is a popular choice for this function in the gaming industry.

The logic or scripting portion of the inference engine is only part of the solution. The inference engine needs information to work with. We need an initial store of knowledge that defines the opponent s reactions as well as a means of adding knowledge of the environment. Sensor methods provide the environmental knowledge. The next piece of the puzzle is a set of action methods that can be triggered by the logic in order to carry out actions. The decisions made by the inference engine are useless unless they trigger an action or reaction to the current situation. A state system ties all of this together. A system of states and transitions between those states serves to put everything into a context. Figure 8 “1 shows an example of a state diagram. State diagrams are used to illustrate a set of states and the conditions required to transition between the states.

click to expand
Figure 8 “1: State diagram

A state diagram consists of circles that represent the states and directional lines that represent transitions from one state to another. Each of the lines is labeled with the logic that determines if that transition should be made. In this example, the software begins in the Idle state. When the game begins, a transition is made to the Drive Forward state. When the game is over, it transitions to the Brake state and back to Idle once stopped . Each state has a number of methods that are executed while that state is active. These actions, which can control speed (accelerating and braking) and steering (right or left) in this example, move the opponent and cause it to interact with the player and the environment.




Introduction to 3D Game Engine Design Using DirectX 9 and C#
Introduction to 3D Game Engine Design Using DirectX 9 and C#
ISBN: 1590590813
EAN: 2147483647
Year: 2005
Pages: 98

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net