Chapter 8. Artificial Intelligence

This chapter will cover the following recipes:

  • A simple pathfinding algorithm for a maze
  • Pathfinding for tile-based environments with obstacles
  • Using a fuzzy logic for decision making

Introduction

This chapter will show you how to add a bit of intelligence into your game. However, this does not mean that your game characters will be able to behave like real-life people. Instead, they will be able to handle specific situations with a predefined set of rules. This adds a realistic-looking behavior to the game characters.

The earlier games used a simple mechanism with static environment and static movement paths. Nonplayer characters or NPCs could move only along certain paths and couldn't handle changes in the game environment. You could see this in the Super Mario Bros series.

The next step in artificial intelligence was introduced in 3D action games such as Doom. NPCs always try to approach the player character after they've been alarmed about the player's presence. But still, they can't handle the simplest obstacles. A certain level of intelligence is emulated with special skills to make the games more challenging.

Modern games use a static or dynamic set of paths to move from one point to another. The advantage of static paths is that these are usually well designed within certain game environments and allow NPCs to move to other locations even if there are obstacles. The downside of this approach is that this set of paths must be prepared by game developers and it usually can't be changed during gameplay. What's more, it can't respond to dynamic changes in the environment.

Dynamic paths are used in some games today to incorporate intelligent movement in changing game environments. This consists of graph-like structures, where significant locations are marked as graph nodes and paths between these nodes can contain a set of instructions to successfully move between these two locations. However, this approach is the hardest to implement and it's more computationally intensive as well.

Artificial intelligence in games is used not only for pathfinding, but also for NPC behavior. This kind of AI can be divided into two categories: static and dynamic. Most games use static behavioral AI with a set of rules that define NPC actions on certain inputs. The downside of static AI is that it can't learn new things. Dynamic behavioral AI usually uses neural network expert systems with a feedback loop (observation) to generate a set of rules on top of predefined static rules. A typical example of such a system is the H.A.L. 9000 computer in A Space Odyssey or a robot in the Terminator movie series.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.124.21