def buildByCondition(condition, y, blockID):
    buildPositions = np.where(condition)
    for p in zip(*buildPositions):
        x = area[0] + p[0]
        z = area[1] + p[1]
        if BUILD:
            interfaceUtils.setBlock(x, y, z, blockID)
    interfaceUtils.sendBlocks()
Exemple #2
0
def buildHouse(x1, y1, z1, x2, y2, z2):
    """Build a small house."""
    # floor
    interfaceUtils.fill(x1, y1, z1, x2 - 1, y1, z2 - 1, "cobblestone")

    # walls
    interfaceUtils.fill(x1 + 1, y1, z1, x2 - 2, y2, z1, "oak_planks")
    interfaceUtils.fill(x1 + 1, y1, z2 - 1, x2 - 2, y2, z2 - 1, "oak_planks")
    interfaceUtils.fill(x1, y1, z1 + 1, x1, y2, z2 - 2, "oak_planks")
    interfaceUtils.fill(x2 - 1, y1, z1 + 1, x2 - 1, y2, z2 - 2, "oak_planks")

    # corners
    interfaceUtils.fill(x1, y1, z1, x1, y2, z1, "oak_log")
    interfaceUtils.fill(x2 - 1, y1, z1, x2 - 1, y2, z1, "oak_log")
    interfaceUtils.fill(x1, y1, z2 - 1, x1, y2, z2 - 1, "oak_log")
    interfaceUtils.fill(x2 - 1, y1, z2 - 1, x2 - 1, y2, z2 - 1, "oak_log")

    # clear interior
    for y in range(y1 + 1, y2):
        for x in range(x1 + 1, x2 - 1):
            for z in range(z1 + 1, z2 - 1):
                # check what's at that place and only delete if not air
                if "air" not in interfaceUtils.getBlock(x, y, z):
                    interfaceUtils.setBlock(x, y, z, "air")

    # roof
    if x2 - x1 < z2 - z1:  # if the house is longer in Z-direction
        for i in range(0, (1 - x1 + x2) // 2):
            interfaceUtils.fill(x1 + i, y2 + i, z1, x2 - 1 - i, y2 + i, z2 - 1,
                                "bricks")
    else:
        # same as above but with x and z swapped
        for i in range(0, (1 - z1 + z2) // 2):
            interfaceUtils.fill(x1, y2 + i, z1 + i, x2 - 1, y2 + i, z2 - 1 - i,
                                "bricks")

    if interfaceUtils.isBuffering():
        interfaceUtils.sendBlocks()
    floor = cv2.dilate(floor, strctElmt3x3)

    cv2.imshow("layers", (mapUtils.normalize(walls) * 255).astype(np.uint8))
    cv2.waitKey(1)

    for dx in range(area[2]):
        for dz in range(area[3]):
            x = area[0] + dx
            z = area[1] + dz
            y = yBase + dy

            # color = softPickBlockColor(dy / yHeight)
            # color = "light_gray"

            # block = ("%s_concrete" % color) if wallNoiseMask[dx, dz] else "light_gray_stained_glass"
            block = "smooth_stone" if wallNoiseMask[
                dx, dz] else "light_gray_stained_glass"

            if floor[dx, dz] > 0 and not roof[dx, dz] > 0:
                interfaceUtils.placeBlockBatched(x, y, z,
                                                 "light_gray_concrete")
            elif walls[dx, dz] > 0:
                interfaceUtils.placeBlockBatched(x, y, z, block)
            elif roof[dx, dz] > 0:
                interfaceUtils.placeBlockBatched(x, y, z,
                                                 "dark_prismarine_slab")

cv2.destroyWindow("layers")

interfaceUtils.sendBlocks()
                    interfaceUtils.placeBlockBatched(area[0] + x, ry - 1 + i,
                                                     area[1] + z,
                                                     "gray_concrete", 1000)
            # walkway decoration
            wmapVal = int(walkwMap[(x, z)])
            if wmapVal % 2 == 1:
                # wall adjacent
                dir = int((wmapVal - 1) / 2)
                cdir1 = cardinals[dir]
                cdir2 = cardinals[(dir + 2) % 4]
                interfaceUtils.placeBlockBatched(
                    area[0] + x, ry, area[1] + z,
                    "polished_blackstone_stairs[facing=%s]" % cdir1, 1000)
                interfaceUtils.placeBlockBatched(area[0] + x, ry + 1,
                                                 area[1] + z,
                                                 "end_rod[facing=%s]" % cdir2,
                                                 1000)
                interfaceUtils.placeBlockBatched(area[0] + x, ry + 2,
                                                 area[1] + z,
                                                 "polished_blackstone_slab",
                                                 1000)
            elif wmapVal % 2 == 0 and wmapVal != 4:
                # inner corner
                for i in range(3):
                    interfaceUtils.placeBlockBatched(area[0] + x, ry + i,
                                                     area[1] + z,
                                                     "polished_blackstone",
                                                     1000)

    interfaceUtils.sendBlocks()  # send remaining blocks in buffer
                _water = 100
            _y -= 1

        _block = ws.getBlockAt(_x, _y, _z)
        _food = ft.getFood(_x, _y, _z)

        _score = _food + _y/20 + utils.mdist2d(_x, _z, *center) - _water
        location.append((-1*_score, (_x, _y, _z)))
    location.sort()

    location = location[0][1]

    # DEBUG
    for _y in range(location[1]+6, location[1]+16):
        iu.setBlock(location[0],_y,location[2],"minecraft:glowstone")
    iu.sendBlocks()

    steps = set()

    # aco = acoEngine.ACO(ws, ft, location)
    dfs = dfsEngine.DFS(ws, ft, location)
    for i in range(10):
        food, s = dfs.runDFS(location)
        steps = steps.union(s)


    for s in steps:
        iu.setBlock(*s, "minecraft:netherrack")
    iu.sendBlocks()
    print("The Kraken has landed at {}.".format(location))