def simulate_until_max_t(
        max_t, _simulate_until_attractor_or_target_substate_or_max_t, initial_state,
        perturbed_nodes_by_t, predecessor_node_lists, truth_tables):

    """
    Simulate for given number of time steps.

    :param max_t: time after which to stop the simulation
    :param _simulate_until_attractor_or_target_substate_or_max_t: [function] to simulate
        until attractor or max_t
    :param initial_state: initial network state
    :param perturbed_nodes_by_t: perturbations of network nodes
    :param predecessor_node_lists: predecessor nodes for each node
    :param truth_tables: truth tables of node update rules
    :return: simulation states
    """
    states, state_codes_since_last_perturbation, *_ = \
        _simulate_until_attractor_or_target_substate_or_max_t(
            initial_state, perturbed_nodes_by_t, predecessor_node_lists, truth_tables)
    last_simulation_t = len(states) - 1

    if last_simulation_t < max_t:
        # Find attractor states.
        attractor_instance_first_state_code = state_codes_since_last_perturbation[-1]
        attractor_l = len(state_codes_since_last_perturbation) - \
            state_codes_since_last_perturbation.index(attractor_instance_first_state_code) - 1
        attractor_instance_states = states[-attractor_l:]
        # Deduce remaining simulation states.
        remaining_l_to_simulate = max_t - last_simulation_t
        n_attractor_instance_repetitions, n_leftover_states = divmod(remaining_l_to_simulate,
                                                                     len(attractor_instance_states))
        states.extend(attractor_instance_states * n_attractor_instance_repetitions +
                      attractor_instance_states[:n_leftover_states])

    return states