Pokemon AI- Gotta code ‘em all

Most people remember pokemon games to be nostalgic. Every 8-bit pixel revives a new memory and every classic sound effect teleports one back to losing a battle to a critical hit.

They are known for their unique monsters, stats, moves and battles. The story mode allows players to battle eight gyms, enemy bosses, elite four members with the champion, and countless trainers throughout the journey. These battles all come with various pokemon with varying move-sets. Most people assume that the moves and pokemon chosen by the machine are random, making the game based on chance. However, the actual story is way different.

Pokemon AI- workings

The pokemon video games use various calculations to determine which move would be the best to secure a win in a given fight. The AI agent is coded in such a way that it has two main goals- navigate the map to each new trainer and defeat each trainer without losing a Pokemon. Thus, it uses the trainer’s HP (Health Potential) stats and damage dealt by a move to calculate a win in all fights.

As an example, we can take a battle from Pokemon Emerald Kaizo, the most difficult Pokemon game: 

Imagine you are fighting against the emerald AI in a trainer fight.

Sample fight in Emerald Kaizo

Here’s how the AI will make its decisions. Firstly, the AI agent will rarely switch a pokemon. Additionally, it will try and go for the move that guarantees a kill on your pokemon. The AI can calculate the actual damage a move may do. Normally a move deals around 85-100% of its maximum damage ability. Thus, the AI calculates the damage roll and plays the most damaging move. If the AI’s HP is very low, it is more likely to pick a healing or self-destructing move. This also depends on the type of pokemon that is being fought. If the AI pokemon is slower than yours, then the agent may choose a stat lowering move instead of a damaging move. In any case, if the AI see a kill, it will for sure go for it.

 

AI processing

The AI code is written in python and uses the pywin32 add-on that includes the Win32 API. The Win32 API allows the programs to interface with Windows, specifically simulating key presses. The AI uses these simulated key presses to interact with the emulator rather than building the emulator into the AI code. The AI runs all choices through a decision tree that dictates what decisions to make. 

After this, the attack variations like STAB and critical hits are entirely based on pokemon typing and stats. Even if you are not a Pokemon fan you have to agree that this is an amazing exercise in working around the programming of Artificial Intelligence. The reputation of Pokemon games exists for a reason. They pioneered the battle AI software, thereby creating a complex universe full of possibilities and imagination. The legacy of Pokemon games will forever be preserved in the form of stories, mangas, TV shows and the infamous enemy AI.

Come Aboard The StarTech!

We don’t spam! Read more in our privacy policy

We don’t spam! Read our privacy policy for more info.

2 thoughts on “Pokemon AI- Gotta code ‘em all”

  1. After reading your article, it reminded me of some things about gate io that I studied before. The content is similar to yours, but your thinking is very special, which gave me a different idea. Thank you. But I still have some questions I want to ask you, I will always pay attention. Thanks.

    Reply
  2. At the beginning, I was still puzzled. Since I read your article, I have been very impressed. It has provided a lot of innovative ideas for my thesis related to gate.io. Thank u. But I still have some doubts, can you help me? Thanks.

    Reply

Leave a Comment