How Do Video Game Enemies Think? [VIDEO]
Rogelio Valdés
Jan 4, 2021
See the Video Game Programming Course at robinacademy.com/vg
Lately I have been playing a lot of Zelda: Breath of the Wild and Hyrule Warriors: Age of Calamity. I really enjoy fighting the enemies, so much so that I have already memorized many of their behavior patterns. The more I play, the more I realize how simple their logic actually is. In fact, it is very similar to the enemies we program in our Video Game Programming Course.
As a child, I was always curious about how video game enemies “thought,” and in recent years people have become very used to calling that artificial intelligence. But is that really what it is? Let’s look at it.
Take this enemy from Hyrule Warriors as an example. It is a relatively difficult enemy to defeat, and at first it may seem very “intelligent.” But if you pay attention while fighting Sooga, you start noticing that he usually tries to move close to the player and then launches an attack. Some attacks leave him vulnerable for a few seconds and let us destroy his guard. Other attacks are quick and do not leave any opening. Finally, he has strong attacks that we can block using one of the powers from the Sheikah Slate.
So how does the character decide what action to take? One useful way to think about this is as a decision tree. The root of the tree is the start of the battle, where these characters are usually instructed to approach the player. Once they get close enough, the branches begin. One branch tells him to perform the attack with the two swords that create purple circles. Each branch represents a different move. But he cannot choose every branch at once or perform every action at the same time.
How does the game choose which branch to follow?
One very simple method is randomness: rolling a die, generating a random number, and so on.
Imagine we spin a wheel, and depending on where it lands, we select one branch or one attack. You could spin it three times and get the same attack all three times, or you could get three completely different attacks. That makes the enemy harder to predict.
Is this artificial intelligence?
It might look like the enemy is reacting differently every time, but it is not learning anything from our actions. It is not changing its fighting style because we moved to different terrain or because we used a different kind of attack. So this is not really artificial intelligence. And most enemies have worked like this for decades.
Can we make them more advanced? Absolutely. Imagine I change the size of each section of the wheel so that one attack becomes more likely than another. Then imagine those probabilities change depending on the terrain or the type of attacks the player is using. That gets more interesting, but it still is not truly artificial intelligence.
There are games with much more complex enemies, bigger decision trees, and highly specific moves for different situations. But even hugely successful games like Zelda still use relatively simple systems like this. And that tells us something important: your game does not have to be the most technologically advanced in order to be fun.
So then, what is artificial intelligence? It does exist, and it is already being used. Artificial intelligence is an algorithm that perceives its environment, understands what is happening around it, and can adapt in order to respond in the best possible way to achieve its goal. The enemy we just described does not adapt, which is why it is not truly intelligent. It is a fascinating topic, but that will be for another video.
If this topic interested you and you want to learn how video game enemies actually work, I invite you to check out the Video Game Programming Course, where we show exactly how these ideas translate into code so you can build your own enemies.
See the Video Game Programming Course at robinacademy.com/vg