Skip to content

Commit

Permalink
Move type chart into data
Browse files Browse the repository at this point in the history
  • Loading branch information
hsahovic committed Oct 31, 2019
1 parent a0bddd6 commit 3319ab1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
16 changes: 16 additions & 0 deletions src/poke_env/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import json
import os

from typing import Any
from typing import Dict

from poke_env.utils import compute_type_chart


TYPE_CHART_PATH: str = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "data", "typeChart.json"
Expand All @@ -26,3 +29,16 @@
os.path.join(os.path.dirname(os.path.realpath(__file__)), "data", "moves.json")
) as moves:
MOVES = json.load(moves)

TYPE_CHART: Dict[Any, Dict[Any, float]] = compute_type_chart(TYPE_CHART_PATH)
"""
A dictionnary representing the Pokemon type chart.
Each key is a string representing a type (corresponding to `Type` names), and each value
is a dictionnary whose keys are string representation of types, and whose values are
floats.
TYPE_CHART[type_1][type_2] corresponds to the damage multiplier of an attack of type_1
on a Pokemon of type_2. This dictionnary isncomputed using the `compute_type_chart`
function.
"""
4 changes: 2 additions & 2 deletions src/poke_env/environment/pokemon_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from enum import Enum
from enum import unique
from typing import Optional
from ..utils import TYPE_CHART
from ..data import TYPE_CHART


@unique
Expand Down Expand Up @@ -42,7 +42,7 @@ class PokemonType(Enum):
def __str__(self) -> str:
return f"{self.name} (pokemon type) object"

def damage_multiplier( # pyre-ignore
def damage_multiplier(
self, type_1: "PokemonType", type_2: Optional["PokemonType"] = None
) -> float:
"""Computes the damage multiplier from this type on a pokemon with types `type_1`
Expand Down
19 changes: 2 additions & 17 deletions src/poke_env/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import json

from poke_env.data import TYPE_CHART_PATH
from typing import Dict


def compute_type_chart() -> Dict[str, Dict[str, float]]:
def compute_type_chart(chart_path: str) -> Dict[str, Dict[str, float]]:
"""Returns the pokemon type_chart.
Returns a dictionnary representing the Pokemon type chart, loaded from a json file
Expand All @@ -17,7 +16,7 @@ def compute_type_chart() -> Dict[str, Dict[str, float]]:
:return: The pokemon type chart
:rtype: Dict[str, Dict[str, float]]
"""
with open(TYPE_CHART_PATH) as chart:
with open(chart_path) as chart:
json_chart = json.load(chart)

types = [str(entry["name"]).upper() for entry in json_chart]
Expand Down Expand Up @@ -50,17 +49,3 @@ def to_id_str(name: str) -> str:
name = name.replace(c, "")

return name


TYPE_CHART: Dict["PokemonType", Dict["PokemonType", float]] = compute_type_chart()
"""
A dictionnary representing the Pokemon type chart.
Each key is a string representing a type (corresponding to `Type` names), and each value
is a dictionnary whose keys are string representation of types, and whose values are
floats.
TYPE_CHART[type_1][type_2] corresponds to the damage multiplier of an attack of type_1
on a Pokemon of type_2. This dictionnary isncomputed using the `compute_type_chart`
function.
"""

0 comments on commit 3319ab1

Please sign in to comment.