Strict and Partial key logic implementations with new test suite utility

This commit is contained in:
aerinon
2023-02-17 10:07:43 -07:00
parent 2b8b9156d9
commit d7c15ae22c
17 changed files with 512 additions and 24 deletions

126
test/NewTestSuite.py Normal file
View File

@@ -0,0 +1,126 @@
import fnmatch
import os
import subprocess
import sys
import multiprocessing
import concurrent.futures
import argparse
from collections import OrderedDict
cpu_threads = multiprocessing.cpu_count()
py_version = f"{sys.version_info.major}.{sys.version_info.minor}"
def main(args=None):
successes = []
errors = []
task_mapping = []
tests = OrderedDict()
successes.append(f"Testing DR (NewTestSuite)")
print(successes[0])
# max_attempts = args.count
pool = concurrent.futures.ThreadPoolExecutor(max_workers=cpu_threads)
dead_or_alive = 0
alive = 0
def test(test_name: str, command: str, test_file: str):
tests[test_name] = [command]
base_command = f"python3.8 DungeonRandomizer.py --suppress_rom --suppress_spoiler"
def gen_seed():
task_command = base_command + " " + command
return subprocess.run(task_command, capture_output=True, shell=True, text=True)
task = pool.submit(gen_seed)
task.success = False
task.name = test_name
task.test_file = test_file
task.cmd = base_command + " " + command
task_mapping.append(task)
for test_suite, test_files in args.test_suite.items():
for test_file in test_files:
test(test_suite, f'--customizer {os.path.join(test_suite, test_file)}', test_file)
from tqdm import tqdm
with tqdm(concurrent.futures.as_completed(task_mapping),
total=len(task_mapping), unit="seed(s)",
desc=f"Success rate: 0.00%") as progressbar:
for task in progressbar:
dead_or_alive += 1
try:
result = task.result()
if result.returncode:
errors.append([task.name + ' ' + task.test_file, task.cmd, result.stderr])
else:
alive += 1
task.success = True
except Exception as e:
raise e
progressbar.set_description(f"Success rate: {(alive/dead_or_alive)*100:.2f}% - {task.name}")
def get_results(testname: str):
result = ""
dead_or_alive = [task.success for task in task_mapping if task.name == testname]
alive = [x for x in dead_or_alive if x]
success = f"{testname} Rate: {(len(alive) / len(dead_or_alive)) * 100:.2f}%"
successes.append(success)
print(success)
result += f"{(len(alive)/len(dead_or_alive))*100:.2f}%\t"
return result.strip()
results = []
for t in tests.keys():
results.append(get_results(t))
for result in results:
print(result)
successes.append(result)
return successes, errors
if __name__ == "__main__":
successes = []
parser = argparse.ArgumentParser(add_help=False)
# parser.add_argument('--count', default=0, type=lambda value: max(int(value), 0))
parser.add_argument('--cpu_threads', default=cpu_threads, type=lambda value: max(int(value), 1))
parser.add_argument('--help', default=False, action='store_true')
args = parser.parse_args()
if args.help:
parser.print_help()
exit(0)
cpu_threads = args.cpu_threads
test_suites = {}
# not sure if it supports subdirectories properly yet
for root, dirnames, filenames in os.walk('test/suite'):
test_suites[root] = fnmatch.filter(filenames, '*.yaml')
args = argparse.Namespace()
args.test_suite = test_suites
s, errors = main(args=args)
if successes:
successes += [""] * 2
successes += s
print()
if errors:
with open(f"new-test-suite-errors.txt", 'w') as stream:
for error in errors:
stream.write(error[0] + "\n")
stream.write(error[1] + "\n")
stream.write(error[2] + "\n\n")
with open("new-test-suite-success.txt", "w") as stream:
stream.write(str.join("\n", successes))
input("Press enter to continue")

View File

@@ -0,0 +1,44 @@
# Possible improvements: account for items that are possibly in logic
# Example: Mire Big Key in harmless means all 6 mire smalls required for fire-locked side,
# if you have access to harmless via:
# 2 pod smalls + bow, hammer or 3 pod small
meta:
players: 1
settings:
1:
key_logic_algorithm: default
keysanity: True
crystals_needed_for_gt: 0 # to skip trash fill
placements:
1:
Hobo: Big Key (Misery Mire)
Waterfall Fairy - Left: Small Key (Misery Mire)
Waterfall Fairy - Right: Small Key (Misery Mire)
Palace of Darkness - Big Chest: Hammer
advanced_placements:
1:
# Contrast with partial_2
- type: Verification
item: Flippers
locations:
Misery Mire - Map Chest: True
Misery Mire - Main Lobby: True
Misery Mire - Bridge Chest: True
Misery Mire - Spike Chest: True
Misery Mire - Compass Chest: False
Misery Mire - Big Key Chest: False
Misery Mire - Boss: False
# Contrast with partial_3
- type: Verification
item: Big Key (Ganons Tower)
locations:
Ganons Tower - Big Key Chest: True
Ganons Tower - Big Key Room - Left: True
Ganons Tower - Big Key Room - Right: True
Ganons Tower - Bob's Chest: True
# Normal logic doesn't allow this placement
# unless hammer is placed before it - no algorithm does this in non-keysanity, but possible in keysanity
- type: Verification
item: Small Key (Palace of Darkness)
locations:
Palace of Darkness - Dark Maze - Bottom: True

