def test_reach_size_from_start(echoes_game_description, default_layout_configuration, minimal_logic, nodes, safe_nodes): # Setup specific_levels = { trick.short_name: LayoutTrickLevel.HYPERMODE for trick in echoes_game_description.resource_database.trick } layout_configuration = dataclasses.replace( default_layout_configuration, trick_level_configuration=TrickLevelConfiguration( minimal_logic=minimal_logic, specific_levels=specific_levels if not minimal_logic else {}), ) player_pool = generator.create_player_pool(Random(15000), layout_configuration, 0) game, state = logic_bootstrap(layout_configuration, player_pool.game, player_pool.patches) # Run reach = GeneratorReach.reach_from_state(game, state) # Assert assert len(list(reach.nodes)) >= nodes assert len(list(reach.safe_nodes)) >= safe_nodes
def __init__(self, persistence_path: Path, layout_configuration: LayoutConfiguration): super().__init__() self.setupUi(self) set_default_window_icon(self) self._collected_pickups = {} self._widget_for_pickup = {} self._actions = [] self._asset_id_to_item = {} self._node_to_item = {} self.layout_configuration = layout_configuration self.persistence_path = persistence_path player_index = 0 # FIXME try: player_pool = generator.create_player_pool(None, self.layout_configuration, player_index) except base_patches_factory.MissingRng as e: raise InvalidLayoutForTracker("Layout is configured to have random {}, " "but that isn't supported by the tracker.".format(e)) pool_patches = player_pool.patches self.game_description, self._initial_state = logic_bootstrap(layout_configuration, player_pool.game, pool_patches) self.logic = Logic(self.game_description, layout_configuration) self._initial_state.resources["add_self_as_requirement_to_resources"] = 1 self.menu_reset_action.triggered.connect(self._confirm_reset) self.resource_filter_check.stateChanged.connect(self.update_locations_tree_for_reachable_nodes) self.hide_collected_resources_check.stateChanged.connect(self.update_locations_tree_for_reachable_nodes) self.undo_last_action_button.clicked.connect(self._undo_last_action) self.configuration_label.setText("Trick Level: {}; Elevators: Vanilla; Starts with:\n{}".format( layout_configuration.trick_level_configuration.global_level.value, ", ".join( resource.short_name for resource in pool_patches.starting_items.keys() ) )) self.setup_pickups_box(player_pool.pickups) self.setup_possible_locations_tree() self._starting_nodes = { node for node in self.game_description.world_list.all_nodes if node.is_resource_node and node.resource() in self._initial_state.resources } persistence_path.mkdir(parents=True, exist_ok=True) previous_state = _load_previous_state(persistence_path, layout_configuration) if not self.apply_previous_state(previous_state): with persistence_path.joinpath("layout_configuration.json").open("w") as layout_file: json.dump(layout_configuration.as_json, layout_file) self._add_new_action(self._initial_state.node)
def __init__(self, persistence_path: Path, layout_configuration: LayoutConfiguration): super().__init__() self.setupUi(self) set_default_window_icon(self) self._collected_pickups = {} self._widget_for_pickup = {} self._actions = [] self._asset_id_to_item = {} self._node_to_item = {} self.layout_configuration = layout_configuration self.persistence_path = persistence_path player_pool = generator.create_player_pool(Random(0), self.layout_configuration, 0) pool_patches = player_pool.patches self.game_description, self._initial_state = logic_bootstrap( layout_configuration, player_pool.game, pool_patches) self.logic = Logic(self.game_description, layout_configuration) self._initial_state.resources[ "add_self_as_requirement_to_resources"] = 1 self.menu_reset_action.triggered.connect(self._confirm_reset) self.resource_filter_check.stateChanged.connect( self.update_locations_tree_for_reachable_nodes) self.hide_collected_resources_check.stateChanged.connect( self.update_locations_tree_for_reachable_nodes) self.undo_last_action_button.clicked.connect(self._undo_last_action) self.configuration_label.setText( "Trick Level: {}; Starts with:\n{}".format( layout_configuration.trick_level_configuration. pretty_description, ", ".join(resource.short_name for resource in pool_patches.starting_items.keys()))) self.setup_pickups_box(player_pool.pickups) self.setup_possible_locations_tree() self.setup_elevators() self.setup_translator_gates() persistence_path.mkdir(parents=True, exist_ok=True) previous_state = _load_previous_state(persistence_path, layout_configuration) if not self.apply_previous_state(previous_state): self.setup_starting_location(None) with persistence_path.joinpath("layout_configuration.json").open( "w") as layout_file: json.dump(layout_configuration.as_json, layout_file) self._add_new_action(self._initial_state.node)
async def test_run_filler( echoes_game_description, default_layout_configuration, mocker, ): # Setup rng = Random(5000) status_update = MagicMock() logbook_nodes = [ node for node in echoes_game_description.world_list.all_nodes if isinstance(node, LogbookNode) ] player_pools = { 0: create_player_pool(rng, default_layout_configuration, 0, 1), } initial_pickup_count = len(player_pools[0].pickups) patches = echoes_game_description.create_game_patches() patches = patches.assign_hint( logbook_nodes[0].resource(), Hint(HintType.LOCATION, None, PickupIndex(0))) action_log = (MagicMock(), MagicMock()) player_state = MagicMock() player_state.index = 0 player_state.game = player_pools[0].game player_state.pickups_left = runner._split_expansions( player_pools[0].pickups)[0] player_state.scan_asset_initial_pickups = {} mocker.patch( "randovania.generator.filler.runner.retcon_playthrough_filler", autospec=True, return_value=({ player_state: patches }, action_log)) # Run filler_result = await runner.run_filler(rng, player_pools, status_update) assert filler_result.action_log == action_log assert len(filler_result.player_results) == 1 result_patches = filler_result.player_results[0].patches remaining_items = filler_result.player_results[0].unassigned_pickups # Assert assert len(result_patches.hints) == len(logbook_nodes) assert [ hint for hint in result_patches.hints.values() if hint.precision is None ] == [] assert initial_pickup_count == len(remaining_items) + len( result_patches.pickup_assignment.values())
def test_run_filler( mock_retcon_playthrough_filler: MagicMock, echoes_game_description, default_layout_configuration, ): # Setup rng = Random(5000) status_update = MagicMock() logbook_nodes = [ node for node in echoes_game_description.world_list.all_nodes if isinstance(node, LogbookNode) ] player_pools = { 0: create_player_pool(rng, default_layout_configuration, 0), } initial_pickup_count = len(player_pools[0].pickups) patches = echoes_game_description.create_game_patches() patches = patches.assign_hint( logbook_nodes[0].resource(), Hint(HintType.LOCATION, None, PickupIndex(0))) action_log = (MagicMock(), MagicMock()) mock_retcon_playthrough_filler.return_value = {0: patches}, action_log # Run filler_result = runner.run_filler(rng, player_pools, status_update) assert filler_result.action_log == action_log assert len(filler_result.player_results) == 1 result_patches = filler_result.player_results[0].patches remaining_items = filler_result.player_results[0].unassigned_pickups # Assert assert len(result_patches.hints) == len(logbook_nodes) assert [ hint for hint in result_patches.hints.values() if hint.precision is None ] == [] assert initial_pickup_count == len(remaining_items) + len( result_patches.pickup_assignment.values())
def test_reach_size_from_start(echoes_game_description, default_layout_configuration): # Setup layout_configuration = dataclasses.replace( default_layout_configuration, trick_level_configuration=TrickLevelConfiguration( LayoutTrickLevel.HYPERMODE), ) player_pool = generator.create_player_pool(Random(15000), layout_configuration, 0) game, state = logic_bootstrap(layout_configuration, player_pool.game, player_pool.patches) # Run reach = GeneratorReach.reach_from_state(game, state) # Assert assert len(list(reach.nodes)) == 44 assert len(list(reach.safe_nodes)) == 5