Zillion: Some Code Cleaning (#4780)

This commit is contained in:
Doug Hoskisson
2025-04-20 04:07:17 -07:00
committed by GitHub
parent 199b6bdabb
commit a26abe079e
8 changed files with 37 additions and 37 deletions

View File

@@ -25,15 +25,15 @@ def set_randomizer_locs(cs: CollectionState, p: int, zz_r: Randomizer) -> int:
z_world = cs.multiworld.worlds[p]
assert isinstance(z_world, ZillionWorld)
_hash = p
hash_ = p
for z_loc in z_world.my_locations:
zz_name = z_loc.zz_loc.name
zz_item = z_loc.item.zz_item \
if isinstance(z_loc.item, ZillionItem) and z_loc.item.player == p \
else zz_empty
zz_r.locations[zz_name].item = zz_item
_hash += (hash(zz_name) * (z_loc.zz_loc.req.gun + 2)) ^ hash(zz_item)
return _hash
hash_ += (hash(zz_name) * (z_loc.zz_loc.req.gun + 2)) ^ hash(zz_item)
return hash_
def item_counts(cs: CollectionState, p: int) -> tuple[tuple[str, int], ...]:
@@ -67,11 +67,11 @@ class ZillionLogicCache:
returns frozenset of accessible zilliandomizer locations
"""
# caching this function because it would be slow
_hash = set_randomizer_locs(cs, self._player, self._zz_r)
hash_ = set_randomizer_locs(cs, self._player, self._zz_r)
counts = item_counts(cs, self._player)
_hash += hash(counts)
hash_ += hash(counts)
cntr, locs = self._cache.get(_hash, _cache_miss)
cntr, locs = self._cache.get(hash_, _cache_miss)
if cntr == cs.prog_items[self._player]:
# print("cache hit")
return locs
@@ -90,6 +90,6 @@ class ZillionLogicCache:
tr = frozenset(self._zz_r.get_locations(have_req))
# save result in cache
self._cache[_hash] = (cs.prog_items[self._player].copy(), tr)
self._cache[hash_] = (cs.prog_items[self._player].copy(), tr)
return tr