Esempio n. 1
0
def execute_squad(model, x, y, z, width, height, depth, seeds):
    assert width <= SQUAD_W

    (full_w, last_w) = divmod(width, G_DIST + 1)
    # HACK HACK HACK
    if last_w == 1:
        last_w += 1
    prog_dist = distribute_roots(x, y, z, full_w, last_w, seeds)

    (full_h, last_h) = divmod(height, G_DIST + 1)
    prog_er = erase_layers(model, x, y + height, z, full_w, last_w, full_h,
                           last_h, depth)

    prog_clps = collapse_roots(full_w, last_w)

    return move_y(height) + prog_dist + prog_er + prog_clps + move_y(-last_h)
Esempio n. 2
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
Esempio n. 3
0
def erase_layers(model, x, y, z, full_w, last_w, full_h, last_h, depth):
    if full_h == 0:
        if last_h != 0:
            return erase_layer(model, x, y, z, full_w, last_w, last_h, depth)
        else:
            return single()**(full_w + (1 if last_w else 0))

    return erase_layer(model, x, y, z, full_w, last_w, G_DIST + 1, depth) + \
           (move_y(-G_DIST - 1) ** (full_w + (1 if last_w else 0))) + \
           erase_layers(model, x, y - G_DIST - 1, z, full_w, last_w, full_h - 1, last_h, depth)
Esempio n. 4
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
Esempio n. 5
0
def clear_tower(model, x, y, z, width, height, depth) -> GroupProgram:
    assert width <= G_DIST + 1 and depth <= G_DIST + 1

    (full_h, last_h) = divmod(height, G_DIST + 1)

    prog = move_y(height)
    y = height
    for i in range(full_h):
        prog += clear_cube_below(model, x, y, z, width, G_DIST + 1, depth)
        y -= (G_DIST + 1)
    if last_h:
        prog += clear_cube_below(model, x, y, z, width, last_h, depth)

    return prog
Esempio n. 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
Esempio n. 7
0
def drill_down(model, x, y, z, depth) -> GroupProgram:
    prog = single()

    while depth > 0:
        if model[Pos(x, y - 1, z)]:
            prog += single(Void(Diff(0, -1, 0)))

        step = 1
        for i in range(2, depth + 1):
            if model[Pos(x, y - i, z)]:
                break
            else:
                step += 1
        prog += move_y(-step)
        y -= step
        depth -= step
    return prog
Esempio n. 8
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