Skip to content

Commit

Permalink
Fix badges and items
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguy11325 committed Jun 16, 2024
1 parent fe06f48 commit 2a6c71a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pokemonred_puffer/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,10 @@ def _get_obs(self):
# player_x, player_y, map_n = self.get_game_coords()
_, wBagItems = self.pyboy.symbol_lookup("wBagItems")
bag = self.pyboy.memory[wBagItems : wBagItems + 40]
end_of_bag = list(bag[::2]).index(0xFF)
try:
end_of_bag = 2 * list(bag[::2]).index(0xFF)
except ValueError:
end_of_bag = len(bag)
bag = np.array(bag, dtype=np.uint8)
bag[end_of_bag:] = 0

Expand Down Expand Up @@ -1055,7 +1058,8 @@ def disable_wild_encounter_hook(self, *args, **kwargs):

def agent_stats(self, action):
levels = [self.read_m(f"wPartyMon{i+1}Level") for i in range(self.read_m("wPartyCount"))]
badges = self.read_short("wObtainedBadges")
badges = self.read_m("wObtainedBadges")
breakpoint()
return {
"stats": {
"step": self.step_count + self.reset_count * self.max_steps,
Expand Down Expand Up @@ -1103,7 +1107,7 @@ def agent_stats(self, action):
"rival3": int(self.read_m(0xD665) == 4),
"rocket_hideout_found": int(self.read_bit(0xD77E, 1)),
}
| {f"badge_{i+1}": badges & (1 << i) for i in range(8)},
| {f"badge_{i+1}": bool(badges & (1 << i)) for i in range(8)},
"reward": self.get_game_state_reward(),
"reward/reward_sum": sum(self.get_game_state_reward().values()),
"pokemon_exploration_map": self.explore_map,
Expand Down

0 comments on commit 2a6c71a

Please sign in to comment.