Skip to content

Commit

Permalink
sc2: Updated ValidInventory to allow passing count to has(); added ne…
Browse files Browse the repository at this point in the history
…w methods to TestInventory in test_rules
  • Loading branch information
MatthewMarinets committed Dec 29, 2024
1 parent 3ba582b commit c74e31a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions worlds/sc2/pool_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def __init__(self, world: 'SC2World', item_pool: List[StarcraftItem]) -> None:
for parent_item in item_parents.child_item_to_parent_items.get(item.name, []):
self.item_name_to_child_items.setdefault(parent_item, []).append(item)

def has(self, item: str, player: int) -> bool:
return self.logical_inventory.get(item, 0) > 0
def has(self, item: str, player: int, count: int = 1) -> bool:
return self.logical_inventory.get(item, 0) >= count

def has_any(self, items: Set[str], player: int) -> bool:
return any(self.logical_inventory.get(item) for item in items)
Expand Down
2 changes: 1 addition & 1 deletion worlds/sc2/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ def protoss_any_anti_air_soa(self, state: CollectionState) -> bool:
item_names.SOA_SOLAR_BOMBARDMENT, item_names.SOA_PURIFIER_BEAM,
item_names.SOA_PYLON_OVERCHARGE,
), self.player)
or state.has(item_names.SOA_PROGRESSIVE_PROXY_PYLON, self.player, 2) # Reinforcements)
or state.has(item_names.SOA_PROGRESSIVE_PROXY_PYLON, self.player, 2) # Warp-In Reinforcements
)

def protoss_any_anti_air_unit(self, state: CollectionState) -> bool:
Expand Down
5 changes: 4 additions & 1 deletion worlds/sc2/test/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def is_item_progression(self, item: str) -> bool:
def random_boolean(self):
return self.random.choice([True, False])

def has(self, item: str, player: int):
def has(self, item: str, player: int, count: int = 1):
if not self.is_item_progression(item):
raise AssertionError("Logic item {} is not a progression item".format(item))
return self.random_boolean()
Expand Down Expand Up @@ -56,6 +56,9 @@ def count(self, item: str, player: int) -> int:
def count_from_list(self, items: Iterable[str], player: int) -> int:
return sum(self.count(item_name, player) for item_name in items)

def count_from_list_unique(self, items: Iterable[str], player: int) -> int:
return sum(self.count(item_name, player) for item_name in items)


class TestWorld:
"""
Expand Down

0 comments on commit c74e31a

Please sign in to comment.