Building a Competitive Pokémon Team using Analytics and Fight Simulation Visualization

Satyam
Analytics Vidhya
Published in
8 min readApr 2, 2021

--

Source: Image by Author

I recently, along with my teammates (Shubham and Harshit ) participated in an Analytics Competition which was organized by Information Management and Analytics Club, IMI Delhi where we emerged as winner. In this blog, I will explain our solution in detail which might be of help to analytics enthusiasts in similar competitions.

You can download the data set along with the problem statement from here.

Objective

The primary objectives of the case were :

  1. Creating a Primary & Secondary Team of 5 Pokémon using historical data
  2. Estimations of their statistics when they compete in the Pokémon Arena

Data Pre-processing

1) Dropping irrelevant columns

‘japanese_name’ was dropped because it was irrelevant to our analysis

2) Handling Missing Values

i) Values are missing in columns: ‘type2’, ‘percentage_male’, ‘weight_kg’ and ‘height’

ii) Missing value in ‘type2’ column represents Pokémon is only of one type (Assumption) and it was left missing.

iii) Missing value in ‘percentage_male’ column represents Pokémon is gender-less (based on research done) and hence it was filled with “-999” to represent gender-less

iv) Missing value of ‘height’, ‘weight_kg’ columns were filled using median

Team Formation Strategy

Before taking part in this competition, I had significantly less idea regarding Pokémons. Interestingly , my nephew helped me in understanding everything related to Pokémons. You can call this as my primary research!!! : )

Effective Score Calculation

We used an effective score method where an effective score was calculated for each Pokémon and based on the score, primary and secondary teams were selected.

Effective Score Formula

Here, S_Score = Strength score and W_Score = Weakness score.

Note: S_Score and W_Score was normalized before calculating Final score

From the effective score formula, it is evident that effective score would increase with increase in Pokémon Strength and decrease with increase in weakness score and vice-versa.

Now, we will have to calculate S_Score and W_Score.

Strength Score (S_Score) Calculation

Here, the most important task was to identify the variables which can used to calculate strength score. As the major objective of score calculation was to build a team for battle, we chose the variables which can impact its performance in the arena positively.

The strength score was calculated using the following variables:

1) ‘attack’,

2) ‘defense’,

3) ‘hp’,

4) ‘special_attack’,

5) ‘special_defense’,

6) ‘speed’

S_score=(attack_weight× attack)×(defense_weight×defense)…..(speed_weight×speed)

Where attack_weight, defense_weight… speed_weight are weights given to variables for calculating Strength Score

Calculation of weights for Strength score: Weights of variables involved in calculating Strength score was calculated using Random Forest feature importance. It was assumed that legendary Pokémon would perform better compared to others in the arena. Based on the above assumption, classification model was designed and features’ importance was calculated and assigned to respective variables (Permutation importance should be preferred over RF feature importance as the latter can be misleading. Refer here for more)

Weakness Score (W_Score) Calculation

Weakness score was calculated using weaknesses of each Pokémon against other.

The weakness score was calculated using the following variables:

1) ‘against_bug’,

2) ‘against_dark’,

……

18) ‘against_water’

(Refer data-set for complete list of variables)

W_score=(bug_weight× against_bug)×(dark_weight×against_dark)…..(water_weight×against_water)

Where bug_weight, dark_weight etc are weights given to different variables used for calculating W_Score.

Calculation of weights for Weakness Score: For calculating the weights given to different variables, number of different types of Pokémon was calculated and weights were assigned accordingly.

Number of Pokémon of different types

The above strategy was adopted because each Pokémon’s vulnerability varies against different kinds of Pokémons. For example, if the number of bug type Pokémon is high, probability of encountering a bug kind of Pokémon in battle ground would be higher, hence more weightage should be given to “against_bug” weakness.

Team Formation

Once we got the effective scores of all the Pokémon,we sorted them based on calculated Effective Score. Top five Pokémon’s were assigned to Primary Team except for “Salamence” as his type was same as “Rayquaza”. (Each team of 5 should have all different types of Pokémon according to the problem statement) “Rayquaza” was preferred over “Salamece” because of higher effective score. Similarly, the Secondary team was selected. “Salamece” was assigned to the secondary team.

Team Statistics Visualization

Primary Team
Secondary Team

From the above plots, we can compare different members of our primary and secondary teams based on different parameters such as attack, special attack, hp etc.

Based on comparison, following insights can be derived:

  • Defense and Attack of “Groudon” is maximum in the primary team whereas Special Defense and Special attack of “Kyogre” is maximum
  • Hp and Speed of the primary team members are not too different from each other.
  • In the secondary team, attack, defense, and special defense of “Tyranitor” is maximum but, hp and special attack are low.

Battle Estimations

The Objective of this analysis was to determine the fight statistics of Pokémon battles. A simulation of 100 battles between the chosen Primary Team and 100 randomly selected teams of 5 Pokémon was executed.

The Simulation can be extended to nC5 randomly generated teams. (Note: Requires heavy computational resources and hence we limited ourselves with 100 simulations)

