64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
import json
|
|
import random
|
|
import pandas as pd
|
|
#load moves from json file
|
|
#eclude moves with power equal to null,
|
|
# do not consider the effect,effects or changes fields
|
|
available_moves = dict()
|
|
|
|
keys_to_skip = ['effect','effects','changes']
|
|
with open('moves.json', 'r') as file:
|
|
for line in file:
|
|
m = json.loads(line)
|
|
|
|
if m['power'] == None or m['accuracy'] == None:
|
|
continue
|
|
else:
|
|
|
|
available_moves[m['name']] = {}
|
|
m_keys = list(m.keys())
|
|
for k in m_keys:
|
|
if k in keys_to_skip:
|
|
continue
|
|
else:
|
|
available_moves[m['name']][k] = m[k]
|
|
continue
|
|
available_moves_df = pd.DataFrame.from_dict(available_moves,orient='index')
|
|
|
|
#loading pokemons from json file
|
|
#assume levell = 1 for all
|
|
pokemons_dict = dict()
|
|
with open('pokemons.json', 'r') as file:
|
|
for line in file:
|
|
p = json.loads(line)
|
|
p['level'] = 1
|
|
pokemons_dict[p['name']] = p
|
|
#pokemons_dict[p['name']]['level'] = 1
|
|
|
|
current_pokemon_types = p['types'] + ['normal']
|
|
compatible_moves = []
|
|
for m in available_moves.keys():
|
|
if available_moves[m]['type'] in current_pokemon_types:
|
|
compatible_moves.append(m)
|
|
#select two random moves
|
|
selected_moves = [random.choice(compatible_moves) for _ in range(2)]
|
|
pokemons_dict[p['name']]['moves'] = selected_moves
|
|
pokemons_df = pd.DataFrame.from_dict(pokemons_dict,orient='index')
|
|
|
|
|
|
available_pokemon_names = list(pokemons_dict.keys())
|
|
available_starter_names = ['bulbasaur', 'charmander', 'squirtle']
|
|
|
|
#type effectiveness
|
|
type_effectiveness = []
|
|
available_types = dict()
|
|
with open('type_effectiveness.json', 'r') as file:
|
|
for line in file:
|
|
loaded_line = json.loads(line)
|
|
type_effectiveness.append(loaded_line)
|
|
available_types[loaded_line['attack']] = loaded_line['attack']
|
|
type_effectiveness_df = pd.DataFrame.from_dict(type_effectiveness)
|
|
#NOTE: from a practical point of view, since type_effectiveness is accessed many times
|
|
#in the main code, using pandas DataFrame is not efficient. I decided to keep using dictionaries
|
|
#for the type effectiveness. The justification arises especially if we consider
|
|
#how long data generation will take. |