View File

@@ -0,0 +1,24 @@
# Even though Lamp is Flipper-locked, this logic considers that a key could be wasted in the dark in mire
# Only fire locked mire is off limits
meta:
players: 1
settings:
1:
key_logic_algorithm: partial
keysanity: true
placements:
1:
Hobo: Lamp
Waterfall Fairy - Left: Small Key (Misery Mire)
advanced_placements:
1:
- type: Verification
item: Flippers
locations:
Misery Mire - Map Chest: True
Misery Mire - Main Lobby: True
Misery Mire - Bridge Chest: True
Misery Mire - Spike Chest: True
Misery Mire - Compass Chest: False
Misery Mire - Big Key Chest: False
Misery Mire - Boss: False

View File

@@ -0,0 +1,26 @@
# For contrast with default logic
# This logic is not yet smart enough to allow the crystal blocked chests with two keys (Spike Pot and one other)
meta:
players: 1
settings:
1:
key_logic_algorithm: partial
keysanity: True
placements:
1:
Hobo: Lamp
Waterfall Fairy - Left: Small Key (Misery Mire)
Waterfall Fairy - Right: Small Key (Misery Mire)
Swamp Palace - Entrance: Big Key (Misery Mire)
advanced_placements:
1:
- type: Verification
item: Flippers
locations:
Misery Mire - Map Chest: False
Misery Mire - Main Lobby: False
Misery Mire - Bridge Chest: True
Misery Mire - Spike Chest: True
Misery Mire - Compass Chest: False
Misery Mire - Big Key Chest: False
Misery Mire - Boss: False

View File

