Skip to content

Commit

Permalink
Animate scripts config
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguy11325 committed Jun 28, 2024
1 parent 0ff06af commit da98592
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
5 changes: 4 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ debug:
disable_ai_actions: True
use_global_map: False
reduce_res: False
train:
animate_scripts: True
train:
device: cpu
compile: False
compile_mode: default
Expand Down Expand Up @@ -68,6 +69,8 @@ env:
infinite_money: True
use_global_map: False
save_state: False
animate_scripts: False



train:
Expand Down
33 changes: 17 additions & 16 deletions pokemonred_puffer/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(self, env_config: pufferlib.namespace):
self.infinite_money = env_config.infinite_money
self.use_global_map = env_config.use_global_map
self.save_state = env_config.save_state
self.animate_scripts = env_config.animate_scripts
self.action_space = ACTION_SPACE

# Obs space-related. TODO: avoid hardcoding?
Expand Down Expand Up @@ -783,30 +784,30 @@ def cut_if_next(self):

# open start menu
self.pyboy.button("START", delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, self.animate_scripts)
# scroll to pokemon
# 1 is the item index for pokemon
for _ in range(24):
if self.pyboy.memory[self.pyboy.symbol_lookup("wCurrentMenuItem")[1]] == 1:
break
self.pyboy.button("DOWN", delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, render=self.animate_scripts)
self.pyboy.button("A", delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, self.animate_scripts)

# find pokemon with cut
# We run this over all pokemon so we dont end up in an infinite for loop
for _ in range(7):
self.pyboy.button("DOWN", delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, self.animate_scripts)
party_mon = self.pyboy.memory[self.pyboy.symbol_lookup("wCurrentMenuItem")[1]]
_, addr = self.pyboy.symbol_lookup(f"wPartyMon{party_mon%6+1}Moves")
if 0xF in self.pyboy.memory[addr : addr + 4]:
break

# Enter submenu
self.pyboy.button("A", delay=8)
self.pyboy.tick(4 * self.action_freq, render=True)
self.pyboy.tick(4 * self.action_freq, self.animate_scripts)

# Scroll until the field move is found
_, wFieldMoves = self.pyboy.symbol_lookup("wFieldMoves")
Expand All @@ -817,12 +818,12 @@ def cut_if_next(self):
if current_item < 4 and FieldMoves.CUT.value == field_moves[current_item]:
break
self.pyboy.button("DOWN", delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, self.animate_scripts)

# press a bunch of times
for _ in range(5):
self.pyboy.button("A", delay=8)
self.pyboy.tick(4 * self.action_freq, render=True)
self.pyboy.tick(4 * self.action_freq, self.animate_scripts)

def surf_if_attempt(self, action: WindowEvent):
if not (
Expand Down Expand Up @@ -869,25 +870,25 @@ def surf_if_attempt(self, action: WindowEvent):
# open start menu
self.pyboy.send_input(WindowEvent.PRESS_BUTTON_START)
self.pyboy.send_input(WindowEvent.RELEASE_BUTTON_START, delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, self.animate_scripts)
# scroll to pokemon
# 1 is the item index for pokemon
for _ in range(24):
if self.pyboy.memory[self.pyboy.symbol_lookup("wCurrentMenuItem")[1]] == 1:
break
self.pyboy.send_input(WindowEvent.PRESS_ARROW_DOWN)
self.pyboy.send_input(WindowEvent.RELEASE_ARROW_DOWN, delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, self.animate_scripts)
self.pyboy.send_input(WindowEvent.PRESS_BUTTON_A)
self.pyboy.send_input(WindowEvent.RELEASE_BUTTON_A, delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, self.animate_scripts)

# find pokemon with surf
# We run this over all pokemon so we dont end up in an infinite for loop
for _ in range(7):
self.pyboy.send_input(WindowEvent.PRESS_ARROW_DOWN)
self.pyboy.send_input(WindowEvent.RELEASE_ARROW_DOWN, delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, self.animate_scripts)
party_mon = self.pyboy.memory[self.pyboy.symbol_lookup("wCurrentMenuItem")[1]]
_, addr = self.pyboy.symbol_lookup(f"wPartyMon{party_mon%6+1}Moves")
if 0x39 in self.pyboy.memory[addr : addr + 4]:
Expand All @@ -896,7 +897,7 @@ def surf_if_attempt(self, action: WindowEvent):
# Enter submenu
self.pyboy.send_input(WindowEvent.PRESS_BUTTON_A)
self.pyboy.send_input(WindowEvent.RELEASE_BUTTON_A, delay=8)
self.pyboy.tick(4 * self.action_freq, render=True)
self.pyboy.tick(4 * self.action_freq, self.animate_scripts)

# Scroll until the field move is found
_, wFieldMoves = self.pyboy.symbol_lookup("wFieldMoves")
Expand All @@ -911,13 +912,13 @@ def surf_if_attempt(self, action: WindowEvent):
break
self.pyboy.send_input(WindowEvent.PRESS_ARROW_DOWN)
self.pyboy.send_input(WindowEvent.RELEASE_ARROW_DOWN, delay=8)
self.pyboy.tick(self.action_freq, render=True)
self.pyboy.tick(self.action_freq, self.animate_scripts)

# press a bunch of times
for _ in range(5):
self.pyboy.send_input(WindowEvent.PRESS_BUTTON_A)
self.pyboy.send_input(WindowEvent.RELEASE_BUTTON_A, delay=8)
self.pyboy.tick(4 * self.action_freq, render=True)
self.pyboy.tick(4 * self.action_freq, self.animate_scripts)

def solve_missable_strength_puzzle(self):
in_cavern = self.read_m("wCurMapTileset") == Tilesets.CAVERN.value
Expand Down Expand Up @@ -955,7 +956,7 @@ def solve_missable_strength_puzzle(self):
self.pyboy.symbol_lookup("wRepelRemainingSteps")[1]
] = 0xFF
self.pyboy.button(button, 8)
self.pyboy.tick(self.action_freq * 1.5, render=True)
self.pyboy.tick(self.action_freq * 1.5, self.animate_scripts)
self.pyboy.memory[self.pyboy.symbol_lookup("wRepelRemainingSteps")[1]] = (
current_repel_steps
)
Expand Down Expand Up @@ -985,7 +986,7 @@ def solve_switch_strength_puzzle(self):
0xFF
)
self.pyboy.button(button, 8)
self.pyboy.tick(self.action_freq * 2, render=True)
self.pyboy.tick(self.action_freq * 2, self.animate_scripts)
self.pyboy.memory[self.pyboy.symbol_lookup("wRepelRemainingSteps")[1]] = (
current_repel_steps
)
Expand Down

0 comments on commit da98592

Please sign in to comment.