From d8d148ac135c5848820f22bdc9bc13aa62831cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Bolduc?= <16137441+Jouramie@users.noreply.github.com> Date: Sun, 17 May 2026 17:41:34 -0400 Subject: [PATCH] Stardew Valley: Bypass CollectionState overhead by just calling prog_items (#6065) --- worlds/stardew_valley/stardew_rule/state.py | 4 ++-- worlds/stardew_valley/test/TestStardewRule.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/worlds/stardew_valley/stardew_rule/state.py b/worlds/stardew_valley/stardew_rule/state.py index 3fe294a3ba..dcf0a2bc79 100644 --- a/worlds/stardew_valley/stardew_rule/state.py +++ b/worlds/stardew_valley/stardew_rule/state.py @@ -27,7 +27,7 @@ class TotalReceived(BaseStardewRule): def __call__(self, state: CollectionState) -> bool: c = 0 for item in self.items: - c += state.count(item, self.player) + c += state.prog_items[self.player][item] if c >= self.count: return True return False @@ -56,7 +56,7 @@ class Received(CombinableStardewRule): return self.count def __call__(self, state: CollectionState) -> bool: - return state.has(self.item, self.player, self.count) + return state.prog_items[self.player][self.item] >= self.count def evaluate_while_simplifying(self, state: CollectionState) -> Tuple[StardewRule, bool]: return self, self(state) diff --git a/worlds/stardew_valley/test/TestStardewRule.py b/worlds/stardew_valley/test/TestStardewRule.py index 93b32b0d8a..842e4589c6 100644 --- a/worlds/stardew_valley/test/TestStardewRule.py +++ b/worlds/stardew_valley/test/TestStardewRule.py @@ -1,4 +1,5 @@ import unittest +from collections import Counter from typing import cast from unittest.mock import MagicMock, Mock @@ -103,7 +104,7 @@ class TestEvaluateWhileSimplifying(unittest.TestCase): def test_short_circuit_when_combinable_rules_is_false(self): collection_state = MagicMock() - collection_state.has = Mock(return_value=False) + collection_state.prog_items = {1: Counter()} other_rule = MagicMock() rule = And(Received("Potato", 1, 10), cast(StardewRule, other_rule)) @@ -113,6 +114,7 @@ class TestEvaluateWhileSimplifying(unittest.TestCase): def test_identity_is_removed_from_other_rules(self): collection_state = MagicMock() + collection_state.prog_items = {1: Counter()} rule = Or(false_, Received("Potato", 1, 10)) rule.evaluate_while_simplifying(collection_state) @@ -122,6 +124,7 @@ class TestEvaluateWhileSimplifying(unittest.TestCase): def test_complement_replaces_combinable_rules(self): collection_state = MagicMock() + collection_state.prog_items = {1: Counter()} rule = Or(Received("Potato", 1, 10), true_) rule.evaluate_while_simplifying(collection_state) @@ -132,6 +135,7 @@ class TestEvaluateWhileSimplifying(unittest.TestCase): expected_simplified = true_ expected_result = True collection_state = MagicMock() + collection_state.prog_items = {1: Counter()} rule = Or(Or(expected_simplified), Received("Potato", 1, 10)) actual_simplified, actual_result = rule.evaluate_while_simplifying(collection_state) @@ -142,6 +146,7 @@ class TestEvaluateWhileSimplifying(unittest.TestCase): def test_already_simplified_rules_are_not_simplified_again(self): collection_state = MagicMock() + collection_state.prog_items = {1: Counter()} other_rule = MagicMock() other_rule.evaluate_while_simplifying = Mock(return_value=(other_rule, False)) rule = Or(cast(StardewRule, other_rule), Received("Potato", 1, 10))