Skip to content

Commit da00d67

Browse files
committed
Merge 'Fix MW goal hint weight initialization and add regression test' (OoTRandomizer#2539)
2 parents 99c431a + 7d9405a commit da00d67

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Fix unshuffled treasure box shop keys showing the wrong item model while inside the chests if `Key Appearance Matches Dungeon` is enabled.
2020
* Add two missing locations: `Ganons Castle MQ Shadow Trial Explosives Wonderitem` and a `Bombable Fairy` in MQ Jabu.
2121
* Improve the error message when a settings string from the wrong randomizer version is imported.
22+
* Fix wrong Goal hints being generated for worlds other than the first in multiworld seeds.
2223

2324
# 9.0
2425

Goals.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ def update_goal_items(spoiler: Spoiler) -> None:
248248
woth_locations = list(required_locations['way of the hero'])
249249
del required_locations['way of the hero']
250250

251+
# Update category and goal weights that have required locations
252+
for category_name, goals in required_locations.items():
253+
for goal_name, goal_worlds in goals.items():
254+
for world_id, locations in goal_worlds.items():
255+
worlds[world_id].goal_categories[category_name].weight = 1
256+
worlds[world_id].goal_categories[category_name].get_goal(goal_name).weight = 1
257+
251258
# Update WOTH items
252259
woth_locations_dict = {}
253260
for world in worlds:
@@ -362,8 +369,7 @@ def search_goals(categories: dict[str, GoalCategory], reachable_goals: ValidGoal
362369
else:
363370
location_weights = (location, 1, 1)
364371
required_locations[category.name][goal.name][world_id].append(location_weights)
365-
goal.weight = 1
366-
category.weight = 1
372+
367373
# Locations added to goal exclusion for future categories
368374
# Main use is to split goals between before/after rainbow bridge
369375
# Requires goal categories to be sorted by priority!

Unittest.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import unittest
1313
from collections import Counter, defaultdict
1414
from typing import Literal, Optional, Any, overload
15+
from unittest.mock import patch
1516

1617
from EntranceShuffle import EntranceShuffleError
1718
from Fill import ShuffleError
@@ -567,6 +568,68 @@ def test_fix_broken_drops(self):
567568

568569

569570
class TestHints(unittest.TestCase):
571+
def test_multiworld_goal_weights_initialized_per_world(self):
572+
settings = make_settings_for_test({
573+
"world_count": 2,
574+
"bridge": "medallions",
575+
"bridge_medallions": 4,
576+
"shuffle_ganon_bosskey": "medallions",
577+
"ganon_bosskey_medallions": 6,
578+
"item_pool_value": "minimal",
579+
"trials_random": False,
580+
"trials": 0,
581+
"open_forest": "closed_deku",
582+
"open_door_of_time": "open",
583+
"shuffle_song_items": "song",
584+
"tokensanity": "off",
585+
"mq_dungeons_mode": "vanilla",
586+
"hint_dist_user": {
587+
"name": "goal_weight_regression",
588+
"gui_name": "Goal Weight Regression",
589+
"description": "Custom hint distribution for multiworld goal weight regression testing.",
590+
"add_locations": [],
591+
"remove_locations": [],
592+
"add_items": [],
593+
"remove_items": [],
594+
"dungeons_woth_limit": 2,
595+
"dungeons_barren_limit": 1,
596+
"named_items_required": True,
597+
"vague_named_items": False,
598+
"use_default_goals": True,
599+
"distribution": {
600+
"trial": {"order": 1, "weight": 0.0, "fixed": 0, "copies": 1},
601+
"always": {"order": 2, "weight": 0.0, "fixed": 0, "copies": 1},
602+
"woth": {"order": 3, "weight": 0.0, "fixed": 0, "copies": 1},
603+
"goal": {"order": 4, "weight": 0.0, "fixed": 6, "copies": 1},
604+
"barren": {"order": 5, "weight": 0.0, "fixed": 0, "copies": 1},
605+
"entrance": {"order": 6, "weight": 0.0, "fixed": 0, "copies": 1},
606+
"sometimes": {"order": 7, "weight": 0.0, "fixed": 99, "copies": 1},
607+
},
608+
},
609+
}, seed="TESTTESTTEST", outfilename="multiworld-goal-weight-regression")
610+
611+
# Build weights via update_goal_items and skip hint generation, which mutates weights.
612+
with patch("Main.build_gossip_hints", return_value=None):
613+
spoiler = main(settings)
614+
615+
self.assertGreater(len(spoiler.worlds), 1)
616+
for world in spoiler.worlds[1:]:
617+
with self.subTest(world=world.id + 1):
618+
self.assertIn(world.id, spoiler.goal_locations)
619+
self.assertGreater(len(spoiler.goal_locations[world.id]), 0)
620+
621+
weighted_goals = 0
622+
for category_name, goals in spoiler.goal_locations[world.id].items():
623+
category = world.goal_categories[category_name]
624+
for goal_name, goal_worlds in goals.items():
625+
if not any(len(locations) > 0 for locations in goal_worlds.values()):
626+
continue
627+
weighted_goals += 1
628+
self.assertEqual(category.weight, 1)
629+
self.assertEqual(category.get_goal(goal_name).weight, 1)
630+
631+
self.assertGreater(weighted_goals, 0)
632+
570633
def test_skip_zelda(self):
571634
# Song from Impa would be WotH, but instead of relying on random chance to get HC WotH,
572635
# just exclude all other locations to see if HC is barren.

version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '9.0.23'
1+
__version__ = '9.0.24'
22

33
# This is a supplemental version number for branches based off of main dev.
44
supplementary_version = 0

0 commit comments

Comments
 (0)