コード例 #1
0
def evaluate_to_sun(
        individual: (Node, List[Node]), pop_coord, block_buffer: BlockBuffer):
    root = individual[0]

    # Place the sun
    sun_coordinate = (pop_coord[0] - 10, pop_coord[1] + 10, pop_coord[2] - 10)
    block_buffer.add_block(sun_coordinate, 0, GOLD_BLOCK)
    block_buffer.send_to_server()

    blocks = block_buffer.get_cube_info(
        pop_coord,
        (sun_coordinate[0] - 1, sun_coordinate[1] + 1, sun_coordinate[2] - 1))

    _sun = [b for b in blocks if b.type == GOLD_BLOCK]
    assert len(_sun) == 1, "no sun found"
    _sun = _sun[0]

    closest_to_sun = float("inf")
    for b in blocks:
        if b.type != AIR and b.type != GOLD_BLOCK:
            dist = (b.position.x - _sun.position.x) ** 2 + \
                   (b.position.y - _sun.position.y) ** 2 + \
                   (b.position.z - _sun.position.z) ** 2
            dist = dist**0.5
            if dist < closest_to_sun:
                closest_to_sun = dist

    return closest_to_sun
コード例 #2
0
def show_population(population, coordinates, block_buffer: BlockBuffer):
    root_nodes_pop = list(zip(*population))
    roots_and_coordinates = zip(root_nodes_pop[0], coordinates)
    buffer_blocks_fn = lambda r: set_nodes_as_blocks(r[0], r[1], block_buffer)
    list(map(buffer_blocks_fn, roots_and_coordinates))
    block_buffer.send_to_server()