def test_encode_no_tricks_are_removed():
    from_json = TrickLevelConfiguration.from_json(
        {
            "minimal_logic": False,
            "specific_levels": {
                "Dash": "disabled"
            }
        },
        game=RandovaniaGame.METROID_PRIME_ECHOES)

    encoded, byte_count = bitpacking.pack_results_and_bit_count(
        from_json.bit_pack_encode({}))

    assert encoded == b'\x00\x00\x00\x00'
    assert byte_count == 26

    decoder = BitPackDecoder(encoded)
    decoded = TrickLevelConfiguration.bit_pack_unpack(
        decoder, {
            "reference":
            TrickLevelConfiguration(False, {},
                                    RandovaniaGame.METROID_PRIME_ECHOES),
        })

    assert decoded.specific_levels == {}
def test_decode(trick_level_data):
    # Setup
    data, _, expected = trick_level_data

    # Run
    decoder = BitPackDecoder(data)
    result = TrickLevelConfiguration.bit_pack_unpack(
        decoder, {
            "reference":
            TrickLevelConfiguration(False, {},
                                    RandovaniaGame.METROID_PRIME_ECHOES),
        })

    # Assert
    assert result == expected
Esempio n. 3
0
async def test_round_trip_generated_patches(default_preset):
    # Setup
    preset = dataclasses.replace(
        default_preset,
        uuid=uuid.UUID('b41fde84-1f57-4b79-8cd6-3e5a78077fa6'),
        base_preset_uuid=default_preset.uuid,
        configuration=dataclasses.replace(default_preset.configuration,
                                          trick_level=TrickLevelConfiguration(
                                              minimal_logic=True,
                                              specific_levels={},
                                              game=default_preset.game,
                                          )))

    description = await generator._create_description(
        generator_params=GeneratorParameters(
            seed_number=1000,
            spoiler=True,
            presets=[preset],
        ),
        status_update=lambda x: None,
        attempts=0,
    )
    all_patches = description.all_patches

    # Run
    encoded = game_patches_serializer.serialize(all_patches)
    decoded = game_patches_serializer.decode(encoded,
                                             {0: preset.configuration})
    decoded_with_original_game = {
        i: dataclasses.replace(d, game=orig.game)
        for (i, d), orig in zip(decoded.items(), all_patches.values())
    }

    # Assert
    assert all_patches == decoded_with_original_game
def _trick_level_data(request, mocker, echoes_game_description):
    tricks = echoes_game_description.resource_database.trick[:14]
    mocker.patch(
        "randovania.layout.base.trick_level_configuration._all_tricks",
        return_value=tricks)
    return (request.param["encoded"], request.param["bit_count"],
            TrickLevelConfiguration.from_json(
                request.param["json"],
                game=RandovaniaGame.METROID_PRIME_ECHOES))
def test_set_level_for_trick_remove(echoes_resource_database):
    trick = echoes_resource_database.trick[0]
    config = TrickLevelConfiguration(False, {},
                                     RandovaniaGame.METROID_PRIME_ECHOES)

    assert config.level_for_trick(trick) == LayoutTrickLevel.DISABLED

    config = config.set_level_for_trick(trick, LayoutTrickLevel.ADVANCED)
    assert config.level_for_trick(trick) == LayoutTrickLevel.ADVANCED

    config = config.set_level_for_trick(trick, LayoutTrickLevel.DISABLED)
    assert config.level_for_trick(trick) == LayoutTrickLevel.DISABLED
Esempio n. 6
0
    def trick_resources_for_configuration(
        self,
        configuration: TrickLevelConfiguration,
        resource_database: ResourceDatabase,
    ) -> CurrentResources:
        """
        :param configuration:
        :param resource_database:
        :return:
        """

        static_resources = {}

        for trick in resource_database.trick:
            if configuration.minimal_logic:
                level = LayoutTrickLevel.maximum()
            else:
                level = configuration.level_for_trick(trick)
            static_resources[trick] = level.as_number

        return static_resources
def test_pretty_description_tricks_echoes(levels, expected):
    config = TrickLevelConfiguration(False, levels,
                                     RandovaniaGame.METROID_PRIME_ECHOES)
    assert config.pretty_description == expected
def test_pretty_description_minimal_logic():
    config = TrickLevelConfiguration(True, {},
                                     RandovaniaGame.METROID_PRIME_ECHOES)
    assert config.pretty_description == "Minimal Logic"
