Example #1
0
def check_unifier(full_shapes, unique_shapes):
    full_keys = [repr(shape) for shape in full_shapes]

    all_orientations = []
    for base_shape in unique_shapes:
        all_orientations.extend(get_all_orientations(base_shape))

    for key in all_orientations:
        if key not in full_keys:
            print('Shape was not in original list!')
            print(Shape(key))

    for key in full_keys:
        if key not in all_orientations:
            print('Shape not a rotation of unified list!')
            print(Shape(key))
Example #2
0
def get_all_orientations(shape):
    all_orientations = []
    for _ in range(0, 4):
        key = shape.rotate()
        all_orientations.append(key)
        shape = Shape(key)
    shape = Shape(shape.flip())
    for _ in range(0, 4):
        key = shape.rotate()
        all_orientations.append(key)
        shape = Shape(key)
    return all_orientations
Example #3
0
 def test_long_drop(self):
     shape = Shape('#...:...#:.#..:..#.')
     left, right = shape.cut()
     assert left == '...#:..#.:....:....'
     assert right == '#...:.#..:....:....'
Example #4
0
 def test_scaffolding_prevents_drop(self):
     shape = Shape('#.#.:...#:....:....')
     left, right = shape.cut()
     assert left == '..#.:...#:....:....'
     assert right == '#...:....:....:....'
Example #5
0
 def test_repr(self):
     key = '##.#:..#.:....:....'
     shape = Shape(key)
     assert repr(shape) == key
Example #6
0
 def test_stack_angle(self):
     bottom = Shape('##..:....:....:....')
     top = Shape('.##.:....:....:....')
     merged = bottom.stack(top)
     assert merged == '##..:.##.:....:....'
Example #7
0
 def test_stack_tall(self):
     bottom = Shape('#...:#...:....:....')
     top = Shape('#...:#...:....:....')
     merged = bottom.stack(top)
     assert merged == '#...:#...:#...:#...'
Example #8
0
 def test_diagonal(self):
     bottom = Shape('...#:....:....:....')
     top = Shape('.#..:....:....:....')
     merged = bottom.stack(top)
     assert merged == '.#.#:....:....:....'
Example #9
0
 def test_logo(self):
     left_half = Shape('...#:..#.:....:....')
     right_half = Shape('##..:....:....:....')
     logo = left_half.stack(right_half)
     assert logo == '##.#:..#.:....:....'
Example #10
0
 def test_tetris(self):
     bottom = Shape('.##.:..#.:..#.:....')
     top = Shape('.#..:.##.:....:....')
     merged = bottom.stack(top)
     assert merged == '.##.:..#.:.##.:.##.'
Example #11
0
 def test_trim_to_four_layers(self):
     bottom = Shape('#...:#...:...#:....')
     top = Shape('####:...#:....:....')
     merged = bottom.stack(top)
     assert merged == '#...:#...:...#:####'
Example #12
0
 def test_long_drop(self):
     bottom = Shape('#...:#...:#...:#...')
     top = Shape('.#..:....:....:....')
     merged = bottom.stack(top)
     assert merged == '##..:#...:#...:#...'
Example #13
0
 def test_staircase(self):
     bottom = Shape('#..#:##..:....:....')
     top = Shape('.##.:..##:....:....')
     merged = bottom.stack(top)
     assert merged == '#..#:##..:.##.:..##'
Example #14
0
 def test_stack_merge_on_second_layer(self):
     bottom = Shape('##..:#...:....:....')
     top = Shape('.##.:....:....:....')
     merged = bottom.stack(top)
     assert merged == '##..:###.:....:....'
Example #15
0
 def test_no_empty_shape(self):
     empty = Shape('....:....:....:....')
     with pytest.raises(ValueError):
         empty.stack(empty)
Example #16
0
 def test_simple_merge(self):
     bottom = Shape('##..:....:....:....')
     top = Shape('..##:....:....:....')
     merged = bottom.stack(top)
     assert merged == '####:....:....:....'
Example #17
0
 def test_spiral(self):
     shape = Shape('#...:.#..:..#.:...#')
     rotated = shape.rotate()
     assert rotated == '.#..:..#.:...#:#...'
Example #18
0
 def test_stack_full_layers(self):
     bottom = Shape('####:....:....:....')
     top = Shape('####:....:....:....')
     merged = bottom.stack(top)
     assert merged == '####:####:....:....'
Example #19
0
 def test_vertical(self):
     shape = Shape('..##:....:....:....')
     left, right = shape.cut()
     assert left == '..##:....:....:....'
     assert right == '....:....:....:....'
Example #20
0
impossible = []
rest = buildable_shapes[:]
n = 0
while len(rest) > 0:
    try_shape = all_shapes.pop(0)
    if rest[0] == try_shape:
        _ = rest.pop(0)
    else:
        impossible.append(try_shape)

short_keys = [
    ':'.join(shape[i:i + 4] for i in range(0, 16, 4)) for shape in impossible
]

impossible_shapes = [Shape(k) for k in short_keys]

# No floating layers
impossible_shapes = [
    shape for shape in impossible_shapes
    if not ((not any(shape.layers[1]) and
             (any(shape.layers[2]) or any(shape.layers[3]))) or
            (not any(shape.layers[2]) and any(shape.layers[3])))
]

layers_2 = [
    s for s in impossible_shapes
    if not any(s.layers[3]) and not any(s.layers[2])
]

layers_3 = [
Example #21
0
 def test_horizontal(self):
     shape = Shape('#..#:....:....:....')
     left, right = shape.cut()
     assert left == '...#:....:....:....'
     assert right == '#...:....:....:....'
Example #22
0
 def test_two_layers(self):
     shape = Shape('####:####:....:....')
     left, right = shape.cut()
     assert left == '..##:..##:....:....'
     assert right == '##..:##..:....:....'
Example #23
0
 def test_str(self):
     key = '##.#:..#.:.##.:##..'
     pretty = str(Shape(key))
     assert pretty == """