Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: alan-turing-institute/p2lab-pokemon
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bb9ce0e437952f7a928f7fc1e448c02e5a15dacc
Choose a base ref
..
head repository: alan-turing-institute/p2lab-pokemon
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4ca40439740b1f0428f7add51bf4ea9b07c343b2
Choose a head ref
Showing with 13 additions and 13 deletions.
  1. +3 −3 .pre-commit-config.yaml
  2. +4 −4 src/p2lab/genetic/operations.py
  3. +6 −6 src/p2lab/pokemon/pokefactory.py
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -32,20 +32,20 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.1"
rev: "v3.0.2"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: [--prose-wrap=always]

- repo: https://github.com/asottile/blacken-docs
rev: "1.15.0"
rev: "1.16.0"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.3.0]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.284"
rev: "v0.0.285"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
8 changes: 4 additions & 4 deletions src/p2lab/genetic/operations.py
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ def locus_swap(
team2: list[str],
num_pokemon: int,
allow_all: bool,
locus: int | None = None,
locus: int = None,
) -> tuple(list[str], list[str]):
"""
A method of performing the crossover. Pick a 'locus' point: this
@@ -194,7 +194,7 @@ def slot_swap(
team2: list[str],
num_pokemon: int,
allow_all: bool,
k: int | None = None,
k: int = None,
) -> tuple(list[str], list[str]):
"""
A method of performing the crossover. This method randomly
@@ -294,7 +294,7 @@ def mutate(
mutate_prob: float | np.ndarray,
pokemon_population: list[str],
allow_all: bool,
k: int | None = None,
k: int = None,
):
"""
A mutation operation. At random, k members of a team are swapped with k
@@ -362,7 +362,7 @@ def fitness_mutate(
fitness: np.array,
pokemon_population: list[str],
allow_all: bool,
k: int | None = None,
k: int = None,
):
"""
A mutation operation. Does the same as regular mutation, except that
12 changes: 6 additions & 6 deletions src/p2lab/pokemon/pokefactory.py
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ def __init__(self, gen=1, drop_forms=True):
self.dex2mon = {
int(self.dex.pokedex[m]["num"]): m
for m in self.dex.pokedex
if "forme" not in self.dex.pokedex[m]
if "forme" not in self.dex.pokedex[m].keys()
}
else:
self.dex2mon = {
@@ -68,24 +68,24 @@ def make_pokemon(self, dexnum=None, generate_moveset=False, **kwargs):
raise ValueError(msg)
if dexnum is None:
dexnum = np.random.choice(list(self.dex2mon.keys()))
if generate_moveset or "moves" not in kwargs:
if generate_moveset or "moves" not in kwargs.keys():
poss_moves = self.get_allowed_moves(dexnum)
moves = (
np.random.choice(poss_moves, 4, replace=False)
if len(poss_moves) > 3
else poss_moves
)
kwargs["moves"] = moves
if "ivs" not in kwargs:
if "ivs" not in kwargs.keys():
ivs = [31] * 6
kwargs["ivs"] = ivs
if "evs" not in kwargs:
if "evs" not in kwargs.keys():
# TODO: implement EV generation better
evs = [510 // 6] * 6
kwargs["evs"] = evs
if "level" not in kwargs:
if "level" not in kwargs.keys():
kwargs["level"] = 100
if "ability" not in kwargs:
if "ability" not in kwargs.keys():
kwargs["ability"] = np.random.choice(
list(self.get_allowed_abilities(dexnum).values())
)