Visualize the center of the rank battle environment from the Pokemon Home API

What is the Pokemon environment?

The term environment used in Pokemon battles refers to what kind of Pokemon, strategy, and construction are used in the rank battle of Pokemon Sword Shield. It can be said that the real thrill of Pokemon battles is to create a structure that is easy to win in the current environment by knowing the environment and considering the meta for it.

The center of the environment

In Character Rank Maker operated by Pokemon Soldier, a Pokemon battle information sharing site for apts. Evaluations from S to E ranks can be set personally, and the character ranks that are subjectively evaluated by famous commentators and commentary video contributors are referred to.

Pokemon Soldier himself regularly publishes character ranks. https://youtu.be/TMXQ497foRg

スクリーンショット 2020-11-24 172842.png

The S rank of this character rank is defined in the video as "the center of the environment" by Pokemon Soldier. On the other hand, I thought that the problem was that the evaluation of the center of the environment was subjective, and that a quantitative evaluation method was necessary.

Target

The goal is to "quantitatively evaluate the center of the environment." In this article, I would like to consider the center of the environment based on data as much as possible.

Pokemon home

Pokemon Home is a Pokemon management app that can be used on smartphones and Switch. Since the number of Pokemon that can be stored in the software is limited, you can use it by temporarily storing unnecessary Pokemon here.

In addition to that, this Pokemon Home is also equipped with an exchange function, Pokemon environmental information in ranked battles, player ranking function, etc., and is frequently used for environmental surveys among apt people.

API As introduced in the article here, Pokemon Home directly uses the API used in the app by disguising the User-Agent. You can get json data by hitting it. The following API is used this time. Please check the link for details.

#Get information on season terms
https://api.battle.pokemon-home.com/cbd/competition/rankmatch/list
#Acquisition of battle data for the relevant season / term
https://resource.pokemon-home.com/battledata/ranking/$id/$rst/$ts2/pokemon
#Pokemon data for the relevant season term
https://resource.pokemon-home.com/battledata/ranking/$id/$rst/$ts2/pdetail-$j

Evaluation method

In order to process the environment into a form that is visually easy to understand and easy to analyze, we will consider evaluation using graphs this time. As for the graph, there is an article I wrote in the past, so please refer to here.

In this article, we decided to evaluate the high rate of simultaneous adoption with Pokemon, which has the highest usage rate ranking. This is because I thought that the focus of the environment should be on the impact on other Pokemon and the ease of incorporating it into the party, rather than the performance of a single unit. Considering the top 10 Pokemon with high simultaneous adoption rate of the top 30 Pokemon Home usage rate rankings, we will visualize the relationship with an undirected graph.

Nodes and edges

Nodes and edges need to be defined for undirected graphs.

This time, we will create a graph with nodes as Pokemon and edges as the presence or absence of the highest simultaneous adoption rate.

For example, if you consider 10 animals that have a high simultaneous adoption rate with Aceburn, you will extend 10 edges from the Aceburn node to each Pokemon node.

図1.png

This was repeated for the top 30 Pokemon, and it was assumed that the Pokemon that reigns over the node with the highest degree is the Pokemon that has a strong mutual relationship with the Pokemon at the top of the environment.

Data collection

The required data is as follows.

--Pokédex (Pokédex number and name association) --Season term ID information (rst, ts1, ts2) --Competition environment information for the season term (Pokemon list with the highest usage rate) --Information on Pokemon for the season term (Pokemon list with the highest simultaneous adoption rate)

Pokédex

When I searched for a Pokédex compatible with 8 generations, there was a person who distributed it as a json file, so I borrowed here. .. Since the information on Pokemon such as Ulaos Blizapos added after the isolated island of armor has not been updated yet, if you try it in the latest environment, the result will be a little noisy due to the Pokemon that is not in the picture book.

> git clone https://github.com/dayu282/pokemon-data.json
import json

pokedex = {}
for i in range(8):
  #Added Pokemon of all generations
  j = i + 1
  with open("pokemon-data.json/en/gen" + str(j) + "-en.json", "r", encoding = "utf-8") as f:
    pokemons = json.loads(f.read())
    for pokemon in pokemons:
      pokedex[pokemon["no"]] = pokemon["name"]

Season term ID information

