Skip to content

Commit 18c3b19

Browse files
Starcraft 2: Moving pool filter to use a counter instead of a dict (#6366)
1 parent b34b84a commit 18c3b19

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

‎worlds/sc2/pool_filter.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from typing import Callable, Dict, List, Set, Tuple, TYPE_CHECKING, Iterable
3+
from collections import Counter
34

45
from BaseClasses import Location, ItemClassification
56
from .item import StarcraftItem, ItemFilterFlags, item_names, item_parents, item_groups
@@ -110,7 +111,7 @@ def __init__(self, world: 'SC2World', item_pool: List[StarcraftItem]) -> None:
110111
self.player = world.player
111112
self.world: 'SC2World' = world
112113
# Track all Progression items and those with complex rules for filtering
113-
self.logical_inventory: Dict[str, int] = {}
114+
self.logical_inventory: Counter[str] = Counter()
114115
for item in item_pool:
115116
if not item_table[item.name].is_important_for_filtering():
116117
continue
@@ -125,13 +126,13 @@ def __init__(self, world: 'SC2World', item_pool: List[StarcraftItem]) -> None:
125126
self.item_name_to_child_items.setdefault(parent_item, []).append(item)
126127

127128
def has(self, item: str, player: int, count: int = 1) -> bool:
128-
return self.logical_inventory.get(item, 0) >= count
129+
return self.logical_inventory[item] >= count
129130

130131
def has_any(self, items: Set[str], player: int) -> bool:
131-
return any(self.logical_inventory.get(item) for item in items)
132+
return any(self.logical_inventory[item] for item in items)
132133

133134
def has_all(self, items: Set[str], player: int) -> bool:
134-
return all(self.logical_inventory.get(item) for item in items)
135+
return all(self.logical_inventory[item] for item in items)
135136

136137
def has_group(self, item_group: str, player: int, count: int = 1) -> bool:
137138
return False # Deliberately fails here, as item pooling is not aware about mission layout
@@ -140,17 +141,17 @@ def count_group(self, item_name_group: str, player: int) -> int:
140141
return 0 # For item filtering assume no missions are beaten
141142

142143
def count(self, item: str, player: int) -> int:
143-
return self.logical_inventory.get(item, 0)
144+
return self.logical_inventory[item]
144145

145146
def count_from_list(self, items: Iterable[str], player: int) -> int:
146-
return sum(self.logical_inventory.get(item, 0) for item in items)
147+
return sum(self.logical_inventory[item] for item in items)
147148

148149
def count_from_list_unique(self, items: Iterable[str], player: int) -> int:
149150
result = 0
150151
for item in items:
151152
if self.logical_inventory[item] > 0:
152153
result += 1
153-
return result
154+
return result
154155

155156
def generate_reduced_inventory(self, inventory_size: int, filler_amount: int, mission_requirements: List[Tuple[str, Callable]]) -> List[StarcraftItem]:
156157
"""Attempts to generate a reduced inventory that can fulfill the mission requirements."""

0 commit comments

Comments
 (0)