From ea8498f402163abf07f2cb6c02fa403f1ed20701 Mon Sep 17 00:00:00 2001 From: Kara Alexandra Date: Fri, 16 Jan 2026 15:47:53 -0600 Subject: [PATCH] Add --tries arg --- CLI.py | 2 ++ DungeonRandomizer.py | 50 +++++++++++++++++++++------------- Rom.py | 2 +- resources/app/cli/lang/en.json | 5 ++++ 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/CLI.py b/CLI.py index 5db1fc78..ca1b3dff 100644 --- a/CLI.py +++ b/CLI.py @@ -88,6 +88,7 @@ def parse_cli(argv, no_defaults=False): parser.add_argument('--seed', default=defval(int(settings["seed"]) if settings["seed"] != "" and settings["seed"] is not None else None), help="\n".join(fish.translate("cli", "help", "seed")), type=int) parser.add_argument('--count', default=defval(int(settings["count"]) if settings["count"] != "" and settings["count"] is not None else 1), help="\n".join(fish.translate("cli", "help", "count")), type=int) + parser.add_argument('--tries', default=defval(int(settings["tries"]) if settings["tries"] != "" and settings["tries"] is not None else 1), help="\n".join(fish.translate("cli", "help", "tries")), type=int) parser.add_argument('--customitemarray', default={}, help=argparse.SUPPRESS) # included for backwards compatibility @@ -293,6 +294,7 @@ def parse_settings(): "seed": "", "count": 1, + "tries": 1, "startinventory": "", 'beemizer': '0', "remote_items": False, diff --git a/DungeonRandomizer.py b/DungeonRandomizer.py index 94b83faf..06fec596 100755 --- a/DungeonRandomizer.py +++ b/DungeonRandomizer.py @@ -61,29 +61,41 @@ def start(): if args.gui: from Gui import guiMain guiMain(args) - elif args.count is not None and args.count > 1: + else: + count = args.count or 1 + tries = args.tries or 1 random.seed(None) seed = args.seed or random.randint(0, 999999999) failures = [] + attempts = 0 logger = logging.getLogger('') - for _ in range(args.count): - try: - main(seed=seed, args=args, fish=fish) - logger.info('%s %s', fish.translate("cli","cli","finished.run"), _+1) - except (FillError, EnemizerError, Exception, RuntimeError) as err: - failures.append((err, seed)) - logger.warning('%s: %s', fish.translate("cli","cli","generation.failed"), err) - seed = random.randint(0, 999999999) - for fail in failures: - logger.info('%s\tseed failed with: %s', fail[1], fail[0]) - fail_rate = 100 * len(failures) / args.count - success_rate = 100 * (args.count - len(failures)) / args.count - fail_rate = str(fail_rate).split('.') - success_rate = str(success_rate).split('.') - logger.info('Generation fail rate: ' + str(fail_rate[0] ).rjust(3, " ") + '.' + str(fail_rate[1] ).ljust(6, '0') + '%') - logger.info('Generation success rate: ' + str(success_rate[0]).rjust(3, " ") + '.' + str(success_rate[1]).ljust(6, '0') + '%') - else: - main(seed=args.seed, args=args, fish=fish) + for seednum in range(count): + for trynum in range(tries): + try: + attempts += 1 + main(seed=seed, args=args, fish=fish) + logger.info('%s %s', fish.translate("cli","cli","finished.run"), seednum + 1) + logger.info('') + seed = random.randint(0, 999999999) + break + except (FillError, EnemizerError, Exception, RuntimeError) as err: + failures.append((err, seed)) + logger.warning('%s: %s', fish.translate("cli","cli","generation.failed"), err) + logger.info('') + seed = random.randint(0, 999999999) + + if count > 1 or tries > 1: + for fail in failures: + logger.info('seed %9s failed with: %s', fail[1], fail[0]) + if len(failures) > 0: + logger.info('') + fail_rate = 100 * len(failures) / attempts + success_rate = 100 * (attempts - len(failures)) / attempts + logger.info('Generation failure rate: %6.2f%%', fail_rate) + logger.info('Generation success rate: %6.2f%%', success_rate) + + if len(failures) == attempts: + sys.exit(1) if __name__ == '__main__': diff --git a/Rom.py b/Rom.py index ab0ce2a8..4b37bc60 100644 --- a/Rom.py +++ b/Rom.py @@ -3120,7 +3120,7 @@ ConnectorEntrances = {'Elder House (East)': 'Elder House', 'Hookshot Cave': 'The rock on dark DM', 'Two Brothers House (West)': 'The door near the race game', 'Old Man Cave (East)': 'The SW-most cave on west DM', - 'Old Man House (Bottom)': 'A cave with a door on west DM', + 'Old Man House (Bottom)': 'A cave with a doorframe on west DM', 'Old Man House (Top)': 'The eastmost cave on west DM', 'Death Mountain Return Cave (East)': 'The westmost cave on west DM', 'Spectacle Rock Cave Peak': 'The highest cave on west DM', diff --git a/resources/app/cli/lang/en.json b/resources/app/cli/lang/en.json index e5093801..c8b427b6 100644 --- a/resources/app/cli/lang/en.json +++ b/resources/app/cli/lang/en.json @@ -352,6 +352,11 @@ "--seed given will produce the same %(default)s (different) rom(s) each", "time)." ], + "tries": [ + "Use to attempt multiple times to succeed at generating a seed.", + "If --seed is provided, it will be used for the first seed, then", + "used to derive the next seed, until one succeeds." + ], "fastmenu": [ "Select the rate at which the menu opens and closes. (default: %(default)s)" ],