Files
ppse/HW3/game_data.py
T

48 lines
1.6 KiB
Python

import json
import random
#exclude 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]
#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)
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 (compatible) random moves
selected_moves = [random.choice(compatible_moves) for _ in range(2)]
pokemons_dict[p['name']]['moves'] = selected_moves
available_pokemon_names = list(pokemons_dict.keys())
available_starters = ['bulbasaur', 'charmander', 'squirtle']
#type effectiveness
type_effectiveness = []
with open('type_effectiveness.json', 'r') as file:
for line in file:
type_effectiveness.append(json.loads(line))