Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When making an npc combatant, it's easy obvious what to do to get a robot deathmachine by optimizing combat tactics, timing and attack types, but harder (and more interesting in a fight) to get an idiosyncratic, inpredictable enemy. What behaviors (algorithms?) are useful for creating a more organic, unconventional enemy?

Edit: My specific use case is with MMO-like enemies, e.g. World of Warcraft, although with less graphics involved. Note that that means both human and inhuman enemies (animals, monsters, etc)

share|improve this question

There is a very interesting article on the matter on Gamasutra: Intelligent Mistakes: How to Incorporate Stupidity Into Your AI Code, by Mick West.

This article talks about a Pool game AI. When implementing such an AI, it's quite easy to make it pot a ball at each shoot. A simplistic way to make the AI less "smart" is, as suggested on other answers, to add a random factor to the calculation, making the AI miss more.

But there is two major flaws with such an approach. First, it's unpredictable. For a player playing in "Easy" mode, it's unacceptable that the AI gets "lucky". What if your random factor makes the AI do an even better shot, hitting a more valuable ball, or doing a combo? You don't know what is going to happen, and being lucky shouldn't be an option for the AI on an easy mode.

The other flaw is that the player will try to identify a pattern in the AI behaviors. And with a simple random factor, there is no pattern. But that doesn't mean the player won't see any pattern, quite the opposite, in fact. As soon as the AI gets lucky, the player will see a strategy in its behavior. In the article, the players are complaining about the AI playing a position strategy. When there's just a random factor in the angular precision.

From my point of view, after reading this eye-opening article, a non-perfect AI should never use randomization as a simplification factor. It's quite the opposite. An easier AI should be smarter, but trying to help the player.

In the article Pool game example, the best option for implementing an "easy mode" AI was in fact to remove all random factor, and to add a positioning strategy. The AI would try to hit balls in order to prepare an easy and awesome shot for the player.

This way, the player will think he got lucky. And that's what you're expecting for a game when playing it easy.

share|improve this answer
It would also be useful for the AI to remember what the player is able to take advantage of. The developers may think that he has an 'easy pot' but if he can't pot it, the case tactic should be less used by the AI. It is also beneficial, because you can train the player, remember what he can't do, and purposely exploit this every so often until he can, this way the player is neither bored, neither frustrated. – Jonathan Connell May 30 '11 at 8:33
While I agree with not using the randomization, I don't agree with "helping the player": that would be like cheating, only much worse because you would be lying to the player. – o0'. May 30 '11 at 12:05
@Lo'oris: Well, I don't see it as a lie. When the players tells the game to go easy on him, he's expecting the game to be gentle. When you're playing a game you're really good at with a friend who's just discovering it, I feel it's quite okay to give him opportunities. It makes the game more enjoyable for everybody. – Tyn May 30 '11 at 12:58
There is a good blog post by Shawn Hargreaves on randomization, and the ability for a human to spot patterns in randomness. This would translate ton, in this case, a player incorrectly judging the tactics of an AI player. – Jonathan Connell May 31 '11 at 7:29
Actually I think randomization on accuracy is a good way to go. With a real player who is not that great, sometimes he will make a mistake and hit a better ball in. – AttackingHobo May 31 '11 at 16:09

The key concept is to avoid giving the NPC "perfect knowledge".

  • Randomized margin of error on any decisions or actions that involve a calculation. obvious example being aiming (ie. stormtrooper snipers). If they don't always hit you, it's more realistic.
  • Line of Sight ... if they can't see you, it can make an interesting game of cat and mouse.
  • Team tactics, depending on your type of game, enemies that adapt to the situation can be way more interesting. For example, if you're getting shot at, you wouldn't charge in blindly, you'd take cover until incoming fire lets up. Or perhaps you would feel more comfortable with rushing in if you've got team-mates nearby ... you can simulate those behaviors to make the NPCs behave as if they were alive.

I'm sure there's a ton more examples that will be given, maybe you could tell us about your game and we can get more specific :-)

share|improve this answer

One quick way to render a perfect AI fightable is to have it make unperfect decisions by adding some 'noise' to either its inputs or its outputs. By noise I mean some random factors.

Here's a small example for output:

  • Perfect algorithm yields three possible actions ranked with a score.
  • Add a random value to each score.
  • Pick best score.

Here are some ideas for input:

  • If actions are based on opponent's health, add a random factor (say +/- 10 for a 0-100 health bar) to perceived state by AI.
  • Same for rating of actions, if AI knows some attacks are stronger than others, randomly add/subtract some values there.

One obvious thing to take into consideration is the speed of the AI. In most games, AIs can react MUCH faster than humans (especially in fighting) and do apparent multitasking (very visible in RTS games). So you have to act on that, by keeping the AI a bit slow (maybe adaptively so), and limiting the amount of things it can do in a determined frame of time (ie one action each half-second).

Hope this helps, and good luck!

share|improve this answer

It's difficult to give a directly useful answer without knowing what exactly you're trying to do.

I have two things to say on the subject that might help you out.

First thing (and this is by far the most important one), if you're trying to make the enemy feel more interesting and human then your combat tactics are irrelevant. The trick to making players "believe" an enemy is alive is to use animation, sounds, and little details to imply human behavior. The perfect AI might walk around a corner, see a player, and shoot. A human AI might walk around a corner, see a player, have a surprised look on his face and shout out in alarm, and shoot. The first one seems robotic. The second one seems human. Both are using identical AI in every way, other than the insertion of the animation just before shooting (or, to keep the tactical behavior the same, during shooting).

Second, avoid randomizing. Players don't appreciate it as much as designers want to think they will. Players don't see "computer generated a 1 out of 100, followed by a 5, 3, and 4, so the error factors for the last four shots were only 1%, 5%, 3%, and 4%, and that's why you died in half a second this round." The players just see enemies that sometimes wildly miss and other times nail them repeatedly for no discernible reason, which is incredibly frustrating. Good game design is largely about building patterns that human players can observe, learn, and beat, and making the player's success based on his own judgement and skills and intuition rather than making it about whether the player got lucky. The urge to randomize comes from experience with table-top games and gambling games, both of which are incredibly different mediums than video games (and what works in one medium often does not make sense in another).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.