Beispiel #1
0
def test_run_filler(mock_retcon_playthrough_filler: MagicMock,
                    echoes_game_description,
                    pickup
                    ):
    # Setup
    configuration = LayoutConfiguration.default()
    rng = Random(5000)
    status_update = MagicMock()
    item_pool = [pickup]
    patches = GamePatches.with_game(echoes_game_description)

    logbook_nodes = [node for node in echoes_game_description.world_list.all_nodes if isinstance(node, LogbookNode)]

    mock_retcon_playthrough_filler.return_value = patches.assign_hint(
        logbook_nodes[0].resource(), Hint(HintType.LOCATION, None, PickupIndex(0))
    ).assign_pickup_assignment({PickupIndex(1): pickup})

    # Run
    result_patches, remaining_items = runner.run_filler(configuration, echoes_game_description,
                                                        item_pool, patches,
                                                        rng, status_update)

    # Assert
    assert len(result_patches.hints) == len(logbook_nodes)
    assert [hint for hint in patches.hints.values()
            if hint.item_precision is None or hint.location_precision is None] == []
    assert remaining_items == [pickup]
Beispiel #2
0
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, 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 = {}

    mock_retcon_playthrough_filler.return_value = {
        player_state: 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())
Beispiel #3
0
def _retryable_create_patches(
    configuration: LayoutConfiguration,
    game: GameDescription,
    rng: Random,
    status_update: Callable[[str], None],
) -> Tuple[GamePatches, List[PickupEntry]]:
    """
    Runs the rng-dependant parts of the generation, with retries
    :param configuration:
    :param game:
    :param rng:
    :param status_update:
    :return:
    """
    base_patches = base_patches_factory.create_base_patches(
        configuration, rng, game)
    pool_patches, item_pool = pool_creator.calculate_item_pool(
        configuration, game.resource_database, base_patches)
    _validate_item_pool_size(item_pool, game)
    return run_filler(configuration, game, item_pool, pool_patches, rng,
                      status_update)
Beispiel #4
0
def _retryable_create_patches(rng: Random,
                              presets: Dict[int, Preset],
                              status_update: Callable[[str], None],
                              ) -> FillerResults:
    """
    Runs the rng-dependant parts of the generation, with retries
    :param rng:
    :param presets:
    :param status_update:
    :return:
    """
    player_pools: Dict[int, PlayerPool] = {}

    for player_index, player_preset in presets.items():
        status_update(f"Creating item pool for player {player_index + 1}")
        player_pools[player_index] = create_player_pool(rng, player_preset.layout_configuration, player_index)

    for player_pool in player_pools.values():
        _validate_item_pool_size(player_pool.pickups, player_pool.game)

    return run_filler(rng, player_pools, status_update)