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
Merge branch 'master' of github.com:cameronangliss/poke-env into open…
…-sheets-fill-battle-obj
cameronangliss committed Feb 22, 2025
commit 76c93275efb025fc0b08456357e1629d68885c39
15 changes: 11 additions & 4 deletions src/poke_env/environment/abstract_battle.py
Original file line number Diff line number Diff line change
@@ -225,8 +225,11 @@

player_role = identifier[:2]
name = identifier[3:].strip()
is_mine = player_role == self._player_role
team = self._team if is_mine or force_self_team else self._opponent_team
team = (
self._team
if player_role == self._player_role or force_self_team
else self._opponent_team
)

# if the pokemon has a nickname, this ensures we recognize it
split_details = [
@@ -241,17 +244,21 @@
]
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:
if player_role == self._player_role or force_self_team:
self._team = dict(items)

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

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L247-L252

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

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
team = self._team if is_mine or force_self_team else self._opponent_team
team = (
self._team
if player_role == self._player_role or force_self_team
else self._opponent_team
)
if identifier in team:
return team[identifier]

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

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L261

Added line #L261 was not covered by tests

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

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

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1014

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

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1019-L1023

Added lines #L1019 - L1023 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 1030 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1029-L1030

Added lines #L1029 - L1030 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 1037 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

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

Added lines #L1035 - L1037 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 1041 in src/poke_env/environment/abstract_battle.py

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1041

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

Codecov / codecov/patch

src/poke_env/environment/abstract_battle.py#L1046-L1047

Added lines #L1046 - L1047 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 248 in src/poke_env/player/player.py

Codecov / codecov/patch

src/poke_env/player/player.py#L247-L248

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

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

Codecov / codecov/patch

src/poke_env/player/player.py#L252

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

Codecov / codecov/patch

src/poke_env/player/player.py#L304-L305

Added lines #L304 - L305 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 310 in src/poke_env/player/player.py

Codecov / codecov/patch

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

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

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

Codecov / codecov/patch

src/poke_env/player/player.py#L312

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

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

Codecov / codecov/patch

src/poke_env/player/player.py#L323

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

Codecov / codecov/patch

src/poke_env/player/player.py#L424-L425

Added lines #L424 - L425 were not covered by tests
battle, from_teampreview_request=True
)
elif split_message[1] == "bigerror":
You are viewing a condensed version of this merge commit. You can view the full changes here.