Sunday, August 7, 2011

Learning AI for Games

Understanding Artificial Intelligence

To understand AI for games you want to have a basic understanding of general AI. This will make it easier to understand and expand on later. Lets dive right into some basic AI!

Introduction to AI

AI, short for Artificial Intelligence is replicating the human thought process with computers. AI alone is a broad topic but luckily we are only focusing on game AI. Now to give a basic example of a simple thought process that's purely logical.

*Sorry for the small text in the diagram

This example is very simple and straight forward. Notice how it doesn't really act like a human necessarily would. It doesn't have any human emotion or feelings.

Lets aim at a more realistic approach instead. I show a more detailed human-realistic diagram below.

*Sorry for the small text in the diagram

With this little add-on we get a bit more complex as you or I would think. This extra decision gives it a better human thought. Now if you wanted to go more in depth you could add feelings. For example if you felt sick you wouldn't eat or if you were tired you would eat to gain energy. 

Now we will move onto AI in games and the types.

AI in Games

There are three general AI types in games. They each are for certain tasks such as following the player. The following three are game AI types.

  • Roaming AI
  • Behavioral AI
  • Strategic AI
Roaming AI

Roaming AI is basically AI that move certain ways. It makes decisions based on whats around it. Types of roaming AI are chasing, evading, and patterned roaming. Each have their own specialties.

Chasing

Chasing is a type of Roaming AI which chases another object. AN example of this is shown.

The square is coded to chase the circle where ever it goes. The circle is going in a circle making it harder for the square to get it. Now how this would work is the square would check the circles position and decide the quickest way to get the circle. In other words the square would check the circles x and y coordinates.  

Evading

Evading is much like chasing but opposite. An object avoids another object and attempts to get away. A quick example is as shown.

The square attempts to get away from the circle. What the square does is looks at the circles position and goes away from it.

Patterned Roaming

Patterned roaming is basically a set pattern of which an object follows. An example would look something like this.

The square is set to go in a figure eight while the circle goes in a circle. This is all that those shapes are coded to do.

That covers all roaming AI, next I will move onto behavioral AI.

Behavioral AI

Behavioral AI is basically roaming AI that`s much more complex. Instead of an object always following the same instructions it has multiple decisions. Here`s a basic example. 

The square has a 50% chance of chasing the circle, 10% to run away, and 40% to move around randomly. This gives a more complex approach offering decisions instead of one rule.

Aggressive and Passive Example

To give a better example I will show two different types of shapes. One being passive and one being aggressive.

The square is the aggressive shape and the circle is passive. Since the square is aggressive it is 50% likely to chase the circle. It still has 45% to wander and 5% to evade. While the circle is 50% to evade from the square and 40% chance of wandering. It also has a 10% chance of staying still. Each of these shapes are very different because one is aggressive and one is passive.

Next I will be moving onto strategic AI which is much more complex.

Strategic AI

Strategic AI is an interesting type of AI. This AI basically must follow rules of a game. This is the AI you would play against in a chess game. A good example is a game called Age of Empires 3. You could play against the AI but they had to play with the same rules you had so the game was fair. A really fun thing I used to do was open up the editor and watch two AI players vs each other. It was very interesting to see how the two AI interacted. Anyway back onto topic, strategic AI is much more complex because it has to play the game at the same level as thew gamer.

Deciding the Right AI

Now since you have an understanding of the types of game AI you may be looking to pick one for your game. Lets break down the types to make it easier to see.

Roaming - objects interacting with other objects by moving

Behavioral - objects with multiple decisions 

Strategic - follows same rules as player

Now it will be a bit easier to figure out which one you need. If none of the types I have talked about look to be what you want, search around the web.

Phew this has been a lot of typing. Hope you enjoyed it.


No comments:

Post a Comment