Skip to content

Commit 0494285

Browse files
style: pre-commit fixes
1 parent 1fa2984 commit 0494285

8 files changed

Lines changed: 43 additions & 28 deletions

File tree

src/p2lab/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
p2lab: a package for genetic optimisation of pokemon teams
55
"""
66

7-
87
from __future__ import annotations
98

109
__version__ = "0.1.0"

src/p2lab/_compat/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
p2lab: a package for genetic optimisation of pokemon teams
55
"""
66

7-
87
from __future__ import annotations

src/p2lab/_compat/typing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
p2lab: a package for genetic optimisation of pokemon teams
55
"""
66

7-
87
from __future__ import annotations
98

109
from typing import Literal, Protocol, runtime_checkable

src/p2lab/genetic/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def crossover(
6161
team2_pokemon = team2_old.pokemon
6262

6363
# Randomly pick locus
64-
locus = random.sample(range(0, num_pokemon), k=1)[0]
64+
locus = random.sample(range(num_pokemon), k=1)[0]
6565

6666
# Check that the sliciing here works but you get the idea
6767
team1_new_pokemeon = team1_pokemon[0:locus] + team2_pokemon[locus:num_pokemon]

src/p2lab/pokemon/pokefactory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
This is directly inspired by poke-env's diagostic_tools folder
66
"""
7+
78
from __future__ import annotations
89

910
import numpy as np

target_api.md

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ running genetic algorithms to optimize teams.
77
Thank you to github copilot for helping me write this document lmao
88

99
```python3
10-
11-
team = generate_team(format='gen8randombattle', seed=1234)
10+
team = generate_team(format="gen8randombattle", seed=1234)
1211

1312
# a team object contains a list of 6 pokemon objects with their moves, items, etc.
1413
# it's also tracking the (normalised) number of wins/losses/ties for this team.
@@ -30,12 +29,12 @@ team = generate_team(format='gen8randombattle', seed=1234)
3029
# here's an idealised Bot class that uses these same env variables to run a showdown bot, but more cleanly:
3130
bot_1 = Bot(
3231
team,
33-
strategy='safest',
34-
websocket_uri='sim.psim.us:8000',
35-
user='whimsicaldreams',
36-
password='password',
37-
bot_mode='CHALLENGE_USER',
38-
format='gen3ou',
32+
strategy="safest",
33+
websocket_uri="sim.psim.us:8000",
34+
user="whimsicaldreams",
35+
password="password",
36+
bot_mode="CHALLENGE_USER",
37+
format="gen3ou",
3938
num_battles=1,
4039
save_replay=False,
4140
)
@@ -47,25 +46,27 @@ bot_1 = Bot(
4746
# now we can run a battle between two bots:
4847
bot_2 = Bot(
4948
team,
50-
strategy='safest',
51-
websocket_uri='sim.psim.us:8000',
52-
user='melonchomper',
53-
password='password',
54-
bot_mode='CHALLENGE_USER', # this would need to be ACCEPT_CHALLENGE
55-
format='gen3ou',
49+
strategy="safest",
50+
websocket_uri="sim.psim.us:8000",
51+
user="melonchomper",
52+
password="password",
53+
bot_mode="CHALLENGE_USER", # this would need to be ACCEPT_CHALLENGE
54+
format="gen3ou",
5655
num_battles=1,
5756
save_replay=False,
5857
)
5958

6059
# from a little google searching, it looks like we can run these bots in parallel using asyncio:
6160

61+
6262
async def run_battle(bot_1, bot_2):
6363
# individually run the showdown bots at the same time, and wait for the results
6464
await asyncio.gather(bot_1.challenge(bot_2), bot_2.accept(bot_1))
6565
# parse the results
6666
# update the win/loss/tie counts for each team
6767
...
6868

69+
6970
run_battle(bot_1, bot_2)
7071

7172
# within this function, we'll need to:
@@ -74,7 +75,20 @@ run_battle(bot_1, bot_2)
7475
# - update the win/loss/tie counts for each team
7576

7677
# here's a more generic example, where we specify a number of battles for each team, and then run them all:
77-
bots = {f'bot{i}':Bot(team, strategy='safest', websocket_uri='sim.psim.us:8000', user=f'bot{i}', password='password', bot_mode='CHALLENGE_USER' if i % 2 == 0 else 'ACCEPT_CHALLENGE', format='gen3ou', num_battles=10, save_replay=False) for i in range(10)}
78+
bots = {
79+
f"bot{i}": Bot(
80+
team,
81+
strategy="safest",
82+
websocket_uri="sim.psim.us:8000",
83+
user=f"bot{i}",
84+
password="password",
85+
bot_mode="CHALLENGE_USER" if i % 2 == 0 else "ACCEPT_CHALLENGE",
86+
format="gen3ou",
87+
num_battles=10,
88+
save_replay=False,
89+
)
90+
for i in range(10)
91+
}
7892

7993
# num_battles = 10 would mean that bot would challenge the same bot 10 times, so we can make every bot fight every other bot 10 times
8094

@@ -85,14 +99,18 @@ for bot_1, bot_2 in itertools.combinations(bots.values(), 2):
8599
if bot_1 != bot_2:
86100
try:
87101
# make sure bot_1 is the challenger and bot_2 is the acceptor
88-
bot_1.bot_mode = 'CHALLENGE_USER'
89-
bot_2.bot_mode = 'ACCEPT_CHALLENGE'
102+
bot_1.bot_mode = "CHALLENGE_USER"
103+
bot_2.bot_mode = "ACCEPT_CHALLENGE"
90104

91105
# check if either bot is currently in a battle
92106
if bot_1.in_battle or bot_2.in_battle:
93-
print(f'Bot {bot_1} or {bot_2} is currently in a battle, waiting for them to finish...')
107+
print(
108+
f"Bot {bot_1} or {bot_2} is currently in a battle, waiting for them to finish..."
109+
)
94110
while bot_1.in_battle or bot_2.in_battle:
95-
await asyncio.sleep(1) # hopefully this will wait for the battle to finish
111+
await asyncio.sleep(
112+
1
113+
) # hopefully this will wait for the battle to finish
96114

97115
# run the battle
98116
bot_1.in_battle = True
@@ -105,7 +123,7 @@ for bot_1, bot_2 in itertools.combinations(bots.values(), 2):
105123

106124
except Exception as e:
107125
print(e)
108-
print(f'Error running battle between {bot_1} and {bot_2}')
126+
print(f"Error running battle between {bot_1} and {bot_2}")
109127

110128
# ensure we're only here once every bot has fought every other bot
111129
while any(bot.in_battle for bot in bots.values()):

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from p2lab.pokemon import pokefactory, premade, teams
66

77

8-
@pytest.fixture()
8+
@pytest.fixture
99
def default_factory():
1010
return pokefactory.PokeFactory()
1111

1212

13-
@pytest.fixture()
13+
@pytest.fixture
1414
def gen_1_pool():
1515
return teams.import_pool(premade.gen_1_pokemon())

tests/test_package.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ def test_version():
1010

1111
@runtime_checkable
1212
class HasQuack(Protocol):
13-
def quack(self) -> str:
14-
...
13+
def quack(self) -> str: ...
1514

1615

1716
class Duck:

0 commit comments

Comments
 (0)