Skip to content

Commit

Permalink
Merge pull request #41 from alan-turing-institute/patch/poke-env
Browse files Browse the repository at this point in the history
Patch/poke env - fixes the NoneType error when battling
  • Loading branch information
Aoife Hughes authored Jun 20, 2023
2 parents 66fc2bf + 409e9a2 commit b22a754
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 17 additions & 5 deletions src/p2lab/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import argparse
import asyncio

import numpy as np
Expand Down Expand Up @@ -44,13 +45,24 @@ async def main_loop(num_teams, team_size, num_generations, unique):
print(f"Fitness: {fitness}")


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("-g", help="Number of generations", type=int, default=10)
parser.add_argument("-t", help="Team size", type=int, default=2)
parser.add_argument("-n", help="Number of teams", type=int, default=30)
parser.add_argument("-s", help="Random seed", type=int, default=None)
parser.add_argument("-u", help="Unique teams", default=True)
return vars(parser.parse_args())


def main():
num_teams = 30
team_size = 2
num_generations = 10
unique = True
args = parse_args()

if args["s"] is not None:
np.random.seed(args["s"])

asyncio.get_event_loop().run_until_complete(
main_loop(num_teams, team_size, num_generations, unique)
main_loop(args["n"], args["t"], args["g"], args["u"])
)


Expand Down
6 changes: 4 additions & 2 deletions src/p2lab/pokemon/teams.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from copy import deepcopy

__all__ = (
"Team",
"generate_pool",
Expand All @@ -18,7 +20,7 @@

class Team:
def __init__(self, pokemon) -> None:
self.pokemon = np.array(pokemon)
self.pokemon = np.array(deepcopy(pokemon))
self.first_name = self.pokemon[0].formatted.split("|")[0]

def to_packed_str(self) -> str:
Expand Down Expand Up @@ -106,7 +108,7 @@ def generate_teams(pool, num_teams, team_size=6, unique=False):
msg = f"Cannot generate {num_teams} teams of size {team_size} from pool of size {len(pool)}"
raise Exception(msg)
indicies = np.random.choice(
len(pool), size=num_teams * team_size, replace=False
len(pool), size=(num_teams, team_size), replace=False
)
teams = np.array(pool)[indicies].reshape(num_teams, team_size)
return [Team(team) for team in teams]
Expand Down

0 comments on commit b22a754

Please sign in to comment.