def test_reach_size_from_start_echoes(small_echoes_game_description,
                                      default_echoes_configuration, mocker):
    # Setup
    game = derived_nodes.remove_inactive_layers(
        small_echoes_game_description,
        default_echoes_configuration.active_layers()).get_mutable()

    mocker.patch(
        "randovania.game_description.default_database.game_description_for",
        return_value=game)
    generator = game.game.generator

    specific_levels = {
        trick.short_name: LayoutTrickLevel.maximum()
        for trick in game.resource_database.trick
    }

    def item(name: str):
        return find_resource_info_with_long_name(game.resource_database.item,
                                                 name)

    ni = NodeIdentifier.create

    def nodes(*names: str):
        def get_index(n: Node):
            return n.node_index

        result = [
            game.world_list.node_by_identifier(ni(*name.split("/")))
            for name in names
        ]
        result.sort(key=get_index)
        return result

    layout_configuration = dataclasses.replace(
        default_echoes_configuration,
        trick_level=TrickLevelConfiguration(
            minimal_logic=False,
            specific_levels=specific_levels,
            game=default_echoes_configuration.game),
        starting_location=StartingLocationList.with_elements(
            [game.starting_location],
            game=RandovaniaGame.METROID_PRIME_ECHOES,
        ))
    patches = generator.base_patches_factory.create_base_patches(
        layout_configuration, Random(15000), game, False, player_index=0)
    state = generator.bootstrap.calculate_starting_state(
        game, patches, default_echoes_configuration)
    state.resources.add_resource_gain([
        (item("Combat Visor"), 1),
        (item("Amber Translator"), 1),
        (item("Scan Visor"), 1),
        (item("Morph Ball"), 1),
        (item("Power Beam"), 1),
        (item("Charge Beam"), 1),
        (item("Grapple Beam"), 1),
        (item("Dark Beam"), 1),
        (item("Dark Ammo"), 50),
        (item("Missile"), 5),
    ])

    # Run
    reach = OldGeneratorReach.reach_from_state(game, state)
    reach_lib.collect_all_safe_resources_in_reach(reach)

    # Assert

    assert list(reach.nodes) == nodes(
        "Temple Grounds/Path of Eyes/Front of Translator Gate",
        "Temple Grounds/Path of Eyes/Lore Scan",
        "Temple Grounds/Path of Eyes/Translator Gate",
        "Temple Grounds/Path of Eyes/Door to Torvus Transport Access",
        "Temple Grounds/Torvus Transport Access/Door to Path of Eyes",
        "Temple Grounds/Torvus Transport Access/Door to Transport to Torvus Bog",
        "Temple Grounds/Torvus Transport Access/Lock - Door to Transport to Torvus Bog",
        "Temple Grounds/Transport to Torvus Bog/Door to Torvus Transport Access",
        "Temple Grounds/Transport to Torvus Bog/Lock - Door to Torvus Transport Access",
        "Temple Grounds/Transport to Torvus Bog/Elevator to Torvus Bog - Transport to Temple Grounds",
        "Torvus Bog/Transport to Temple Grounds/Elevator to Temple Grounds - Transport to Torvus Bog",
        "Torvus Bog/Transport to Temple Grounds/Door to Temple Transport Access",
        "Torvus Bog/Temple Transport Access/Door to Transport to Temple Grounds",
        "Torvus Bog/Temple Transport Access/Door to Torvus Lagoon",
        "Torvus Bog/Torvus Lagoon/Door to Temple Transport Access",
        "Torvus Bog/Torvus Lagoon/Door to Path of Roots",
        "Torvus Bog/Torvus Lagoon/Keybearer Corpse (S-Dly)",
        "Torvus Bog/Path of Roots/Door to Torvus Lagoon",
        "Torvus Bog/Path of Roots/Door to Great Bridge",
        "Torvus Bog/Path of Roots/Pickup (Missile)",
        "Torvus Bog/Path of Roots/Next to Pickup",
        "Torvus Bog/Path of Roots/Under Lore Scan",
        "Torvus Bog/Path of Roots/Lore Scan",
        "Torvus Bog/Great Bridge/Door to Path of Roots",
    )
    assert len(list(reach.safe_nodes)) == 22