Rules of the Battle:

  • In order to ensure fair battles, each opponent will also have a team of 5 Pokémon
  • The Pokémon with greater speed will attack first
  • In case of stalemate of the above condition, a random selection will be made
  • The limitation of having only one Pokémon of a particular type does not apply to the opposition (Stress Test)
  • Once defeated (hp=zero), the Pokémon cannot take part in other battles
  • The simulation will continue unless all the Pokémons in the opponent team are defeated
  • The team with last Pokémon standing will win
  • When a Pokémon moves into next round it will carry its updated HP from previous battle

Battle Simulation Algorithm:

You can also directly refer to the code given at the end.

Step 1: Load 2 teams of 5 Pokémon each into the battle simulation

Here, we are sending two teams to fight in the arena.

Step 2: Select Pokémon from each team having: HP !=0 and Max(Speed)

Each team should select one Pokémon which will go first for the fight. The Pokémon with max speed and Hit Points not equal to zero will be selected.

Step 3: Load 2 selected Pokémon into battle Simulation

Step 4: Calculate the attack and defense points (Engineered Feature) for both the Pokémons

Attack Points= ( Pokémon[‘attack’] + Pokémon[‘ special_attack’] ) / 4

Defense Points = (Pokémon[‘defense’] + Pokémon[‘ special_defense’])*4

Attack and defense points signifies how well one Pokémon can attack the other and how well it can avoid attacks from the others in the arena.

Step 5: Calculate the damage done per move

If:

attacking Pokémon has advantageous Type over the defending Pokemon

Then:

Deal bonus damage (Amplify the attack by the factor of Pokémon[‘against_<type>]

Damage = {Attack Points(Attack, Pokemon) / Defense Points (Defense Pokemon)}* amp factor

Here, we are calculating the damage (reduction in Hit Points). The damage will depend upon the attack points of the opponent and defense of the player.

Step 6: The Pokémon with Greater speed of the two will attack first

(Concept taken from Pokémon Gameplay)

Step 7: Fight ends between two Pokémons

Step 8: Calculate HP (Hit Points) of defending Pokémon:

HP = HP - Damage

HP of other will be zero

Step 9: Check If Total HP(HP of the Team)=0

Then: End battle

Else: Continue:

Surviving Pokemon proceeds to next round with leftover HP

Surviving Pokémon fights with next opponent Pokémon with max speed

Repeat from Step 3

Step 10: Defending Pokémon’s turn to attack

Step 11: Repeat from Steps 7–10

Step 12: Iterate till one of the team runs out of all 5 Pokémons i.e. team HP=0 (Defeated Pokémon cannot battle again)

Step 13: Declare the winning team with HP margin

Following outputs shows details of one of the battle between primary team and randomly selected opposition team:

Battle Number:  1
--------------------------------------------------------------------
BATTLE BEGINS
--------------------------------------------------------------------
Total Hp Team 1: 533
Total Hp Team 2: 248
----------------------------------------------------------------
Arceus vs Kadabra
HP1: 120 HP2: 40
HP1: 81 HP2: 0
Fight Ends
----------------------------------------------------------------
Total Hp Team 1: 494
Total Hp Team 2: 208
----------------------------------------------------------------
Arceus vs Volbeat
HP1: 81 HP2: 65
HP1: 17 HP2: 0
Fight Ends
----------------------------------------------------------------
Total Hp Team 1: 430
Total Hp Team 2: 143
----------------------------------------------------------------
Arceus vs Finneon
HP1: 17 HP2: 49
HP1: 0 HP2: 32
Fight Ends
----------------------------------------------------------------
Total Hp Team 1: 413
Total Hp Team 2: 126
----------------------------------------------------------------
Rayquaza vs Finneon
HP1: 105 HP2: 32
HP1: 74 HP2: 0
Fight Ends
----------------------------------------------------------------
Total Hp Team 1: 382
Total Hp Team 2: 94
----------------------------------------------------------------
Rayquaza vs Sandile
HP1: 74 HP2: 50
HP1: 25 HP2: 0
Fight Ends
----------------------------------------------------------------
Total Hp Team 1: 333
Total Hp Team 2: 44
----------------------------------------------------------------
Rayquaza vs Squirtle
HP1: 25 HP2: 44
HP1: 0 HP2: 19
Fight Ends
----------------------------------------------------------------
Total Hp Team 1: 308
Total Hp Team 2: 19
----------------------------------------------------------------
Garchomp vs Squirtle
HP1: 108 HP2: 19
HP1: 90 HP2: 0
Fight Ends
----------------------------------------------------------------
Total Hp Team 1: 290
Total Hp Team 2: 0
--------------------------------------------------------------------
BATTLE ENDS
Winner: Team 1 by 290 points

Simulation Results

Primary Team with Opposition

Number of Times primary team won:  100
Number of Times opposition team won: 0
Avg margin: 196.04
Std Deviation in margin: 60.09
Simulation Results

Secondary Team with Opposition

Number of Times secondary team won:  99
Number of Times opposition team won: 1
Avg margin: 185.71
Std Deviation in margin: 53.24
Simulation Results

Battle Estimation Code

You can find the complete code on my Github.

You can reach out to me on LinkedIn . Follow me for more articles on Analytics and Data Science.

--

--