示例#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 erase_rows(model, x, y, z, full_w, last_w, height, full_d, last_d):
    cubes = full_w + (1 if last_w else 0)
    if full_d == 0:
        if last_d != 0:
            return erase_row(model, x, y, z, full_w, last_w, height, last_d)
        else:
            return single()**(full_w + (1 if last_w else 0))
    else:
        prog = erase_row(model, x, y, z, full_w, last_w, height, G_DIST + 1)
        prog += move_z(G_DIST + 1)**cubes
        prog += erase_rows(model, x, y, z + G_DIST + 1, full_w, last_w, height,
                           full_d - 1, last_d)
        prog += move_z(-G_DIST - 1)**cubes
        return prog
示例#3
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
示例#4
0
def clear_forward(model, x, y, z, width, height, depth) -> GroupProgram:
    assert width <= G_DIST + 1

    (full_d, last_d) = divmod(depth, G_DIST + 1)

    deltaz = 0
    prog = single()
    for i in range(full_d):
        last = not last_d and i == full_d - 1
        prog += clear_tower(model, x, y, z + deltaz, width, height, G_DIST + 1)
        if not last:
            prog += move_z(G_DIST + 1)
            deltaz += (G_DIST + 1)
    if last_d:
        prog += clear_tower(model, x, y, z + deltaz, width, height, last_d)

    prog += move_z(-deltaz)
    return prog
示例#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 erase_row(model, x, y, z, full_w, last_w, height, depth):
    # SAME UGLY HACK
    cubes = full_w + (1 if last_w else 0)
    prog_init = single()**cubes
    prog_fini = single()**cubes
    if depth == 1:
        depth += 1
        prog_init += move_z(-1)**cubes
        prog_fini += move_z(+1)**cubes
        z -= 1
    if height == 1:
        height += 1
        prog_init += move_y(+1)**cubes
        prog_fini += move_y(-1)**cubes
        y += 1

    prog_depl = empty()
    for i in range(full_w):
        prog_depl //= deploy_cube(model, x + i * (G_DIST + 1), y, z,
                                  G_DIST + 1, height, depth)
    if last_w != 0:
        prog_depl //= deploy_cube(model, x + full_w * (G_DIST + 1), y, z,
                                  last_w, height, depth)

    prog_void = empty()
    for i in range(full_w):
        prog_void //= void_cube(G_DIST + 1, height, depth)
    if last_w != 0:
        prog_void //= void_cube(last_w, height, depth)

    prog_clps = empty()
    for i in range(full_w):
        prog_clps //= collapse_cube(G_DIST + 1, height, depth)
    if last_w != 0:
        prog_clps //= collapse_cube(last_w, height, depth)

    return prog_init + prog_depl + prog_void + prog_clps + prog_fini
示例#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