Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make open team sheets data populate the battle object #660

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
89c8259
committing after lots of testing in personal project
cameronangliss Dec 8, 2024
27e1445
Merge branch 'master' of github.com:cameronangliss/poke-env into open…
cameronangliss Dec 10, 2024
b6d55c9
handling nicknames
cameronangliss Dec 15, 2024
2a08edc
just do the neutral gender handling manually
cameronangliss Dec 15, 2024
0572dff
remove dead test
cameronangliss Dec 15, 2024
a648666
open sheets is only for vgc
cameronangliss Dec 15, 2024
42a50a3
needs socket connection to send open sheets confirmation
cameronangliss Dec 15, 2024
5c8818c
better assert
cameronangliss Dec 15, 2024
1a78add
even better
cameronangliss Dec 15, 2024
f76fb73
handle the mewtwo issue
cameronangliss Dec 15, 2024
2178ac2
bugfix
cameronangliss Dec 15, 2024
3b1d398
Merge branch 'master' of github.com:cameronangliss/poke-env into open…
cameronangliss Jan 4, 2025
fae869b
Merge branch 'master' of github.com:cameronangliss/poke-env into open…
cameronangliss Feb 15, 2025
9a86911
mew/mewtwo actually fixed now
cameronangliss Feb 16, 2025
c842258
kabuto covered
cameronangliss Feb 16, 2025
2ff61f3
cover this totally with regex
cameronangliss Feb 16, 2025
6e68fab
this should speed things up a bit
cameronangliss Feb 16, 2025
5d0becc
bugfix
cameronangliss Feb 17, 2025
eab7037
more readable
cameronangliss Feb 17, 2025
91a7af0
Kommo-o fix
cameronangliss Feb 17, 2025
76c9327
Merge branch 'master' of github.com:cameronangliss/poke-env into open…
cameronangliss Feb 22, 2025
9e3a69e
fix forfeit behavior
cameronangliss Feb 23, 2025
5ac5300
Merge branch '688-and-683-conflict-fix' of github.com:cameronangliss/…
cameronangliss Feb 23, 2025
898ec1a
use code that already exists
cameronangliss Mar 7, 2025
84ceee4
cleanup
cameronangliss Mar 7, 2025
11f49ce
cleanup
cameronangliss Mar 7, 2025
8807243
debug
cameronangliss Mar 7, 2025
5669a8c
more readable
cameronangliss Mar 7, 2025
202ea0d
cleaning/debugging
cameronangliss Mar 7, 2025
c9757c1
resetting a bunch of changes and pulling in fixes
cameronangliss Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
even better
cameronangliss committed Dec 15, 2024
commit 1a78add43e2ea738927c15562d265f57310ad082
4 changes: 3 additions & 1 deletion src/poke_env/environment/abstract_battle.py
Original file line number Diff line number Diff line change
@@ -229,16 +229,18 @@
for i, p in enumerate(team.values())
if p.base_species in to_id_str(details.split(",")[0])
]
assert len(matches) < 2, f"matches for {details}: {matches}"
assert (
len(matches) < 2
), f"matches for {details}: {[p.species for i, p in enumerate(team.values()) if i in matches]}"
if identifier not in team and matches:
i = matches[0]
items = list(team.items())
items[i] = (identifier, items[i][1])
items[i][1]._name = identifier[4:]
if is_mine or force_self_team:
self._team = dict(items)

Check warning on line 241 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L236-L241

Added lines #L236 - L241 were not covered by tests
else:
self._opponent_team = dict(items)

Check warning on line 243 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L243

Added line #L243 was not covered by tests
team = self._team if is_mine or force_self_team else self._opponent_team

if identifier in team:
@@ -976,40 +978,40 @@
def _update_team_from_open_sheets(
self, message_dict: Dict[str, List[str]], role: str
):
teampreview_team = (

Check warning on line 981 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L981

Added line #L981 was not covered by tests
self.teampreview_team
if role == self.player_role
else self.teampreview_opponent_team
)
team = self._team if role == self.player_role else self._opponent_team
for mon in teampreview_team:
identifier = f"{role}: {mon.base_species.capitalize()}"
if identifier not in team:
team[identifier] = Pokemon(

Check warning on line 990 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L986-L990

Added lines #L986 - L990 were not covered by tests
mon._data.gen,
species=mon.species,
name=mon._data.pokedex[mon.species]["name"],
details=mon._last_details,
)
pokemon = team[identifier]
pokemon_msg = [

Check warning on line 997 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L996-L997

Added lines #L996 - L997 were not covered by tests
msg
for name, msg in message_dict.items()
if mon.base_species in to_id_str(name)
][0]
pokemon._item = to_id_str(pokemon_msg[1])
pokemon._ability = to_id_str(pokemon_msg[2])
pokemon._moves = {

Check warning on line 1004 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1002-L1004

Added lines #L1002 - L1004 were not covered by tests
to_id_str(name): Move(to_id_str(name), self.gen)
for name in pokemon_msg[3].split(",")
}
pokemon._gender = (

Check warning on line 1008 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1008

Added line #L1008 was not covered by tests
PokemonGender.from_request_details(pokemon_msg[6])
if pokemon_msg[6]
else PokemonGender.NEUTRAL
)
pokemon._level = int(pokemon_msg[9])
pokemon._terastallized_type = PokemonType.from_name(

Check warning on line 1014 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1013-L1014

Added lines #L1013 - L1014 were not covered by tests
pokemon_msg[10].split(",")[-1]
)


Unchanged files with check annotations Beta

await self.ps_client.send_message("/timer on", battle.battle_tag)
if hasattr(self.ps_client, "websocket") and "vgc" in self.format:
if self.accept_open_team_sheet:
await self.ps_client.send_message(

Check warning on line 238 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L237-L238

Added lines #L237 - L238 were not covered by tests
"/acceptopenteamsheets", room=battle_tag
)
else:
await self.ps_client.send_message(

Check warning on line 242 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L242

Added line #L242 was not covered by tests
"/rejectopenteamsheets", room=battle_tag
)
battle.move_on_next_request = False
elif split_message[1] == "showteam":
# only need open sheets data for opponent
if split_message[2] == battle.opponent_role:
split_pokemon_messages = [

Check warning on line 295 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L294-L295

Added lines #L294 - L295 were not covered by tests
m.split("|") for m in "|".join(split_message[3:]).split("]")
]
message_dict = {m[0]: m[1:] for m in split_pokemon_messages}
role = split_message[2]
battle._update_team_from_open_sheets(message_dict, role)

Check warning on line 300 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L298-L300

Added lines #L298 - L300 were not covered by tests
# only handle battle request after all open sheets are processed
if (

Check warning on line 302 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L302

Added line #L302 was not covered by tests
battle.team
and battle.opponent_team
and all(
]
)
):
await self._handle_battle_request(

Check warning on line 313 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L313

Added line #L313 was not covered by tests
battle, from_teampreview_request=True
)
elif split_message[1] == "win" or split_message[1] == "tie":
elif split_message[1] == "teampreview":
battle.parse_message(split_message)
# wait for open sheets to be processed before handling battle request
if not self.accept_open_team_sheet:
await self._handle_battle_request(

Check warning on line 400 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L399-L400

Added lines #L399 - L400 were not covered by tests
battle, from_teampreview_request=True
)
elif split_message[1] == "bigerror":