Skip to content

Commit

Permalink
Better debug mode, add no wild encounters mode
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguy11325 committed Jun 9, 2024
1 parent 98e2ae5 commit 8168ba4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ debug:
stream_wrapper: False
init_state: cut
max_steps: 1_000_000
disable_wild_encounters: True
disable_ai_actions: True
train:
device: cpu
compile: False
Expand Down Expand Up @@ -48,6 +50,9 @@ env:
two_bit: True
log_frequency: 2000
auto_flash: True
disable_wild_encounters: False
disable_ai_actions: False


train:
seed: 1
Expand Down
18 changes: 16 additions & 2 deletions pokemonred_puffer/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def __init__(self, env_config: pufferlib.namespace):
self.log_frequency = env_config.log_frequency
self.two_bit = env_config.two_bit
self.auto_flash = env_config.auto_flash
self.disable_wild_encounters = env_config.disable_wild_encounters
self.disable_ai_actions = env_config.disable_ai_actions
self.action_space = ACTION_SPACE

# Obs space-related. TODO: avoid hardcoding?
Expand Down Expand Up @@ -303,6 +305,13 @@ def register_hooks(self):
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)
if self.disable_wild_encounters:
self.pyboy.hook_register(
None,
"TryDoWildEncounter.gotWildEncounterType",
self.disable_wild_encounter_hook,
None,
)

def update_state(self, state: bytes):
self.reset(seed=random.randint(0, 10), options={"state": state})
Expand Down Expand Up @@ -630,8 +639,9 @@ def run_action_on_emulator(self, action):
self.action_hist[action] += 1
# press button then release after some steps
# TODO: Add video saving logic
self.pyboy.send_input(VALID_ACTIONS[action])
self.pyboy.send_input(VALID_RELEASE_ACTIONS[action], delay=8)
if not self.disable_ai_actions:
self.pyboy.send_input(VALID_ACTIONS[action])
self.pyboy.send_input(VALID_RELEASE_ACTIONS[action], delay=8)
self.pyboy.tick(self.action_freq, render=True)

if self.read_bit(0xD803, 0):
Expand Down Expand Up @@ -811,6 +821,10 @@ def cut_hook(self, context):
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):
self.pyboy.memory[self.pyboy.symbol_lookup("wRepelRemainingSteps")[1]] = 100
self.pyboy.memory[self.pyboy.symbol_lookup("wCurEnemyLVL")[1]] = 1

def agent_stats(self, action):
levels = [self.read_m(f"wPartyMon{i+1}Level") for i in range(self.read_m("wPartyCount"))]
return {
Expand Down

0 comments on commit 8168ba4

Please sign in to comment.