Exemple #1
0
def grow_plants(play_area, num, plant_type, bias):
    """
    :param play_area:
    :param num:
    :param plant_type:
    :param bias:
    :return: a list of spawned plants of given type
    """
    normal_distribution = NormalDist(0.5, 0.15)

    plant_db = {}

    dist_rolls = normal_distribution.samples(num)

    if bias == 'edges':
        dist_rolls = inverse_probabilities(dist_rolls)

    for i in range(num):
        location = get_location_in_circle(dist_rolls[i], play_area)
        new_p = Decoration(location, plant_type)
        plant_db[location] = new_p

    clean_up_db = {}

    for p in plant_db.values():
        p_loc = p.rect.left, p.rect.top
        if p_loc not in clean_up_db:
            clean_up_db[p_loc] = p

    return clean_up_db
Exemple #2
0
def get_control(x_):
    seed = x_[0]["close"]
    generated = [{"datetime": r["datetime"], "close": r["close"]} for r in x_]
    try:
        (mean_, stdev_) = dist(x_, 0, len(x_) - 1)
    except (StatisticsError, ValueError, ZeroDivisionError):
        mean_, stdev_ = (0, 1)

    dist_ = NormalDist(mean_, stdev_)
    samples = dist_.samples(len(x_))

    for i in range(1, len(samples)):
        seed *= round(exp(samples[i]), 2)
        generated[i]["close"] = seed

    control = rsi(generated)

    return (control, generated)
Exemple #3
0
def normal_distribution_flower_spawning_strategy(play_area, flower_num):
    """
    Returns a normal-distribution generated list of flowers
    :param play_area:
    :return: list of spawned flowers
    """
    normal_distribution = NormalDist(0.5, 0.15)
    flower_database = {}

    dist_rolls = normal_distribution.samples(flower_num)

    for i in range(flower_num):
        location = get_location_in_circle(dist_rolls[i], play_area)
        new_f = Flower(location)
        flower_database[location] = new_f

    clean_up_table = {}

    for f in flower_database.values():
        f_loc = f.rect.left, f.rect.top
        if f_loc not in clean_up_table:
            clean_up_table[f_loc] = f

    return clean_up_table