Пример #1
0
def add_resources(the_map: world.Map, food_threshold=0.85, money_threshold=0.15):
    for x, y in itertools.product(range(the_map.width), range(the_map.height)):
        if the_map.get(x, y).is_wall:
            the_noise = mn.simplex_noise_2d(x, y)
            if the_noise > food_threshold:
                the_map.set(FoodTile(), x, y, 0)
            elif the_noise < money_threshold:
                the_map.set(MoneyTile(), x, y, 0)
    return the_map
Пример #2
0
def make_crevasse(the_map: world.Map):
    h = the_map.height
    w = the_map.width
    for y in range(h):
        the_noise = mn.simplex_noise_1d(y, the_map.seed) * (w / 2)  # Output from 0 to width/2
        border = (w - the_noise) / 2.0  # Space on either side of the crevice
        for x in range(w):
            if border < x < w - border:
                the_map.set(CrevasseTile(), x, y, 0)
    return the_map
Пример #3
0
def add_resources(the_map: world.Map,
                  food_threshold=0.85,
                  money_threshold=0.15):
    for x, y in itertools.product(range(the_map.width), range(the_map.height)):
        if the_map.get(x, y).is_wall:
            the_noise = mn.simplex_noise_2d(x, y)
            if the_noise > food_threshold:
                the_map.set(FoodTile(), x, y, 0)
            elif the_noise < money_threshold:
                the_map.set(MoneyTile(), x, y, 0)
    return the_map
Пример #4
0
def add_forts(the_map: world.Map, food_range=4, money_range=4, fort_range=6):
    max_range = max(food_range, money_range, fort_range)
    for x, y in itertools.product(range(the_map.width), range(the_map.height)):
        if not the_map.get(x, y).is_wall:
            food = 0
            money = 0
            fort = 0
            for ox, oy in itertools.product(get_safe_range(x, the_map.width, max_range),
                                            get_safe_range(y, the_map.height, max_range)):
                if max(abs(ox - x), abs(oy - y)) <= food_range and \
                        isinstance(the_map.get(ox, oy), resource.FoodTile().__class__):
                    food += 1
                if max(abs(ox - x), abs(oy - y)) <= money_range and \
                        isinstance(the_map.get(ox, oy), resource.MoneyTile().__class__):
                    money += 1
                if max(abs(ox - x), abs(oy - y)) <= fort_range and \
                        isinstance(the_map.get(ox, oy), FortTile().__class__):
                    fort += 1
            if not fort and money > 2 and food > 2 and food + money > 5:
                the_map.set(FortTile(), x, y, 0)

    return the_map
Пример #5
0
def add_forts(the_map: world.Map, food_range=4, money_range=4, fort_range=6):
    max_range = max(food_range, money_range, fort_range)
    for x, y in itertools.product(range(the_map.width), range(the_map.height)):
        if not the_map.get(x, y).is_wall:
            food = 0
            money = 0
            fort = 0
            for ox, oy in itertools.product(
                    get_safe_range(x, the_map.width, max_range),
                    get_safe_range(y, the_map.height, max_range)):
                if max(abs(ox - x), abs(oy - y)) <= food_range and \
                        isinstance(the_map.get(ox, oy), resource.FoodTile().__class__):
                    food += 1
                if max(abs(ox - x), abs(oy - y)) <= money_range and \
                        isinstance(the_map.get(ox, oy), resource.MoneyTile().__class__):
                    money += 1
                if max(abs(ox - x), abs(oy - y)) <= fort_range and \
                        isinstance(the_map.get(ox, oy), FortTile().__class__):
                    fort += 1
            if not fort and money > 2 and food > 2 and food + money > 5:
                the_map.set(FortTile(), x, y, 0)

    return the_map