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
Kommo-o fix
cameronangliss committed Feb 17, 2025
commit 91a7af08b984020a8dacccd520996036721b94d0
4 changes: 4 additions & 0 deletions src/poke_env/environment/abstract_battle.py
Original file line number Diff line number Diff line change
@@ -234,20 +234,24 @@
]
matches = [
i for i, p in enumerate(team.values()) if p.base_species in split_details
] or [
i
for i, p in enumerate(team.values())
if p.base_species in to_id_str(details)
]
assert len(matches) < 2
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 249 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L244-L249

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

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

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L251

Added line #L251 was not covered by tests
team = self._team if is_mine or force_self_team else self._opponent_team
if identifier in team:
return team[identifier]

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

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L254

Added line #L254 was not covered by tests

if self._team_size and len(team) >= self._team_size[player_role]:
raise ValueError(
@@ -998,40 +1002,40 @@
def _update_team_from_open_sheets(
self, message_dict: Dict[str, List[str]], role: str
):
teampreview_team = (

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

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1005

Added line #L1005 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 1014 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

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

Added lines #L1010 - L1014 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 1021 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1020-L1021

Added lines #L1020 - L1021 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 1028 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1026-L1028

Added lines #L1026 - L1028 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 1032 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1032

Added line #L1032 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 1038 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1037-L1038

Added lines #L1037 - L1038 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 246 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L245-L246

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

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

Codecov / codecov/patch

src/poke_env/player/player.py#L250

Added line #L250 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 303 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L302-L303

Added lines #L302 - L303 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 308 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L306-L308

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

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

Codecov / codecov/patch

src/poke_env/player/player.py#L310

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

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

Codecov / codecov/patch

src/poke_env/player/player.py#L321

Added line #L321 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 408 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L407-L408

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