Developing By Me

Project Development and Design

AI Basics

Artificial Intelligence [AI] is a fundamental requirement of any game development. There are several aspects that must be in place before the developer can produce the AI. The developer first must have a working environment that could be a 2D slide scroller or a complex 3D Online Game. The actual game style has little control on what an AI can or could do. This is because the AI is independent from the visual effects that the player will see. Before the developers can create the AI for the computer controlled or Non-Player Characters [NPCs], so they must think through what the NPC will need to do and what it should do.

Since the developer has an NPC that needs to respond it is important to know more about what an NPC is. The NPC is any object within the game that is not directly controlled by the player. In order for the NPC to be interactive it must have some programming logic allowing it to react to external stimulus. That means that when the player performs the action of talking, attacking, or other action the NPC must have a corresponding action or actions. The simple way to perform the task is to create an association list between the action performed and the action taken [Table1].

Player Action NPC Response
Talk Dialog Conversation
Attacks NPC Fights Back
Attacks NPC Home Fights Player to Defend Home

As the table displays there is only one action the NPC can take that is a reaction to the player. This form of AI is the simplest form because the AI does not have to think since there is only one option. Because of the design this is as basic of an AI that can be created. However, what if the developer wanted to make it more complex creating a scenario that could change from fight to fight. To do this there would be more the one response based on the players action [Table2]

Player Action NPC Response
Talk Dialog Conversation
Attacks NPC Fights Back
Attacks NPC Home Fights Player to Defend Home
Talk Attacks Player
Attacks NPC Runs Away
Attacks NPC Home Ignores Player

As the table displays there is more the one action the NPC could take per action the player performs. How will the NPC react? That is the logic code. To do this the developer creates a MOB or a Mobile Object that can be anything within the game environment. The first MOB will be normally something the player will interact with such as a Monster. The monster AI will use the above table depending on the logic created. In order for the monster to choose the correct action it needs some rules [Table3].

Rule Action
Attacked with Health >= 50% Attacks Player
Attacked with Health < 50% Runs Away
Home Attacked but Health > 50% Ignores Player
Home Attacked and Health <= 50% Attacks Player

The first two Rules are strait forward the monster will either attack the player or run away from the player. However the third and forth rules the NPC will wait until the Health of the Home is at 50% then it will attack the player. The rules allow the NPC to be more than a static object. However, if every monster reacts the exact same way then the AI is too simple and highly predictable. It is best to have variety with the AI’s that allows the player to have a different experience for each monster type.

Is predictability good or bad? That is a point of view that is relative to the developer and the gamer. What a developer may consider complicated the player may find it predictable. However if the developer throws a random into the AI to simplify the logic required this becomes a less predictable monster from the players perspective. Many developers find the best way to program the AI is to create a large list of actions and responses then pick and choose which the MOB will react to.

This allows the MOB to act as a vender or a quest giver which cannot be attacked. But it could also create a highly aggressive MOB that will attack the player when the avatar is within view. These two different AI’s stem from the same basic architecture which makes it simplistic to program and yet provide the diversity that the player needs to remain interested. Most games are written with this style AI because it can be written once and then the MOBs can be created statically or dynamically depending on the design of the game environment. In the end, there are many ways to program a simple AI but the table logic method is the first step into the world of writing an AI for any game.


Related pages

  1. Pathfinding Basics
  2. Simple Combat Logic
powered by Related Pages WP plugin

29 Responses to “AI Basics”