예제 #1
0
def cubical(model, high=False):
    (pos1, pos2) = bounding_box(model)

    width = pos2.x - pos1.x + 1
    height = pos2.y - pos1.y + 1
    depth = pos2.z - pos1.z + 1

    (x_cur, x_next) = (0, pos1.x)
    (y_cur, y_next) = (0, pos2.y + 1)
    (z_cur, z_next) = (0, pos1.z)

    prog = move_x(pos1.x)
    prog += move_z(pos1.z - 1)

    if high:
        prog += single(Flip())

    prog += clear_all(model, pos1.x, 0, pos1.z - 1, width, height, depth)

    if high:
        prog += single(Flip())

    prog += move_x(-pos1.x)
    prog += move_z(-pos1.z + 1)

    return prog + single(Halt())
예제 #2
0
def clear_all_squads(model, x, y, z, width, height, depth) -> GroupProgram:
    deltax = 0
    prog = single()
    while width > 0:
        last = width <= SQUAD_W
        this_w = min(SQUAD_W, width)
        prog += execute_squad(model, x + deltax, y, z, this_w, height, depth,
                              39)
        if not last:
            prog += move_x(this_w)
            deltax += this_w
        width -= this_w

    prog += move_x(-deltax)
    return prog
예제 #3
0
def clear_all(model, x, y, z, width, height, depth) -> GroupProgram:
    (full_w, last_w) = divmod(width, G_DIST + 1)

    deltax = 0
    prog = single()
    for i in range(full_w):
        last = not last_w and i == full_w - 1
        prog += clear_forward(model, x + deltax, y, z, G_DIST + 1, height, depth)
        if not last:
            prog += move_x(G_DIST + 1)
            deltax += (G_DIST + 1)
    if last_w:
        prog += clear_forward(model, x + deltax, y, z, last_w, height, depth)

    prog += move_x(-deltax)
    return prog
