From 22c9d23928bc4c944ff19297980eebd040eb7c7e Mon Sep 17 00:00:00 2001 From: thatguy11325 <148832074+thatguy11325@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:31:39 -0500 Subject: [PATCH] restore cut coords to its former glory --- config.yaml | 1 + pokemonred_puffer/environment.py | 21 ++++++++++----------- pokemonred_puffer/rewards/baseline.py | 5 ++++- sweep-config.yaml | 5 +++++ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/config.yaml b/config.yaml index 2b9921f..94fb465 100644 --- a/config.yaml +++ b/config.yaml @@ -328,6 +328,7 @@ rewards: explore_signs: 0.015025767686371013 explore_warps: 0.010135211705238394 hm_count: 7.5 + invalid_cut_coords: 0.0001 level: 1.05 moves_obtained: 4.0 pokecenter_heal: 0.47 diff --git a/pokemonred_puffer/environment.py b/pokemonred_puffer/environment.py index 06d3ed9..e66eed9 100644 --- a/pokemonred_puffer/environment.py +++ b/pokemonred_puffer/environment.py @@ -270,8 +270,8 @@ def register_hooks(self): ) self.pyboy.hook_register(None, "HandleBlackOut", self.blackout_hook, None) self.pyboy.hook_register(None, "SetLastBlackoutMap.done", self.blackout_update_hook, None) - # self.pyboy.hook_register(None, "UsedCut.nothingToCut", self.cut_hook, context=True) - # self.pyboy.hook_register(None, "UsedCut.canCut", self.cut_hook, context=False) + self.pyboy.hook_register(None, "UsedCut.nothingToCut", self.cut_hook, context=True) + self.pyboy.hook_register(None, "UsedCut.canCut", self.cut_hook, context=False) if self.disable_wild_encounters: self.setup_disable_wild_encounters() self.pyboy.hook_register(None, "AnimateHealingMachine", self.pokecenter_heal_hook, None) @@ -420,8 +420,8 @@ def init_mem(self): ] } - self.cut_coords = {} - self.cut_tiles = {} + self.valid_cut_coords = {} + self.invalid_cut_coords = {} self.seen_hidden_objs = {} self.seen_signs = {} @@ -1348,7 +1348,7 @@ def update_warps_hook(self, *args, **kwargs): if key[-1] != 0xFF: self.seen_warps[key] = 1 - def cut_hook(self, context): + def cut_hook(self, context: bool): player_direction = self.pyboy.memory[ self.pyboy.symbol_lookup("wSpritePlayerStateData1FacingDirection")[1] ] @@ -1367,14 +1367,13 @@ def cut_hook(self, context): ] if context: if wTileInFrontOfPlayer in [0x3D, 0x50]: - self.cut_coords[coords] = 10 + self.valid_cut_coords[coords] = 1 else: - self.cut_coords[coords] = 0.001 + self.invalid_cut_coords[coords] = 1 else: - self.cut_coords[coords] = 0.001 + self.invalid_cut_coords[coords] = 1 self.cut_explore_map[local_to_global(y, x, map_id)] = 1 - self.cut_tiles[wTileInFrontOfPlayer] = 1 def disable_wild_encounter_hook(self, *args, **kwargs): if ( @@ -1428,8 +1427,8 @@ def agent_stats(self, action): "taught_cut": int(self.check_if_party_has_hm(TmHmMoves.CUT.value)), "taught_surf": int(self.check_if_party_has_hm(TmHmMoves.SURF.value)), "taught_strength": int(self.check_if_party_has_hm(TmHmMoves.STRENGTH.value)), - # "cut_coords": sum(self.cut_coords.values()), - # "cut_tiles": len(self.cut_tiles), + "valid_cut_coords": len(self.valid_cut_coords), + "invalid_cut_coords": len(self.invalid_cut_coords), "menu": { "start_menu": self.seen_start_menu, "pokemon_menu": self.seen_pokemon_menu, diff --git a/pokemonred_puffer/rewards/baseline.py b/pokemonred_puffer/rewards/baseline.py index 553daba..0820a85 100644 --- a/pokemonred_puffer/rewards/baseline.py +++ b/pokemonred_puffer/rewards/baseline.py @@ -377,7 +377,10 @@ def get_game_state_reward(self): "hm_count": self.reward_config["hm_count"] * self.get_hm_count(), "level": self.reward_config["level"] * self.get_levels_reward(), "badges": self.reward_config["badges"] * self.get_badges(), - "cut_coords": self.reward_config["cut_coords"] * sum(self.cut_coords.values()), + "valid_cut_coords": self.reward_config["valid_cut_coords"] + * len(self.cut_coords.values()), + "invalid_cut_coords": self.reward_config["invalid_cut_coords"] + * len(self.cut_coords.values()), "cut_tiles": self.reward_config["cut_tiles"] * sum(self.cut_tiles.values()), "start_menu": self.reward_config["start_menu"] * self.seen_start_menu, "pokemon_menu": self.reward_config["pokemon_menu"] * self.seen_pokemon_menu, diff --git a/sweep-config.yaml b/sweep-config.yaml index 982674b..2815dbd 100644 --- a/sweep-config.yaml +++ b/sweep-config.yaml @@ -67,6 +67,11 @@ rewards: min: 1.0e-3 max: 10.0 scale: 1.0 + invalid_cut_coords: + carbs.utils.LinearSpace: + min: 1.0e-5 + max: 1.0e-3 + scale: 5e-5 moves_obtained: carbs.utils.LinearSpace: min: 1.0e-3