Esempio n. 1
0
    def test_d13(self):
        puzzle = m.Puzzle()

        nodes = [
            # nothing
            m.ShapeNode(0, terminates=True),
            m.ShapeNode(1, terminates=True),
            m.ShapeNode(2),
            m.ShapeNode(2, terminates=True),
            m.MultipassNode(2),
            m.ShapeNode(2, terminates=True),
            m.MultipassNode(3),
            m.MultipassNode(2),
            m.ShapeNode(1, terminates=True),
            m.ShapeNode(2),
            m.ShapeNode(0, terminates=True),
        ]

        node_ids = [puzzle.add_node(n) for n in nodes]

        ls.triangle_link(puzzle, node_ids[0], node_ids[2], node_ids[3])
        for square in (
                (0, 1, 3, 4),
                (2, 3, 5, 6),
                (3, 4, 6, 7),
                (5, 6, 8, 9),
                (6, 7, 9, 10),
        ):
            square_ids = [node_ids[i] for i in square]
            ls.square_link(puzzle, *square_ids)

        solution = s.solve(puzzle)

        self.assertIsNotNone(solution)
        print(solution)
Esempio n. 2
0
    def test_c16(self):
        puzzle = m.Puzzle()

        # 0 = triangle, 1 = square-on-tip
        nodes = [
            m.ShapeNode(0),
            # nothing
            m.ShapeNode(1, terminates=True),
            m.MultipassNode(2),
            m.MultipassNode(2),
            m.ShapeNode(0, terminates=True),
            m.ShapeNode(0, terminates=True),
            m.MultipassNode(3),
            m.ShapeNode(0),
            m.ShapeNode(1),
            m.MultipassNode(2),
            m.ShapeNode(1, terminates=True),
        ]

        node_ids = [puzzle.add_node(n) for n in nodes]

        for triangle in ((0, 2, 3), (1, 3, 4)):
            triangle_ids = [node_ids[i] for i in triangle]
            ls.triangle_link(puzzle, *triangle_ids)

        for square in ((2, 3, 5, 6), (3, 4, 6, 7), (5, 6, 8, 9), (6, 7, 9, 10)):
            square_ids = [node_ids[i] for i in square]
            ls.square_link(puzzle, *square_ids)

        solution = s.solve(puzzle)

        self.assertIsNotNone(solution)
Esempio n. 3
0
    def test_f18(self):
        puzzle = m.Puzzle()

        # 0 = square, 1 = square-on-tip, 2 = triangle
        nodes = [
            m.ShapeNode(0, terminates=True),
            m.ShapeNode(1),
            m.ShapeNode(1),
            m.ShapeNode(1),
            m.ShapeNode(1, terminates=True),
            m.MultipassNode(2),
            m.MultipassNode(3),
            m.ShapeNode(0),
            m.ShapeNode(1),
            m.ShapeNode(1, terminates=True),
            m.MultipassNode(3),
            m.ShapeNode(0),
            m.ShapeNode(2, terminates=True),
            m.MultipassNode(2),
            m.ShapeNode(2, terminates=True),
            m.ShapeNode(0, terminates=True),
            m.ShapeNode(2),
            m.ShapeNode(2),
            m.ShapeNode(2),
            # nothing
        ]

        node_ids = [puzzle.add_node(n) for n in nodes]

        ls.triangle_link(puzzle, node_ids[14], node_ids[15], node_ids[18])
        for square in (
                (0, 1, 4, 5),
                (1, 2, 5, 6),
                (2, 3, 6, 7),
                (4, 5, 8, 9),
                (5, 6, 9, 10),
                (6, 7, 10, 11),
                (8, 9, 12, 13),
                (9, 10, 13, 14),
                (10, 11, 14, 15),
                (12, 13, 16, 17),
                (13, 14, 17, 18),
        ):
            square_ids = [node_ids[i] for i in square]
            ls.square_link(puzzle, *square_ids)

        solution = s.solve(puzzle)

        self.assertIsNotNone(solution)
        print(solution)
Esempio n. 4
0
    def test_f11(self):
        puzzle = m.Puzzle()

        # 0 = square, 1 = square-on-tip, 2 = triangle
        nodes = [
            m.ShapeNode(0, terminates=True),
            m.ShapeNode(1, terminates=True),
            # nothing
            # nothing
            m.MultipassNode(2),
            m.MultipassNode(2),
            m.ShapeNode(2, terminates=True),
            m.ShapeNode(2, terminates=True),
            m.MultipassNode(2),
            m.MultipassNode(3),
            m.MultipassNode(3),
            m.ShapeNode(1, terminates=True),
            m.ShapeNode(2),
            m.ShapeNode(0, terminates=True),
            m.ShapeNode(2),
            m.ShapeNode(2),
        ]

        node_ids = [puzzle.add_node(n) for n in nodes]

        ls.triangle_link(puzzle, node_ids[1], node_ids[3], node_ids[4])
        for square in (
                (0, 1, 2, 3),
                (2, 3, 6, 7),
                (3, 4, 7, 8),
                (4, 5, 8, 9),
                (6, 7, 10, 11),
                (7, 8, 11, 12),
                (8, 9, 12, 13),
        ):
            square_ids = [node_ids[i] for i in square]
            ls.square_link(puzzle, *square_ids)

        solution = s.solve(puzzle)

        self.assertIsNotNone(solution)
        print(solution)