Pokemon Showdown AI Introduction

Introduction

In my first semester of grad school, I have been taking Artificial Intelligence, learning about the theory and algorithms behind AI. All I have been able to think about in every class is how can I apply this to Pokémon, literally, every class! So, I thought why not give it a go? I haven’t completed the class, therefore as I develop the idea I might think of a better way to enact my vision but for now, I have a basic concept of what I want to achieve and what algorithm to use.

Background on Pokémon Showdown and 6v6 singles battling and mechanics

Pokémon Showdown is an online battle simulator where you can build teams of 6 to battle in different formats. My most played format is the Gen 8 OverUsed Tier. During Lockdown in 2020, I got back into playing on the competitive OU ladder and managed to reach the 1700s for the first time, which placed me top 500 for a brief few days.

Pokémon are tiered so that more Pokémon can be viable despite there being big discrepancies in which ones are good and bad. OU is the second-highest tier, with the most overpowered Legendaries being put into Ubers, and overall, it is the most played tier. The tiers for 6v6 singles are Ubers, OverUsed, UnderUsed, RarelyUsed and NeverUsed. You are also allowed to use Pokémon in tiers lower than the one you are playing in. There are other formats of play but we will be focusing on 6v6 singles.

In competitive battling 6 of your Pokémon versus 6 of your opponent’s Pokémon, with each Pokémon able to have a held item and no consumable items (no potions, revives etc.) that are usually available when playing the main series Pokémon games. Other than Tiering Pokémon, there are certain moves and conditions put into place to keep the game competitive, such as only one Pokémon can be put to sleep at a time, no one-hit KO moves, no Baton Pass etc.

Each Tier develops its own metagame, whereby a certain Pokémon rises to prominence because of how well it does against the Pokémon available in the Tier. This helps when playing competitively because you can develop intuition and understanding of what Pokémon your opponents will play and what sets they have.

The complexity in the battle comes from how you build your team. Pokémon have 6 Stats, which are values that determine the amount of damage dealt or taken by a Pokémon, such values are derived using a damage calculation. These Stats are HP (health points), Attack, Special Attack, Defense, Special Defence and Speed. You also have access to 252 Effort Values (EVs) to assign across the 6 Stats to specify the exact Stats of your Pokémon. This means you could build a Pokémon to be a fast and strong attacker or have a lot of bulk and high Defence. A great deal of effort goes into building a team and then playing it against others. However, all of these factors make developing a Pokémon AI difficult as there are numerous considerations to account for.

Other factors to think about are Status Conditions such as:

  • Paralysis, which halves a Pokémon’s speed and may result in the Pokémon being unable to move.
  • Burn, which reduces the damage a Pokémon can inflict by 1/16thof its total health and halves its attack.
  • Poison, which reduces Pokémon’s health by 1/8th each turn.
  • Toxic Poisoning, which deals n/16th of the Pokémon’s total health, where n starts as 1 and increases by 1 each turn (1/16, 2/16, 3/16 etc.),
  • Sleep, makes a Pokémon unable to move with a 1/3 chance of waking up each turn.
  • Freeze, renders a Pokémon unable to move with a 1/5 chance to thaw out.

There are also Entry Hazards, which can be set up by Moves that damage a Pokémon and reduce a Stat or inflict a Status Condition on the switch in. They are a great way to set up a consistent way to weaken opposing Pokemon on the switch-in.

Complexity is increased further when Pokémon have 4 Moves available to them which can achieve numerous things. Such Moves can damage an opposing Pokémon, inflict a Status Condition, set up Entry Hazards, lower the opposing Pokémon’s Stats, make them flinch, any combination of these effects and more. Each Move also includes a Base Power, determining how much damage it deals, and accuracy, and how likely a Move is to hit.

Damaging Moves are either Special or Physical;

  • Physical Moves are calculated with a Pokémon’s Attack Stat against the opponent’s Defence Stat.
  • Special Moves are calculated with a Pokémon’s Special Attack Stat against the opponents Special Defence Stat.

Pokémon and Moves also have Typing (Fire, Water, Grass, Electric, Ghost etc.) If a Move Type is super effective against your defending Pokémon’s Type, it deals double damage, if a Move is not very effective it does half damage etc. Pokémon also have Dual Typings, so you can have Pokémon that is 4 times weaker against Moves or on the other hand can resist Moves by 4 times (that they only deal 1/4 damage). Additionally, if a Move used by a Pokémon is the same type as the Pokémon there is a 1.5 times damage bonus.

There are more factors involved in Pokémon battling, this is by no means a comprehensive summary, but I wanted to provide some background to illustrate the obstacles that need to be overcome when designing AI for singles battling.

Representation of how Pokemon may be tiered
Damage Formula
Pokemon type matchup chart

Thoughts on how to approach this problem

Monte Carlo Search tree algorithm

Developing AI has been a popular endeavour for classic games, such as Chess and Go. However, these games have a few major differences from Pokémon 6v6 battles.

  • The first difference is that both the classic games are fully observable, meaning you can see all your opponent’s pieces and see all the moves they can make. In Pokémon, you can only see your opponent’s Pokémon, but you do not know their Moves, Ability and EV distribution.
  • The second difference is that Chess and Go are deterministic, meaning they are not luck-based games, there is no random chance or chaotic factor. In Pokémon, Moves have accuracy, but there are chances for Moves to trigger secondary effects and more, which makes Pokémon a stochastic game.
  • The final difference is that Pokémon isn’t turn-based, whereas in Chess and Go each player makes consecutive moves allowing the players to analyse the state of the board after their opponents move and make their next move accordingly. However, in Pokémon, both players make their Moves simultaneously based on the state of the game, and which Pokémon goes first is dependent on the Pokémon’s Speed Stat.

I had to consider all these variables in order to formulate the best method to develop an appropriate AI program. Based on what I have learned, the best solution I can think of is to use the Monte Carlo search tree method. This method analyses a state, all the possible moves, and then runs what is called rollout functions to see which option is best.

The rollout function randomly simulates the game for a certain number of turns and evaluates the final state based on a heuristic function. At each point in the game, a player has a total of 9 options, that is 4 Moves and 5 possible Pokémon to switch into (assuming none have been defeated). The challenge is that the opponent’s Moves and EV distribution are unknown at the outset.

The question is how do I manage the rollout function? I found the solution is to create a Data Set of games, containing data on what Sets and Moves the Pokémon are running, then based on that, pick the most common Set and use that in the rollout. Following that, as information is gained in the battle, use the gained information to predict which particular Set is being used from the Data Sets. For example, when a Dragaplut is using the Move Dragon Dance, the algorithm would adjust the predicted Set to be the most common Set using Dragon Dance, as opposed to the common default Set, being the Choice Specs Set, using the gen 8 ou tier as an example. This can also predict Pokémon’s Stats.

The next issue is how to evaluate the State after the rollout? I believe a suitable option is a Heuristic function that takes into account;

  • Pokémon not defeated on your team against Pokémon not defeated on your opponent’s team
  • the difference of your teams’ % health against your opponent’s team % health,
  • the amount of hazards on your side of the field against hazards on your opponent’s side of the field
  • the number of Pokémon inflicted with Status on your team against the number of Pokémon inflicted with Status on your opponent’s team.

I could also possibly assess the best weighting for this function by implementing a perceptron algorithm.

AI is a new and exciting realm for me, and I am uncertain of the outcomes of applying my strategy, however, I am keen to learn what obstacles I need to overcome and the final result of my effort.