From 7ef770f44ede70d2b8fa70ea3c6eb43a8cb5a01c Mon Sep 17 00:00:00 2001 From: kywch Date: Sun, 17 Mar 2024 10:22:07 -0700 Subject: [PATCH 1/3] fixed local_to_global index error --- pokemonred_puffer/environment.py | 2 +- pokemonred_puffer/global_map.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pokemonred_puffer/environment.py b/pokemonred_puffer/environment.py index e26d064..7fa08ae 100644 --- a/pokemonred_puffer/environment.py +++ b/pokemonred_puffer/environment.py @@ -818,7 +818,7 @@ def get_explore_map(self): explore_map = np.zeros(GLOBAL_MAP_SHAPE) for (x, y, map_n), v in self.seen_coords.items(): gy, gx = local_to_global(y, x, map_n) - if gy >= explore_map.shape[0] or gx >= explore_map.shape[1]: + if gy >= explore_map.shape[0] or gy < 0 or gx >= explore_map.shape[1] or gx < 0: print(f"coord out of bounds! global: ({gx}, {gy}) game: ({x}, {y}, {map_n})") else: explore_map[gy, gx] = v diff --git a/pokemonred_puffer/global_map.py b/pokemonred_puffer/global_map.py index a8b9118..140cbac 100644 --- a/pokemonred_puffer/global_map.py +++ b/pokemonred_puffer/global_map.py @@ -20,3 +20,6 @@ def local_to_global(r: int, c: int, map_n: int): except KeyError: print(f"Map id {map_n} not found in map_data.json.") return r + 0, c + 0 + except IndexError: + print(f"Coord {map_x}, {map_y} out of bounds for map id {map_n}.") + return -1, -1 From 14f9169b32bfabc0993799f75404655401352f9a Mon Sep 17 00:00:00 2001 From: kywch Date: Wed, 20 Mar 2024 10:15:21 -0700 Subject: [PATCH 2/3] added try to local_to_global --- pokemonred_puffer/environment.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pokemonred_puffer/environment.py b/pokemonred_puffer/environment.py index 7fa08ae..297cf6a 100644 --- a/pokemonred_puffer/environment.py +++ b/pokemonred_puffer/environment.py @@ -309,7 +309,7 @@ def init_mem(self): self.seen_hidden_objs = {} self.cut_coords = {} - self.cut_tiles = set([]) + self.cut_tiles = {} # set([]) self.cut_state = deque(maxlen=3) self.seen_start_menu = 0 @@ -809,7 +809,11 @@ def update_seen_coords(self): x_pos, y_pos, map_n = self.get_game_coords() self.seen_coords[(x_pos, y_pos, map_n)] = 1 self.seen_coords_since_blackout.add((x_pos, y_pos, map_n)) - self.explore_map[local_to_global(y_pos, x_pos, map_n)] = 1 + try: + self.explore_map[local_to_global(y_pos, x_pos, map_n)] = 1 + except IndexError: + gy, gx = local_to_global(y_pos, x_pos, map_n) + print(f"coord out of bounds! global: ({gx}, {gy}) game: ({x_pos}, {y_pos}, {map_n})") # self.seen_global_coords[local_to_global(y_pos, x_pos, map_n)] = 1 self.seen_map_ids[map_n] = 1 self.seen_map_ids_since_blackout.add(map_n) From 86ab484117876173f6dea8e69dd98caeedfeab36 Mon Sep 17 00:00:00 2001 From: kywch Date: Wed, 20 Mar 2024 21:59:56 -0700 Subject: [PATCH 3/3] incorporated comments --- pokemonred_puffer/environment.py | 10 +++------- pokemonred_puffer/global_map.py | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pokemonred_puffer/environment.py b/pokemonred_puffer/environment.py index 297cf6a..50686d6 100644 --- a/pokemonred_puffer/environment.py +++ b/pokemonred_puffer/environment.py @@ -309,7 +309,7 @@ def init_mem(self): self.seen_hidden_objs = {} self.cut_coords = {} - self.cut_tiles = {} # set([]) + self.cut_tiles = {} self.cut_state = deque(maxlen=3) self.seen_start_menu = 0 @@ -809,11 +809,7 @@ def update_seen_coords(self): x_pos, y_pos, map_n = self.get_game_coords() self.seen_coords[(x_pos, y_pos, map_n)] = 1 self.seen_coords_since_blackout.add((x_pos, y_pos, map_n)) - try: - self.explore_map[local_to_global(y_pos, x_pos, map_n)] = 1 - except IndexError: - gy, gx = local_to_global(y_pos, x_pos, map_n) - print(f"coord out of bounds! global: ({gx}, {gy}) game: ({x_pos}, {y_pos}, {map_n})") + self.explore_map[local_to_global(y_pos, x_pos, map_n)] = 1 # self.seen_global_coords[local_to_global(y_pos, x_pos, map_n)] = 1 self.seen_map_ids[map_n] = 1 self.seen_map_ids_since_blackout.add(map_n) @@ -822,7 +818,7 @@ def get_explore_map(self): explore_map = np.zeros(GLOBAL_MAP_SHAPE) for (x, y, map_n), v in self.seen_coords.items(): gy, gx = local_to_global(y, x, map_n) - if gy >= explore_map.shape[0] or gy < 0 or gx >= explore_map.shape[1] or gx < 0: + if 0 > gy >= explore_map.shape[0] or 0 > gx >= explore_map.shape[1]: print(f"coord out of bounds! global: ({gx}, {gy}) game: ({x}, {y}, {map_n})") else: explore_map[gy, gx] = v diff --git a/pokemonred_puffer/global_map.py b/pokemonred_puffer/global_map.py index 140cbac..7ed6c75 100644 --- a/pokemonred_puffer/global_map.py +++ b/pokemonred_puffer/global_map.py @@ -22,4 +22,4 @@ def local_to_global(r: int, c: int, map_n: int): return r + 0, c + 0 except IndexError: print(f"Coord {map_x}, {map_y} out of bounds for map id {map_n}.") - return -1, -1 + return 0, 0