예제 #4
0
def distribute_roots(x, y, z, full_w, last_w, seeds):
    if full_w == 0: return single()
    if full_w == 1 and last_w == 0: return single()

    return +single(Fission(Diff(-1,0,0),6)) + \
           (+single(Fission(Diff(1,0,0),max(seeds-7-1,0))) // single()) + \
           (-(single(FusionP(Diff(-1,0,0))) // single(FusionS(Diff(1,0,0)))) // (move_x(G_DIST) + distribute_roots(x+G_DIST, y, z, full_w - 1, last_w, seeds-7-1)))
예제 #5
0
def collapse_cube(width, height, depth):
    # Move 2 up to 1 (4 to 3, 6 to 5, 8 to 7)
    prog_contract_up = (single() // move_y(height - 1)) + -(
        single(FusionP(Diff(0, -1, 0))) // single(FusionS(Diff(0, 1, 0))))
    # Move 3 back to 1 (7 to 5)
    prog_contract_back = (single() // move_z(-depth)) + -(
        single(FusionP(Diff(0, 0, 1))) // single(FusionS(Diff(0, 0, -1))))
    # Move 5 left to 1
    prog_contract_left = (single() // move_x(-width + 2)) + -(
        single(FusionP(Diff(1, 0, 0))) // single(FusionS(Diff(-1, 0, 0))))

    return (prog_contract_up**4) + (prog_contract_back**2) + prog_contract_left
예제 #6
0
def deploy_cube(model, x, y, z, width, height, depth):
    prog7  = move_z(depth) + spawn_down(model, x + (width-1), y, z + (depth+1)) + \
             (single() // drill_down(model, x + (width-1), y-1, z + (depth+1), height-1))

    prog57 = move_x(width-2) + spawn_down(model, x + (width-1), y, z) + \
             (+single(Fission(Diff(0,0,1), 1)) // single()) + \
             (single() // move_y(-height+1) // prog7)

    prog3  = move_z(depth) + spawn_down(model, x, y, z + (depth+1)) + \
             (single() // drill_down(model, x, y - 1, z + (depth+1), height-1))

    prog1  = +single(Fission(Diff(0,-1,0), 0)) + \
             (+single(Fission(Diff(0,0,1), 1)) // single()) + \
             (+single(Fission(Diff(1,0,0), 3)) // single() // single()) + \
             (single() // move_y(-height+1) // prog3 // prog57)

    return prog1
예제 #7
0
def clear_cube_below(model, x, y, z, width, height, depth) -> GroupProgram:
    logging.debug("Cube at x=%d y=%d z=%d, %d x %d x %d", x,y,z,width,height,depth)
    assert width <= G_DIST + 1 and height <= G_DIST + 1 and depth <= G_DIST + 1
    # assert depth > 1
    # assert height > 1
    # assert width > 1

    # THIS IS A STUPID HACK FOR ABOVE (see also prog_fini)
    prog_init = single()
    prog_fini = single()
    if depth == 1:
        depth += 1
        prog_init += move_z(-1)
        prog_fini += move_z(+1)
        z -= 1
    if width == 1:
        width += 1
        prog_init += move_x(-1)
        prog_fini += move_x(+1)
        x -= 1
    if height == 1:
        height += 1
        prog_init += move_y(+1)
        y += 1

    prog7  = move_z(depth) + spawn_down(model, x + (width-1), y, z + (depth+1)) + \
             (single() // drill_down(model, x + (width-1), y-1, z + (depth+1), height-1))

    prog57 = move_x(width-2) + spawn_down(model, x + (width-1), y, z) + \
             (+single(Fission(Diff(0,0,1), 1)) // single()) + \
             (single() // move_y(-height+1) // prog7)

    prog3  = move_z(depth) + spawn_down(model, x, y, z + (depth+1)) + \
             (single() // drill_down(model, x, y - 1, z + (depth+1), height-1))

    prog1  = +single(Fission(Diff(0,-1,0), 0)) + \
             (+single(Fission(Diff(0,0,1), 1)) // single()) + \
             (+single(Fission(Diff(1,0,0), 3)) // single() // single()) + \
             (single() // move_y(-height+1) // prog3 // prog57)

    prog_expand = prog1

    prog_clear = single(GVoid(Diff(0,-1, 1), Diff(width-1,-height+1,depth-1)))   // \
                 single(GVoid(Diff(0, 0, 1), Diff(width-1,height-1,depth-1)))    // \
                 single(GVoid(Diff(0,-1,-1), Diff(width-1,-height+1,-depth+1)))  // \
                 single(GVoid(Diff(0, 0,-1), Diff(width-1,height-1,-depth+1)))   // \
                 single(GVoid(Diff(0,-1, 1), Diff(-width+1,-height+1,depth-1)))  // \
                 single(GVoid(Diff(0, 0, 1), Diff(-width+1,height-1,depth-1)))   // \
                 single(GVoid(Diff(0,-1,-1), Diff(-width+1,-height+1,-depth+1))) // \
                 single(GVoid(Diff(0, 0,-1), Diff(-width+1,height-1,-depth+1)))

    # Move 1 down to 2 (3 to 4, 5 to 6, 7 to 8)
    prog_contract_down = (move_y(-height+1) // single()) + -(single(FusionP(Diff(0,-1,0))) // single(FusionS(Diff(0,1,0))))
    # Move 3 back to 1 (7 to 5)
    prog_contract_back = (single() // move_z(-depth)) + -(single(FusionP(Diff(0,0,1))) // single(FusionS(Diff(0,0,-1))))
    # Move 5 left to 1
    prog_contract_left = (single() // move_x(-width+2)) + -(single(FusionP(Diff(1,0,0))) // single(FusionS(Diff(-1,0,0))))

    prog_contract = (prog_contract_down ** 4) + (prog_contract_back ** 2) + prog_contract_left + move_y(-1)

    return prog_init + prog_expand + prog_clear + prog_contract + prog_fini
예제 #8
0
def collapse_roots(full_w, last_w):
    if full_w == 0: return single()
    if full_w == 1 and last_w == 0: return single()

    return (single() // (collapse_roots(full_w - 1, last_w) + move_x(-G_DIST))) + \
           -(single(FusionP(Diff(1,0,0))) // single(FusionS(Diff(-1,0,0))))