How Does AI Make Decisions in Games? | Gaming-DB
/article/how-ai-works-in-games/edi.webp

How Does AI Make Decisions in Games?

How Does AI Make Decisions in Games?

Recently, we’ve been experiencing an AI craze. We’ve started to become intimately familiar with many AI tools, especially ChatGPT. However, the AI we encounter in these tools and the AI we see in video games are very different concepts. Although we talk about AI in games, what’s actually happening is a decision-making mechanism that applies predetermined actions based on environmental conditions.

The concept of AI we’re referring to is actually a digital structure that can perceive its environment, learn from what it perceives, and make decisions based on what it has learned.

However, what we call AI in video games is far from this concept. Game AI is more of a management mechanism that takes predetermined actions in response to specific predefined situations, rather than a system that can learn and think. Let’s proceed with an example. Consider an enemy AI:

  • If you see the player, shoot.

Our enemy character doesn’t realize the player is approaching and decide to shoot to protect itself. We simply gave it a command. It constantly checks whether it can see the player, and when it does, it performs the shooting action we’ve specified. The developer can manipulate this as desired. For instance, instead of saying if you see the player, shoot, we could say if you see the player, jump.

As you can see here, there’s no learning system involved. We simply had the character constantly check the value of a variable we defined. And when this variable takes on the value we want, we made it perform the action we desired.

Why is AI So Bad in Some Games?

If it’s this simple, why do our enemies act so stupidly in some games? The matter isn’t actually that simple. The more conditions you input, the better your so-called AI becomes. Let’s improve our example:

  • If the player is between 10 and 50 meters away from you, shoot at them.
  • If the player is less than 10 meters away from you, retreat.
  • If the player is more than 50 meters away from you, approach the player.
  • If your health is low, take cover.

As you can see, this AI acts a bit smarter than the previous one. In game development, everything is about making things seem real. There’s no need to make the AI actually intelligent; it’s enough for it to seem intelligent. Imagine if the AI was truly intelligent, truly able to perceive its surroundings and learn new things. You wouldn’t be able to play the game because the AI would constantly beat you.

Instead of calling this system in games AI, it actually makes more sense to call it a behavior tree. We have a behavior tree for each of our characters. You can see an example behavior tree in the image. Behavior Tree Let’s say we have a character on patrol. While on patrol, if it sees someone, it shoots. We’ll have a behavior tree similar to the one on the screen.

The more conditions you add here, the better AI you’ll have. For example, you can have the character check its health at each step. If the character’s health is 100, it’s calm; if it’s 75, it’s aggressive. If it drops below 50, it’s cautious. If it drops below 10, it’s trying to hide, and so on.

Of course, there’s also this: in a good game, you don’t want every AI to behave exactly the same. Because a player who constantly encounters the same thing will start to get bored. In the previous example, we said that an NPC whose health drops below 10 should hide. Instead, we can do something like this: We create a list of possible actions when the health value drops below 10. Whenever the health value drops below 10, one of these actions is randomly performed. This way, we’ve created a better behavior tree.

However, in the near future, we might start seeing real AI in games. For example, imagine an RPG game. You need to enter somewhere, but there’s a guard at the door. In today’s RPG games, the game gives you 3-4 dialogue options. One of these dialogues convinces the guard and opens the door. With real AI, instead of dialogue options, we could create a game where we write whatever dialogue we want and try to manipulate the guard.

Please note that this article was originally written in Turkish. As a result of the translation process, there may be instances where the translated text contains inaccurate equivalents of terms or expressions.