From 5dc11445f283f9610eca2c9695659f5b0c33b11c Mon Sep 17 00:00:00 2001 From: thatguy11325 <148832074+thatguy11325@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:43:52 -0400 Subject: [PATCH] fix end of game crash --- pokemonred_puffer/environment.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pokemonred_puffer/environment.py b/pokemonred_puffer/environment.py index 8264ca3..968e834 100644 --- a/pokemonred_puffer/environment.py +++ b/pokemonred_puffer/environment.py @@ -1496,6 +1496,7 @@ def get_game_coords(self): def get_max_steps(self): return max( + 0, self.max_steps, self.max_steps * (len(self.required_events) + len(self.required_items)) @@ -1602,10 +1603,11 @@ def update_max_op_level(self): self.read_m(f"wEnemyMon{i+1}Level") for i in range(self.read_m("wEnemyPartyCount")) ] + + [0] ) # - opp_base_level ) - self.max_opponent_level = max(self.max_opponent_level, opponent_level) + self.max_opponent_level = max(0, self.max_opponent_level, opponent_level) return self.max_opponent_level def update_health(self): @@ -1688,7 +1690,7 @@ def read_hp_fraction(self): def update_map_progress(self): map_idx = self.read_m(0xD35E) - self.max_map_progress = max(self.max_map_progress, self.get_map_progress(map_idx)) + self.max_map_progress = max(0, self.max_map_progress, self.get_map_progress(map_idx)) def get_map_progress(self, map_idx): if map_idx in self.essential_map_locations.keys(): @@ -1707,7 +1709,7 @@ def get_hm_count(self) -> int: def get_levels_reward(self): # Level reward party_levels = self.read_party() - self.max_level_sum = max(self.max_level_sum, sum(party_levels)) + self.max_level_sum = max(0, self.max_level_sum, sum(party_levels)) if self.max_level_sum < 30: level_reward = 1 * self.max_level_sum else: