Tricks of the Windows Game Programming Gurus:Making Silicon Think with Artificial Intelligence

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

## CHAPTER 12
Making Silicon Think with Artificial Intelligence

> “I’m sorry, Dave. I’m afraid I can’t do that…”

> —HAL 9000, 2001: A Space Odyssey

This chapter is going to answer a lot of questions about the black art of artificial intelligence. In fact, depending on how you look at things, artificial intelligence is not artificial at all. It is an intelligence of sorts based on logic, mathematics, probability, and memory—and isn’t that all we are?

By the end of this chapter, you’ll be able to write code and algorithms to make game creatures perform in a reasonable manner and do almost anything that you want them to do. Here’s what’s covered:

  • Artificial intelligence primer
  • Simple deterministic algorithms
  • Patterns and scripts
  • Behavioral state systems
  • Memory and learning
  • Planning and decision trees
  • Pathfinding
  • Advanced scripting languages
  • Neural network basics
  • Genetic algorithms
  • Fuzzy logic

### Artificial Intelligence Primer

Artificial intelligence, in the most academic sense of the phrase, has come to mean a piece of hardware or software that enables a computer to “think” or process information in a fashion somewhat similar to our own.

Applications in AI just started to surface a few years ago, but today AI and other related fields, such as a-life (artificial life) and intelligent agents, are maturing at an exponential rate. In fact, that little MS-Word paper clip agent keeps annoying me as I write this sentence!

Today, systems exist that are “alive,” as far as anyone can define life. A number of companies have created artificial lifeforms within the virtual domain of the computer that live, die, explore, get sick, reproduce, evolve, get depressed, get hungry, and so on.

This kind of technology has been made possible with artificial neural networks, genetic algorithms, and fuzzy logic. Neural networks are crude approximations of a human brain, and genetic algorithms are a set of techniques and suppositions used for the evolution of software systems based on biological paradigms. Fuzzy logic is set theory based on non-crisp suppositions, like “It’s sort of hot out.”

Sound far out? It is. But it’s real, and it’s only going to get better. Remember, cloning used to be science fiction, but now it’s science fact.

Coming back down to Earth, you aren’t going to create anything as complex as state-of-the-art AI for your games. Instead, you’re going to look at the most simplistic and fundamental techniques that game programmers use to create intelligent creatures—or at least creatures that seem intelligent. In fact, many game programmers are still very behind on AI and haven’t begun to really embrace all that’s available in the field. I suspect that AI and related technologies are going to make the same kind of impact on the gaming world that the DOOM graphics technology made many years ago.

Truthfully, 3D graphics are starting to slow down. Things are looking pretty real these days, but they still act pretty dumb. The next killer game is going to look good, but more importantly, it’s going to be as cunning and devious as the best of us.

Finally, as you read the following pages and experiment with the accompanying programs, remember that all these techniques are just that—techniques. There isn’t a right way or a wrong way, just a way that works. If the computer-operated tank can kick your butt, that’s all you need. If it can’t, you need to do more.

Regardless of how primitive the underlying AI techniques are, the human players will always project personalities onto their virtual opponents. This is key—the player will believe that the objects in the game really are plotting, planning, and thinking, as long as they look like they are… Get it?

### Deterministic AI Algorithms

Deterministic algorithms are behaviors that are predetermined or preprogrammed. For example, if you take a look at the AI for the polygon Asteroids demo introduced in Chapter 8, “Vector Rasterization and 2D Transformations” (shown in Figure 12.1), it’s very simple.

Figure 12.1 The Asteroids AI.

The AI creates an asteroid and then sends it in a random direction with a random velocity. This is a type of intelligence as shown here:

    asteroid_x += asteroid_x_velocity;

    asteroid_y += asteroid_y_velocity;

The asteroids have one goal: to follow their course. That’s it. The AI is simple—the asteroids don’t process any outside input, make course changes, and so on. In a sense they’re intelligent, but their intelligence is rather deterministic and predictable. This is the first kind of AI I want to look at—the simple, predictable, programmable kind. In this class of AI, there are a number of techniques that were born in the Pong/Pac-Man era.

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.