Ejemplo n.º 1
0
def rotate_and_show(pattern, degrees):
    transformer = triangular_pattern.TriangularPatternOperations()
    rotated = transformer.rotate(pattern, degrees, True)

    show_pattern_on_grid(rotated, 0)
    show_pattern_on_grid(rotated, 1)
    show_pattern_on_grid(rotated, 2)
Ejemplo n.º 2
0
def show_orientations_of_pattern(pattern_cells, delete_equal_patterns=False):
    transformer = triangular_pattern.TriangularPatternOperations()

    resulting_patterns = transformer.get_all_orientations(
        pattern_cells, delete_equal_patterns)

    show_patterns_on_grid(resulting_patterns, 6, 1)
    print("Number of patterns: {}".format(len(resulting_patterns)))
Ejemplo n.º 3
0
    def __init__(self, logger=None):

        self.logger = logger or logging.getLogger(__name__)
        self.logger.info("Puzzle solver init.")

        self.transformer = triangular_pattern.TriangularPatternOperations()

        # stats:
        self.state_saver = []
        self.tested_pieces = 0
Ejemplo n.º 4
0
def show_pattern_on_grid(pattern_cells, empty_spacing=0):
    transformer = triangular_pattern.TriangularPatternOperations()

    bounding_box = transformer.get_bounding_box(pattern_cells)
    rows = bounding_box["max_r"] + 1 + empty_spacing * 2
    cols = bounding_box["max_c"] + 1 + empty_spacing * 2

    if empty_spacing > 0:
        pattern_cells = transformer.translate(pattern_cells, "SE",
                                              empty_spacing)
        # pattern_cells = transformer.translate(pattern_cells,"E")

    base = triangular_grid.TriangularGrid(rows, cols)
    base.add_pattern(pattern_cells)
    print(str(base))
Ejemplo n.º 5
0
def show_mirrored(pattern):

    transformer = triangular_pattern.TriangularPatternOperations()

    vertical = transformer.mirror(pattern, False)
    horizontal = transformer.mirror(pattern, True)

    bounding_box = transformer.get_combined_bounding_box(
        [pattern, horizontal, vertical])
    rows = bounding_box["max_r"] + 1
    cols = bounding_box["max_c"] + 1
    base = triangular_grid.TriangularGrid(rows, cols)

    base.add_pattern(pattern)
    base.add_pattern(horizontal)
    base.add_pattern(vertical)

    print(str(base))
Ejemplo n.º 6
0
def show_orientations_of_all_patterns(patterns,
                                      delete_equal_patterns=False,
                                      show_one_pattern_at_a_time=False):
    transformer = triangular_pattern.TriangularPatternOperations()
    resulting_patterns = []

    if show_one_pattern_at_a_time:
        for pattern in patterns:
            show_orientations_of_pattern(pattern, delete_equal_patterns)
    else:

        for pattern in patterns:
            resulting_patterns.extend(
                transformer.get_all_orientations(pattern,
                                                 delete_equal_patterns))

        if not show_one_pattern_at_a_time:
            show_patterns_on_grid(resulting_patterns, 10, 2)
            print("Number of patterns: {}".format(len(resulting_patterns)))
Ejemplo n.º 7
0
def show_patterns_on_grid(patterns, patterns_per_col, spacing=0):
    transformer = triangular_pattern.TriangularPatternOperations()
    # print(patterns)
    arranged_patterns = transformer.arrange_patterns_for_no_overlap(
        patterns, patterns_per_col, spacing)

    # print(arranged_patterns)
    # create fitting field.
    bounding_box = transformer.get_combined_bounding_box(arranged_patterns)

    # print(bounding_box)
    rows = bounding_box["max_r"] + 1  # rows one more than index.
    cols = bounding_box["max_c"] + 1

    # print(rows)
    # print(cols)
    base = triangular_grid.TriangularGrid(rows, cols)

    for pattern in arranged_patterns:
        base.add_pattern(pattern)

    print(str(base))
Ejemplo n.º 8
0
def general_tests_with_patterns():
    transformer = triangular_pattern.TriangularPatternOperations()