From 17cd963665f4e61b59ea40d36da96f77918164b5 Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Sun, 5 Nov 2017 22:08:36 -0500 Subject: [PATCH] Simplify the only-beatable mode. This also makes it faster. --- BaseClasses.py | 12 +++++++++++- Fill.py | 17 ++++------------- Main.py | 2 ++ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index 55aa1ba6..949da8d8 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -183,6 +183,13 @@ class World(object): return True return False + + def has_beaten_game(self, state): + if state.has('Triforce'): return True + if self.goal in ['triforcehunt']: + if state.item_count('Triforce Piece')+state.item_count('Power Star')> self.treasure_hunt_count: + return True + return False def can_beat_game(self, starting_state=None): prog_locations = [location for location in self.get_locations() if location.item is not None and (location.item.advancement or location.event)] @@ -317,7 +324,10 @@ class CollectionState(object): if count == 1: return item in self.prog_items else: - return len([pritem for pritem in self.prog_items if pritem == item]) >= count + return self.item_count(item) >= count + + def item_count(self, item): + return len([pritem for pritem in self.prog_items if pritem == item]) def can_lift_rocks(self): return self.has('Power Glove') or self.has('Titans Mitts') diff --git a/Fill.py b/Fill.py index 983a3279..70ffea92 100644 --- a/Fill.py +++ b/Fill.py @@ -167,23 +167,14 @@ def fill_restrictive(world, base_state, locations, itempool): while itempool and locations: item_to_place = itempool.pop() maximum_exploration_state = sweep_from_pool() + + if world.check_beatable_only: + can_beat_without = world.has_beaten_game(maximum_exploration_state) spot_to_fill = None for location in locations: if location.can_fill(item_to_place): - if world.check_beatable_only: - starting_state = base_state.copy() - for item in itempool: - starting_state.collect(item, True) - - if maximum_exploration_state.can_reach(location): - if world.check_beatable_only: - starting_state.collect(item_to_place, True) - else: - spot_to_fill = location - break - - if world.check_beatable_only and world.can_beat_game(starting_state): + if (world.check_beatable_only and can_beat_without) or maximum_exploration_state.can_reach(location): spot_to_fill = location break diff --git a/Main.py b/Main.py index d1a145fd..8bb7cd0f 100644 --- a/Main.py +++ b/Main.py @@ -118,6 +118,7 @@ def generate_itempool(world): raise NotImplementedError('Not supported yet') world.push_item('Ganon', ItemFactory('Triforce'), False) + world.get_location('Ganon').event = True world.push_item('Agahnim 1', ItemFactory('Beat Agahnim 1'), False) world.get_location('Agahnim 1').event = True world.push_item('Agahnim 2', ItemFactory('Beat Agahnim 2'), False) @@ -177,6 +178,7 @@ def generate_itempool(world): if world.goal == 'pedestal': world.push_item('Master Sword Pedestal', ItemFactory('Triforce'), False) + world.get_location('Master Sword Pedestal').event = True elif world.goal == 'triforcehunt': world.treasure_hunt_count = 20 world.treasure_hunt_icon = 'Triforce Piece'