Skip to content

Commit

Permalink
Merge pull request #4 from kywch/main
Browse files Browse the repository at this point in the history
Handling local_to_global() IndexError
  • Loading branch information
thatguy11325 authored Mar 21, 2024
2 parents c1f1f5d + 86ab484 commit 5ec82a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pokemonred_puffer/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,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
Expand Down Expand Up @@ -668,7 +668,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 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
Expand Down
3 changes: 3 additions & 0 deletions pokemonred_puffer/global_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 0, 0

0 comments on commit 5ec82a0

Please sign in to comment.