#Get all season information and save it in json format
> curl https://api.battle.pokemon-home.com/cbd/competition/rankmatch/list \
  -H 'accept: application/json, text/javascript, */*; q=0.01' \
  -H 'countrycode: 304' \
  -H 'authorization: Bearer' \
  -H 'langcode: 1' \
  -H 'user-agent: Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Mobile Safari/537.36' \
  -H 'content-type: application/json' \
  -d '{"soft":"Sw"}' \
  -o season.json
with open("season.json", "r", encoding = "utf-8") as f:
  data = json.load(f)["list"]

#Arrange only the necessary information for each term
terms = []
for season in data:
  for id in data[season]:
    terms.append({"id" : id, "season" : data[season][id]["season"], "rule" : data[season][id]["rule"], "rst" : data[season][id]["rst"], "ts1" : data[season][id]["ts1"], "ts2" : data[season][id]["ts2"]})

Information on the battle environment and Pokemon for the season and term

By embedding a variable in the command using Jupyter, it is acquired using a loop. Since Pokemon information is divided into 5 parts, get all pdetail- {1 to 5} and concatenate them.

for term in terms:
  if term["rule"] == 0:
    #Acquisition of battle environment
    id = term["id"]
    rst = term["rst"]
    ts1 = term["ts1"]
    ts2 = term["ts2"]
    pokemons_file = str(id) + "-pokemons.json"
    !curl -XGET https://resource.pokemon-home.com/battledata/ranking/$id/$rst/$ts2/pokemon -H 'user-agent: Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Mobile Safari/537.36'  -H 'accept: application/json' -o $pokemons_file
    for i in range(5):
      #Get Pokemon information for the term
      j = i + 1
      pokeinfo_file = str(id) + "-pokeinfo-" + str(j) + ".json"
      !curl -XGET https://resource.pokemon-home.com/battledata/ranking/$id/$rst/$ts2/pdetail-$j -H 'user-agent: Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Mobile Safari/537.36'  -H 'accept: application/json' -o $pokeinfo_file
id = 10011 #Season 1 single battle

#Top Pokemon List
with open(str(id) + "-pokemons.json", "r", encoding = "utf-8") as f: 
  top_pokemons = json.load(f)[:30]

#Pokemon information
pokemons_info = {}
for i in range(5):
  j = i + 1
  with open(str(id) + "-pokeinfo-" + str(j) + ".json") as f:
    data = json.load(f)
    for index in data.keys():
      pokemons_info[index] = data[index]

Drawing graphs and creating order rankings

Now that we have the necessary data, we will draw a graph.

nodes = [] #Node list
edges = [] #Edge list

#Consider the top 30
for pokemon in top_pokemons:
  #Add the Pokemon to the node
  nodes.append(pokedex[pokemon["id"]])
  #Added Pokemon to be adopted together
  with_poke_list = pokemons_info[str(pokemon["id"])][str(pokemon["form"])]["temoti"]["pokemon"]
  for with_poke in with_poke_list:
    nodes.append(pokedex[with_poke["id"]])
    if (pokedex[with_poke["id"]], pokedex[pokemon["id"]]) not in edges: #Eliminate duplication by order
      edges.append((pokedex[pokemon["id"]], pokedex[with_poke["id"]]))

nodes = list(set(nodes)) #Convert to a set once and make it unique
import networkx as nx
import matplotlib.pyplot as plt
from matplotlib import font_manager

#Invalid graph creation
G = nx.Graph()
G.add_nodes_from(nodes)
G.add_edges_from(edges)

#Calculate the average degree of the entire network
average_deg = sum(d for n, d in G.degree()) / G.number_of_nodes()
#Size to be proportional to node order
sizes = [2500*deg/average_deg for node, deg in G.degree()]

plt.figure(figsize=(15, 15))
nx.draw(G, with_labels=True, node_color = "lightblue", node_size = sizes, edge_color = "black")
plt.axis('off')
plt.savefig(str(id) + '-graph.png')
plt.show()
#Sort nodes in descending order
nodes_sorted_by_degree = sorted(G.degree(), key=lambda x: x[1], reverse=True)
print(nodes_sorted_by_degree)
 
#Degree ranking output
x, height = list(zip(*nodes_sorted_by_degree))
plt.figure(figsize=(15, 15))
plt.xlabel("Number of degrees")
plt.ylabel("Name of node")
plt.barh(x, height)
plt.savefig(str(id) + '-degs.png')
plt.show()

