예제 #1
0
def _state_game_data() -> StateGameData:
    return StateGameData(
        Mock(energy_tank=ItemResourceInfo(42, "Energy Tank", "EnergyTank", 14,
                                          None),
             item_percentage=ItemResourceInfo(47, "Item Percentage",
                                              "Percentage", 255, None)), None,
        100)
예제 #2
0
def test_basic_search_with_translator_gate(has_translator: bool,
                                           echoes_resource_database):
    # Setup
    scan_visor = echoes_resource_database.get_item(10)

    node_a = GenericNode("Node A", True, None, 0)
    node_b = GenericNode("Node B", True, None, 1)
    node_c = GenericNode("Node C", True, None, 2)
    translator_node = TranslatorGateNode("Translator Gate", True, None, 3,
                                         TranslatorGate(1), scan_visor)

    world_list = WorldList([
        World("Test World", "Test Dark World", 1, [
            Area(
                "Test Area A", False, 10, 0, True,
                [node_a, node_b, node_c, translator_node], {
                    node_a: {
                        node_b: Requirement.trivial(),
                        translator_node: Requirement.trivial(),
                    },
                    node_b: {
                        node_a: Requirement.trivial(),
                    },
                    node_c: {
                        translator_node: Requirement.trivial(),
                    },
                    translator_node: {
                        node_a: Requirement.trivial(),
                        node_c: Requirement.trivial(),
                    },
                })
        ])
    ])
    game = GameDescription(RandovaniaGame.PRIME2,
                           DockWeaknessDatabase([], [], [],
                                                []), echoes_resource_database,
                           Requirement.impossible(), None, {}, world_list)

    patches = game.create_game_patches()
    patches = patches.assign_gate_assignment({TranslatorGate(1): scan_visor})
    initial_state = State({scan_visor: 1 if has_translator else 0}, (), 99,
                          node_a, patches, None,
                          StateGameData(echoes_resource_database,
                                        game.world_list, 100))

    # Run
    reach = reach_with_all_safe_resources(game, initial_state)

    # Assert
    if has_translator:
        assert set(
            reach.safe_nodes) == {node_a, node_b, translator_node, node_c}
    else:
        assert set(reach.safe_nodes) == {node_a, node_b}
예제 #3
0
def test_basic_search_with_translator_gate(has_translator: bool, echoes_resource_database, echoes_game_patches):
    # Setup
    scan_visor = echoes_resource_database.get_item("DarkVisor")
    nc = functools.partial(NodeIdentifier.create, "Test World", "Test Area A")

    node_a = GenericNode(nc("Node A"), True, None, "", ("default",), {})
    node_b = GenericNode(nc("Node B"), True, None, "", ("default",), {})
    node_c = GenericNode(nc("Node C"), True, None, "", ("default",), {})
    translator_node = ConfigurableNode(translator_identif := nc("Translator Gate"),
                                       True, None, "", ("default",), {})

    world_list = WorldList([
        World("Test World", [
            Area("Test Area A", None, True, [node_a, node_b, node_c, translator_node],
                 {
                     node_a: {
                         node_b: Requirement.trivial(),
                         translator_node: Requirement.trivial(),
                     },
                     node_b: {
                         node_a: Requirement.trivial(),
                     },
                     node_c: {
                         translator_node: Requirement.trivial(),
                     },
                     translator_node: {
                         node_a: Requirement.trivial(),
                         node_c: Requirement.trivial(),
                     },
                 },
                 {}
                 )
        ], {})
    ])
    game = GameDescription(RandovaniaGame.METROID_PRIME_ECHOES, DockWeaknessDatabase([], {}, (None, None)),
                           echoes_resource_database, ("default",), Requirement.impossible(),
                           None, {}, None, world_list)

    patches = echoes_game_patches.assign_node_configuration({
        translator_identif: ResourceRequirement(scan_visor, 1, False)
    })
    initial_state = State({scan_visor: 1 if has_translator else 0}, (), 99,
                          node_a, patches, None, StateGameData(echoes_resource_database, game.world_list, 100, 99))

    # Run
    reach = reach_lib.reach_with_all_safe_resources(game, initial_state)

    # Assert
    if has_translator:
        assert set(reach.safe_nodes) == {node_a, node_b, translator_node, node_c}
    else:
        assert set(reach.safe_nodes) == {node_a, node_b}
예제 #4
0
    def calculate_starting_state(self, game: GameDescription,
                                 patches: GamePatches,
                                 configuration: BaseConfiguration) -> "State":
        starting_node = game.world_list.resolve_teleporter_connection(
            patches.starting_location)
        initial_resources = copy.copy(patches.starting_items)

        starting_energy, energy_per_tank = self.energy_config(configuration)

        if starting_node.is_resource_node:
            assert isinstance(starting_node, ResourceNode)
            add_resource_gain_to_current_resources(
                starting_node.resource_gain_on_collect(
                    NodeContext(
                        patches,
                        initial_resources,
                        game.resource_database,
                        game.world_list,
                    )),
                initial_resources,
            )

        initial_game_state = game.initial_states.get("Default")
        if initial_game_state is not None:
            add_resource_gain_to_current_resources(initial_game_state,
                                                   initial_resources)

        starting_state = State(
            initial_resources, (), None, starting_node, patches, None,
            StateGameData(game.resource_database, game.world_list,
                          energy_per_tank, starting_energy))

        # Being present with value 0 is troublesome since this dict is used for a simplify_requirements later on
        keys_to_remove = [
            resource for resource, quantity in initial_resources.items()
            if quantity == 0
        ]
        for resource in keys_to_remove:
            del initial_resources[resource]

        return starting_state
예제 #5
0
def calculate_starting_state(game: GameDescription, patches: GamePatches,
                             energy_per_tank: int) -> "State":
    starting_node = game.world_list.resolve_teleporter_connection(
        patches.starting_location)
    initial_resources = copy.copy(patches.starting_items)

    if isinstance(starting_node, PlayerShipNode):
        add_resource_gain_to_current_resources(
            starting_node.resource_gain_on_collect(patches, initial_resources,
                                                   game.world_list.all_nodes),
            initial_resources,
        )

    initial_game_state = game.initial_states.get("Default")
    if initial_game_state is not None:
        add_resource_gain_to_current_resources(initial_game_state,
                                               initial_resources)

    starting_state = State(
        initial_resources, (), 99 +
        (100 * initial_resources.get(game.resource_database.energy_tank, 0)),
        starting_node, patches, None,
        StateGameData(
            game.resource_database,
            game.world_list,
            energy_per_tank,
        ))

    # Being present with value 0 is troublesome since this dict is used for a simplify_requirements later on
    keys_to_remove = [
        resource for resource, quantity in initial_resources.items()
        if quantity == 0
    ]
    for resource in keys_to_remove:
        del initial_resources[resource]

    return starting_state
예제 #6
0
def _state_game_data(empty_patches) -> StateGameData:
    return StateGameData(empty_patches.game.resource_database,
                         empty_patches.game.world_list, 100, 99)