コード例 #1
0
ファイル: validate.py プロジェクト: randovania/randovania
def validate_command_logic(args):
    debug.set_level(args.debug)

    description = LayoutDescription.from_file(args.layout_file)
    if description.player_count != 1:
        raise ValueError(
            f"Validator does not support layouts with more than 1 player.")

    configuration = description.get_preset(0).configuration
    patches = description.all_patches[0]
    total_times = []

    final_state_by_resolve = None
    for _ in range(args.repeat):
        before = time.perf_counter()
        final_state_by_resolve = asyncio.run(
            resolver.resolve(configuration=configuration, patches=patches))
        after = time.perf_counter()
        total_times.append(after - before)
        print("Took {:.3f} seconds. Game is {}.".format(
            total_times[-1], "possible"
            if final_state_by_resolve is not None else "impossible"))
    if args.repeat > 1:
        cli_lib.print_report_multiple_times(total_times)

    if args.repeat < 1:
        raise ValueError("Expected at least 1 repeat")
    return 0 if final_state_by_resolve is not None else 1
コード例 #2
0
async def generate_and_validate_description(
    generator_params: GeneratorParameters,
    status_update: Optional[Callable[[str], None]],
    validate_after_generation: bool,
    timeout: Optional[int] = 600,
    attempts: int = 15,
) -> LayoutDescription:
    """
    Creates a LayoutDescription for the given Permalink.
    :param generator_params:
    :param status_update:
    :param validate_after_generation:
    :param timeout: Abort generation after this many seconds.
    :param attempts: Attempt this many generations.
    :return:
    """
    if status_update is None:
        status_update = id

    try:
        result = await _create_description(
            generator_params=generator_params,
            status_update=status_update,
            attempts=attempts,
        )
    except UnableToGenerate as e:
        raise GenerationFailure(
            "Could not generate a game with the given settings",
            generator_params=generator_params,
            source=e) from e

    if validate_after_generation and generator_params.player_count == 1:
        final_state_async = resolver.resolve(
            configuration=generator_params.get_preset(0).configuration,
            patches=result.all_patches[0],
            status_update=status_update,
        )
        try:
            final_state_by_resolve = await asyncio.wait_for(
                final_state_async, timeout)
        except asyncio.TimeoutError as e:
            raise GenerationFailure(
                "Timeout reached when validating possibility",
                generator_params=generator_params,
                source=e) from e

        if final_state_by_resolve is None:
            raise GenerationFailure(
                "Generated game was considered impossible by the solver",
                generator_params=generator_params,
                source=ImpossibleForSolver())

    return result
コード例 #3
0
ファイル: validate.py プロジェクト: juliabenton/randovania
def validate_command_logic(args):
    debug.set_level(args.debug)
    data = prime_database.decode_data_file(args)
    game = data_reader.decode_data(data)

    description = LayoutDescription.from_file(args.layout_file)
    configuration = description.permalink.layout_configuration
    patches = description.patches

    final_state_by_resolve = resolver.resolve(configuration=configuration,
                                              game=game,
                                              patches=patches)
    print(final_state_by_resolve)
コード例 #4
0
ファイル: test_resolver.py プロジェクト: JaggerTSG/confusino
def test_resolver_with_log_file(test_files_dir):
    # Setup
    debug.set_level(0)

    description = LayoutDescription.from_file(test_files_dir.joinpath("log_files", "seed_a.json"))
    configuration = description.permalink.presets[0].layout_configuration
    patches = description.all_patches[0]

    # Run
    final_state_by_resolve = resolver.resolve(configuration=configuration,
                                              patches=patches)

    # Assert
    assert final_state_by_resolve is not None
コード例 #5
0
def validate_command_logic(args):
    debug.set_level(args.debug)

    description = LayoutDescription.from_file(args.layout_file)

    if description.permalink.player_count != 1:
        raise ValueError(f"Validator does not support layouts with more than 1 player.")

    configuration = description.permalink.presets[0].layout_configuration
    patches = description.all_patches[0]

    final_state_by_resolve = resolver.resolve(
        configuration=configuration,
        patches=patches
    )
    print(final_state_by_resolve)
コード例 #6
0
def test_resolver_with_log_file(test_files_dir):
    # Setup
    debug.set_level(0)

    description = LayoutDescription.from_file(
        test_files_dir.joinpath("log_files", "seed_a.json"))
    configuration = description.permalink.layout_configuration
    game = data_reader.decode_data(configuration.game_data)
    patches = description.patches

    # Run
    final_state_by_resolve = resolver.resolve(configuration=configuration,
                                              game=game,
                                              patches=patches)

    # Assert
    assert final_state_by_resolve is not None
コード例 #7
0
ファイル: echoes.py プロジェクト: xisi/randovania
def validate_command_logic(args):
    debug._DEBUG_LEVEL = args.debug
    data = prime_database.decode_data_file(args)
    game = data_reader.decode_data(data)

    if args.layout_file is not None:
        description = LayoutDescription.from_file(Path(args.layout_file))
        configuration = description.permalink.layout_configuration
        patches = description.patches
    else:
        configuration = LayoutConfiguration.default()
        patches = GamePatches.with_game(game).assign_pickup_assignment(
            game.pickup_database.original_pickup_mapping)

    final_state_by_resolve = resolver.resolve(configuration=configuration,
                                              game=game,
                                              patches=patches)
    print(final_state_by_resolve)
コード例 #8
0
def validate_command_logic(args):
    debug.set_level(args.debug)

    description = LayoutDescription.from_file(args.layout_file)
    if description.player_count != 1:
        raise ValueError(
            f"Validator does not support layouts with more than 1 player.")

    configuration = description.get_preset(0).configuration
    patches = description.all_patches[0]

    before = time.perf_counter()
    final_state_by_resolve = asyncio.run(
        resolver.resolve(configuration=configuration, patches=patches))
    after = time.perf_counter()
    print("Took {} seconds. Game is {}.".format(
        after - before,
        "possible" if final_state_by_resolve is not None else "impossible"))
    return 0 if final_state_by_resolve is not None else 1