result

I will show them in order from season 1. There is noise after the ban on the isolated island of armor is lifted.

Season 1

Sword shield environment opening. In terms of order, Mimikyu, Rotom, Drapart, and Drews are overwhelmingly the center of the environment. Looking at the graph, 9 Pokemon are solidified in the center and other Pokemon are drawn so as to surround it, so you can think that 9 Pokemon are S rank in the center of the environment.

10011-graph.png

10011-degs.png

Season 2

The environment begins to change. The new line approaching from the edge is interesting. Nuruant, Brimon, Rhyperior, Nuodehide, etc. enter the environment.

10021-graph.png

10021-degs.png

Season 3

Kyodai Max Snorlax and Kyodai Max Laplace have been unveiled. Immediately enter the environment. At this stage, Laplace has a high adoption rate, but the simultaneous adoption rate with Pokemon with the highest environment is not so high, so in fact, considering this graph, it is evaluated as A or B instead of S rank.

10031-graph.png

10031-degs.png

Season 4

Some new Kyodai Max Pokemon have been lifted, but there is not much change. Torkoal lizardon enters the environment.

10041-graph.png

10041-degs.png

Season 5

No particular change.

10051-graph.png 10051-degs.png

Season 6

The ferrothorn begins to become popular. No other changes.

10061-graph.png

10061-degs.png

Season 7

Lifting the ban on the solitary island of armor. With the lifting of the ban on the dream characteristics of Aceburn Gorilander and the lifting of the ban on Kyodai Max, we will dig into the center of the environment at once. Snorlax Armor Gaa begins to move out of the center of the environment. The fold is a little popular.

10071-graph.png

10071-degs.png

Season 8

Pokemon Home lifted. Pokemon with a receiving loop temperament such as skarmory, blissey, ferrothorn, and dohideide enter the environment. Snorlax is accepted and is out of the environment. At the center of the environment where polygon 2 rages. The value of hippowdon for creating a starting point increases, and hippowdon becomes the center of the environment. By the way, Charizard-1 is a Ulaos who has a problem with pictorial books.

10081-graph.png

10081-degs.png

Season 9

The boundaries of the center of the environment begin to sharpen. Gyarados and Drews go down a little. The receiving loop also begins to appear outside the environment.

10091-graph.png

10091-degs.png

Season 10

It became a high-ranking Pokemon prohibition rule, and the environment changed drastically. Ulaos, Patchragon, Lizardon, Ferrothorn, Rotom, and Achilleine are the focus on the environment. Snorlax and Durant return to the environment. Amoonguss Pixie comes to the environment.

10101-graph.png

10101-degs.png

Season 11

Gengar is at the center of the environment. No other changes.

10111-graph.png

10111-degs.png

Season 12

Lifting of the ban on the snowfield of the crown. Semi-legends such as Landorus, Tekkaguya, Cap, Rehile, Thunder, and Uturoid occupy most of the environment. From the data as of Season 12, it can be said that the center of the current environment is around Mimikyu, Aceburn, Polygon2, Gorilander, Tekkaguya, Caprehille, Landorus, Thunder, and Utsuroid.

10121-graph.png 10121-degs.png

Finally

I set the character rank as of Season 12 as follows based on the order. Please refer to it. It may be full of theory, but I hope it will be useful to you as an index. Let's have a good Pokemon life! 20201124 Season 12 Graph Environmental Rank.png

Postscript: Someone was doing something similar https://qiita.com/b_aka/items/9020e3237ff1a3e676e4

Recommended Posts

Visualize the center of the rank battle environment from the Pokemon Home API
Used from the introduction of Node.js in WSL environment
[Python] Get the text of the law from the e-GOV Law API
Visualize the number of complaints from life insurance companies
I analyzed the rank battle data of Pokemon sword shield and visualized it on Tableau
Visualize the orbit of Hayabusa2
Use the Flickr API from Python
Visualize the response status of the census 2020
From the introduction of GoogleCloudPlatform Natural Language API to how to use it
I tried calling the prediction API of the machine learning model from WordPress
Display the result of video analysis using Cloud Video Intelligence API from Colaboratory.
Pokemon x Data Science (3) --Thinking about Pokemon Sword Shield Party Construction from Network Analysis Where is the center of the network?