diff --git a/examples/reinforcement_learning.py b/examples/reinforcement_learning.py index e7d9362b9..5d3d96ccf 100644 --- a/examples/reinforcement_learning.py +++ b/examples/reinforcement_learning.py @@ -51,7 +51,7 @@ def create_single_agent_env(cls, config: Dict[str, Any]) -> SingleAgentWrapper: open_timeout=None, strict=False, ) - opponent = RandomPlayer() + opponent = RandomPlayer(start_listening=False) return SingleAgentWrapper(env, opponent) def calc_reward(self, battle) -> float: diff --git a/src/poke_env/environment/env.py b/src/poke_env/environment/env.py index f092bdaaa..0a637abf8 100644 --- a/src/poke_env/environment/env.py +++ b/src/poke_env/environment/env.py @@ -18,8 +18,8 @@ from poke_env.concurrency import POKE_LOOP, create_in_poke_loop from poke_env.player.battle_order import ( BattleOrder, - DefaultBattleOrder, ForfeitBattleOrder, + _EmptyBattleOrder, ) from poke_env.player.player import Player from poke_env.ps_client import AccountConfiguration @@ -313,7 +313,7 @@ def reset( self.agent1.order_queue.put(ForfeitBattleOrder()) if self.agent2_to_move: self.agent2_to_move = False - self.agent2.order_queue.put(DefaultBattleOrder()) + self.agent2.order_queue.put(_EmptyBattleOrder()) else: assert self.agent2_to_move self.agent2_to_move = False @@ -384,7 +384,7 @@ def close(self, force: bool = True, wait: bool = True): self.agent1.order_queue.put(ForfeitBattleOrder()) if self.agent2_to_move: self.agent2_to_move = False - self.agent2.order_queue.put(DefaultBattleOrder()) + self.agent2.order_queue.put(_EmptyBattleOrder()) else: assert self.agent2_to_move self.agent2_to_move = False diff --git a/src/poke_env/player/battle_order.py b/src/poke_env/player/battle_order.py index 16bcce9ba..4129ff281 100644 --- a/src/poke_env/player/battle_order.py +++ b/src/poke_env/player/battle_order.py @@ -24,6 +24,12 @@ def message(self) -> str: return "/forfeit" +class _EmptyBattleOrder(BattleOrder): + @property + def message(self) -> str: + return "" + + @dataclass class SingleBattleOrder(BattleOrder): order: Union[Move, Pokemon, str] diff --git a/src/poke_env/player/player.py b/src/poke_env/player/player.py index d307c742a..997ec46e6 100644 --- a/src/poke_env/player/player.py +++ b/src/poke_env/player/player.py @@ -417,7 +417,8 @@ async def _handle_battle_request( if isinstance(choice, Awaitable): choice = await choice message = choice.message - await self.ps_client.send_message(message, battle.battle_tag) + if message: + await self.ps_client.send_message(message, battle.battle_tag) async def _handle_challenge_request(self, split_message: List[str]): """Handles an individual challenge."""