Skip to content

Commit

Permalink
Replaced goal direction/position with output filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Kataiser committed Jun 15, 2023
1 parent 3cdb84f commit b33a38c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
3 changes: 1 addition & 2 deletions movement sim/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ max_fall: 160 # 160 if you aren't fast falling yet, current Y speed if you are.
frames: 12
permutations: 1000000
axis: x # which axis to process, x or y
goal_position: 160.5
filter: [150, 160.5] # only show results within this range
goal_speed: 90 # this is calculated by |final speed - goal speed|
goal_direction: '-' # '-' means approaching from the left/top, '+' is from the right/bottom
prioritize_speed: false # sort by speed instead of position
disabled_key: auto # disable generating a certain key, "auto" or blank will disable keys that can't ever affect input
rng_threshold: 20 # frame count to start using the RNG method when a key is disabled
Expand Down
17 changes: 9 additions & 8 deletions movement sim/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def __init__(self):
self.permutations: int = int(cfg_dict['permutations'])
self.axis: str = str(cfg_dict['axis'])
self.jump_timer: int = int(cfg_dict['jump_timer'])
self.goal_position: float = float(cfg_dict['goal_position'])
self.goal_direction: str = str(cfg_dict['goal_direction'])
self.goal_speed: float = float(cfg_dict['goal_speed'])
self.filter_min: float = float(min(cfg_dict['filter']))
self.filter_max: float = float(max(cfg_dict['filter']))
self.prioritize_speed: bool = bool(cfg_dict['prioritize_speed'])
self.holding: bool = bool(cfg_dict['holding'])
self.auto_jump: bool = bool(cfg_dict['auto_jump'])
Expand All @@ -47,8 +47,8 @@ def __init__(self):
if self.axis not in ('x', 'y'):
print("Axis must be x or y, exiting")
raise SystemExit
if self.goal_direction not in ('-', '+'):
print("Goal direction must be - or +, exiting")
if len(cfg_dict['filter']) != 2:
print("Filter must be two elements, exiting")
raise SystemExit
if self.disabled_key not in ('auto', 'l', 'r', 'j', 'd', 'none'):
print("Disabled key must be auto, l, r, j, d, or just blank. Exiting")
Expand All @@ -71,6 +71,7 @@ def main():
input_formatter.main(config_mtime)
config_mtime = sim_main(False)


def sim_main(do_update_check: bool) -> float:
if do_update_check:
update_check.is_latest_commit()
Expand Down Expand Up @@ -128,8 +129,8 @@ def sim_main(do_update_check: bool) -> float:
sim_function: Callable = sim_x if cfg.axis == 'x' else sim_y
results_pos, results_speed = sim_function(permutation, cfg)

# if result within goal range
if (cfg.goal_direction == '-' and results_pos < cfg.goal_position) or (cfg.goal_direction == '+' and results_pos > cfg.goal_position):
# if result within filter range
if cfg.filter_min <= results_pos <= cfg.filter_max:
append_permutation: bool = True
valid_permutation: Tuple[float, float, tuple]

Expand All @@ -148,11 +149,11 @@ def sim_main(do_update_check: bool) -> float:

# sort both speed and position, with the second one performed being the prioritized one
if cfg.prioritize_speed:
valid_permutations.sort(reverse=cfg.goal_direction == '+', key=lambda p: p[0])
valid_permutations.sort(key=lambda p: p[0])
valid_permutations.sort(reverse=True, key=lambda p: abs(p[1] - cfg.goal_speed))
else:
valid_permutations.sort(reverse=True, key=lambda p: abs(p[1] - cfg.goal_speed))
valid_permutations.sort(reverse=cfg.goal_direction == '+', key=lambda p: p[0])
valid_permutations.sort(key=lambda p: p[0])

# delete unused permutations from memory
input_permutations_len: int = len(input_permutations)
Expand Down

0 comments on commit b33a38c

Please sign in to comment.