Monday, August 23, 2010

Artificial Intelligence Usage in Video Games

Probably the thing I dislike most about some games is how the computer cheats.
I’m playing my strategy game and I have to spend 10 minutes finding their units

while they automatically know where mine are, which type they are, their

energies, and so on. It’s not the fact that they cheat to make the game harder, it’s

the fact that they cheat because the artificial intelligence is very weak. The

computer adversary should know just about the same information as the player.

If you look at a unit, you don’t see their health, their weapons, and their bullets.

You just see a unit and, depending on your units, you respond to it. That’s what

the computer should do; that’s what artificial intelligence is all about.

In this chapter I will first give you a quick overview of several types of artificial

intelligence, and then you will see how you can apply one or two to games. In this

chapter, I’m going to go against the norm for this book and explain the concepts

with little snippets of code instead of complete programs. The reason I’m doing

this is because the implementation of each field of artificial intelligence is very

specific, and where is the fun in watching a graph give you the percentage of the

decisions if you can’t actually see the bad guy hiding and cornering you?

Complete examples would basically require a complete game! For this reason, I

will go over several concrete artificial intelligence examples, giving only the

theory and some basic code for the implementation, and it will be up to you to

choose the best implementation for what you want to do.
 
Here is a breakdown of the major topics in this chapter: 
Understanding the various fields of artificial intelligence


Using deterministic algorithms

Recognizing finite state machines

Identifying fuzzy logic

Understanding a simple method for memory

Using artificial intelligence in games

The Fields of Artificial Intelligence

There are many fields of artificial intelligence; some are more game-oriented and

others are more academic. Although it is possible to use almost any of them in

games, there are a few that stand out, and they will be introduced and explained

in this section.

Expert Systems

Expert systems solve problems that are usually solved by specialized humans. For

example, if you go to a doctor, he will analyze you (either by asking you a set of

questions or doing some analysis himself), and according to his knowledge, he

will give you a diagnosis.


An expert system could be the doctor if it had a broad enough knowledge base. It

would ask you a set of questions, and depending on your answers, it would

consult its knowledge base and give you a diagnosis. The system checks each of

your answers with the possible answers in its knowledge base, and depending on

your answer, it asks you other questions until it can easily give you a diagnosis.

For a sample knowledge tree, take a look at Figure 20.1. As you can see, a few

questions would be asked, and according to the answers, the system would follow

the appropriate tree branch until it reached a leaf.
 
Genetic Algorithms

Using genetic algorithms is a method of computing solutions that relies on the
concepts of real genetic concepts (such as evolution and hereditary logic). You

might have had a biology class in high school that explained heredity, but in case

you didn’t, the field of biology studies the evolution of subjects when they

reproduce. (Okay, maybe there is a little more to it than that, but we are only

interested in this much.)

As you know, everyone has a blood type, with the possible types being A, B, AB,

and O, and each of these types can be either positive or negative. When two

people have a child, their types of blood will influence the type of blood the child

has. All that you are is written in your DNA. Although the DNA is nothing more

than a collection of bridges between four elements, it holds all the information

about you, such as blood type, eye color, skin type, and so on. The little ‘‘creatures’’

that hold this information are called genes.

What you might not know is that although you have only one type of blood, you

have two genes specifying which blood type you have. How can that be? If you

have two genes describing two types of blood, how can you have only one type of

blood?


Neural Networks


Neural networks attempt to solve problems by imitating the workings of a

brain. Researchers started trying to mimic animal learning by using a collection

of idealized neurons and applying stimuli to them to change their behavior.

Neural networks have evolved much in the past few years, mostly due to the

discovery of various new learning algorithms, which made it possible to

implement the idea of neural networks with success. Unfortunately, there still

aren’t major discoveries in this field that make it possible to simulate the human


brain efficiently.

The human brain is made of around 50 billion neurons (give or take a few

billion). Each neuron can compute or process information and send this

information to other neurons. Trying to simulate 50 billion neurons in a computer

would be disastrous. Each neuron takes various calculations to be simulated,

which would lead to around 200 billion calculations. You can forget about

modeling the brain fully, but you can use a limited set of neurons (the human

brain only uses around 10 percent of its capacity for conscious thought) to mimic

basic actions of humans.

In 1962, Rosenblatt created something called a perceptron, one of the earliest

neural network models. A perceptron is an attempt to simulate a neuron by using

a series of inputs, weighted by some factor, which will output a value of 1 if

the sum of all the weighted inputs is greater than a threshold, or 0 if it isn’t.

Figure 20.6 shows the idea of a perceptron and its resemblance to a neuron.

While a perceptron is just a simple way to model a neuron, many other ideas

evolved from this, such as using the same values for various inputs, adding a bias

or memory term, and mixing various perceptrons using the output of one as

input for others. All of this together formed the current neural networks used in

research today.

There are several ways to apply neural networks to games, but probably the most

predominant is by using neural networks to simulate memory and learning. This

field of artificial intelligence is probably one of its most interesting parts, but

unfortunately, the topic is too vast to give a proper explanation of it here.

Fortunately, neural networks are becoming more and more popular these days,

and numerous publications are available about the subject.

No comments:

Post a Comment