@@ -0,0 +1,160 @@
# For contrast with default logic
# Examples of valid big key placement that doesn't work with pure worst case scenarios
# Basically chests that are obtainable two ways+ of spending keys
# (Possible fix: access to the extra door grants access to the mini helma key too)
meta:
players: 1
settings:
1:
key_logic_algorithm: partial
crystals_needed_for_gt: 0 # to skip trash fill
advanced_placements:
1:
- type: Verification
item: Big Key (Desert Palace)
locations:
Desert Palace - Big Chest: False
Desert Palace - Big Key Chest: True
Desert Palace - Boss: False
Desert Palace - Compass Chest: True
Desert Palace - Map Chest: True
Desert Palace - Torch: True
- type: Verification
item: Big Key (Eastern Palace)
locations:
Eastern Palace - Big Chest: False
Eastern Palace - Big Key Chest: True
Eastern Palace - Boss: False
Eastern Palace - Cannonball Chest: True
Eastern Palace - Compass Chest: True
Eastern Palace - Map Chest: True
- type: Verification
item: Big Key (Ganons Tower)
locations:
# These four require not wasting keys upstairs because the big key is down here
Ganons Tower - Big Key Chest: False
Ganons Tower - Big Key Room - Left: False
Ganons Tower - Big Key Room - Right: False
Ganons Tower - Bob's Chest: False
# These are normal
Ganons Tower - Big Chest: False
Ganons Tower - Bob's Torch: True
Ganons Tower - Compass Room - Bottom Left: True
Ganons Tower - Compass Room - Bottom Right: True
Ganons Tower - Compass Room - Top Left: True
Ganons Tower - Compass Room - Top Right: True
Ganons Tower - DMs Room - Bottom Left: True
Ganons Tower - DMs Room - Bottom Right: True
Ganons Tower - DMs Room - Top Left: True
Ganons Tower - DMs Room - Top Right: True
Ganons Tower - Firesnake Room: True
Ganons Tower - Hope Room - Left: True
Ganons Tower - Hope Room - Right: True
Ganons Tower - Map Chest: True
Ganons Tower - Mini Helmasaur Room - Left: False
Ganons Tower - Mini Helmasaur Room - Right: False
Ganons Tower - Pre-Moldorm Chest: False
Ganons Tower - Randomizer Room - Bottom Left: True
Ganons Tower - Randomizer Room - Bottom Right: True
Ganons Tower - Randomizer Room - Top Left: True
Ganons Tower - Randomizer Room - Top Right: True
Ganons Tower - Tile Room: True
Ganons Tower - Validation Chest: False
- type: Verification
item: Big Key (Ice Palace)
locations:
Ice Palace - Big Chest: False
Ice Palace - Big Key Chest: True
Ice Palace - Boss: False
Ice Palace - Compass Chest: True
Ice Palace - Freezor Chest: True
Ice Palace - Iced T Room: True
Ice Palace - Map Chest: True
Ice Palace - Spike Room: True
- type: Verification
item: Big Key (Misery Mire)
locations:
Misery Mire - Big Chest: False
Misery Mire - Big Key Chest: True
Misery Mire - Boss: False
Misery Mire - Bridge Chest: True
Misery Mire - Compass Chest: True
Misery Mire - Main Lobby: True
Misery Mire - Map Chest: True
Misery Mire - Spike Chest: True
- type: Verification
item: Big Key (Palace of Darkness)
locations:
Palace of Darkness - Big Chest: False
Palace of Darkness - Big Key Chest: True
Palace of Darkness - Boss: False
Palace of Darkness - Compass Chest: True
Palace of Darkness - Dark Basement - Left: True
Palace of Darkness - Dark Basement - Right: True
Palace of Darkness - Dark Maze - Bottom: True
Palace of Darkness - Dark Maze - Top: True
Palace of Darkness - Harmless Hellway: True
Palace of Darkness - Map Chest: True
Palace of Darkness - Shooter Room: True
Palace of Darkness - Stalfos Basement: True
Palace of Darkness - The Arena - Bridge: True
Palace of Darkness - The Arena - Ledge: True
- type: Verification
item: Big Key (Skull Woods)
locations:
Skull Woods - Big Chest: True
Skull Woods - Big Key Chest: True
Skull Woods - Boss: True
Skull Woods - Bridge Room: True
Skull Woods - Compass Chest: True
Skull Woods - Map Chest: True
Skull Woods - Pinball Room: True
Skull Woods - Pot Prison: True
- type: Verification
item: Big Key (Swamp Palace)
locations:
Swamp Palace - Big Chest: True
Swamp Palace - Big Key Chest: True
Swamp Palace - Boss: True
Swamp Palace - Compass Chest: True
Swamp Palace - Entrance: False
Swamp Palace - Flooded Room - Left: True
Swamp Palace - Flooded Room - Right: True
Swamp Palace - Map Chest: True
Swamp Palace - Waterfall Room: True
Swamp Palace - West Chest: True
- type: Verification
item: Big Key (Thieves Town)
locations:
Thieves' Town - Ambush Chest: True
Thieves' Town - Attic: False
Thieves' Town - Big Chest: False
Thieves' Town - Big Key Chest: True
Thieves' Town - Blind's Cell: False
Thieves' Town - Boss: False
Thieves' Town - Compass Chest: True
Thieves' Town - Map Chest: True
- type: Verification
item: Big Key (Tower of Hera)
locations:
Tower of Hera - Basement Cage: True
Tower of Hera - Big Chest: False
Tower of Hera - Big Key Chest: True
Tower of Hera - Boss: False
Tower of Hera - Compass Chest: False
Tower of Hera - Map Chest: True
- type: Verification
item: Big Key (Turtle Rock)
locations:
Turtle Rock - Big Chest: False
Turtle Rock - Big Key Chest: True
Turtle Rock - Boss: False
Turtle Rock - Chain Chomps: True
Turtle Rock - Compass Chest: True
Turtle Rock - Crystaroller Room: False
Turtle Rock - Eye Bridge - Bottom Left: False
Turtle Rock - Eye Bridge - Bottom Right: False
Turtle Rock - Eye Bridge - Top Left: False
Turtle Rock - Eye Bridge - Top Right: False
Turtle Rock - Roller Room - Left: True
Turtle Rock - Roller Room - Right: True

View File

@@ -0,0 +1,22 @@
meta:
players: 1
settings:
1:
key_logic_algorithm: strict
keysanity: true
placements:
1:
Hobo: Big Key (Misery Mire)
Waterfall Fairy - Left: Small Key (Misery Mire)
advanced_placements:
1:
- type: Verification
item: Flippers
locations:
Misery Mire - Map Chest: False
Misery Mire - Main Lobby: False
Misery Mire - Bridge Chest: True
Misery Mire - Spike Chest: True
Misery Mire - Compass Chest: False
Misery Mire - Big Key Chest: False
Misery Mire - Boss: False