Esempio n. 1
0
    def test_can_add_cell(self):
        self.field[0, 0] = self.field[1, 1] = 1
        assert Generator(self.field).can_add_cell((1, 0), 1)

        self.field[0, 0] = 1
        self.field[1, 0] = self.field[1, 2] = 1
        assert Generator(self.field).can_add_cell((1, 1), 1)
Esempio n. 2
0
 def test_has_isolated_empty_cell(self):
     self.field[0, 0] = self.field[1, 1] = 1
     self.field[1, 0] = self.field[1, 2] = 1
     self.field[2, 1] = self.field[2, 2] = 1
     assert not Generator(self.field).has_isolated_empty_cells(
             (2, 2), 1, False)
     assert not Generator(self.field).has_isolated_empty_cells(
             (2, 2), 2, False)
Esempio n. 3
0
    def test_isolated(self):
        assert not Generator(self.field).is_isolated((0, 0), 1, False)

        self.field[1, 0] = self.field[1, 1] = 1
        self.field[1, 2] = self.field[0, 0] = 1
        assert not Generator(self.field).is_isolated((0, 0), 1, True)
        assert not Generator(self.field).is_isolated((0, 0), 2, False)

        self.field[1, 0] = self.field[1, 1] = 1
        self.field[1, 2] = self.field[0, 0] = 1
        self.field[0, 0] = self.field[1, 2] = 1
        self.field[2, 1] = self.field[2, 2] = 1
        assert Generator(self.field).is_isolated((1, 1), 1, True)
        assert Generator(self.field).is_isolated((1, 1), 2, False)
Esempio n. 4
0
    def get_field_from_solution(self, field: TriangleField,
                                solution: List[list]) -> List[list]:
        result = TriangleField(Generator.generate_triangle_field(field.size))
        for pair in field.get_targets()['pairs']:
            start, end = tuple(pair)
            number = field[start]

            while start != end:
                for edge in solution:
                    if start in edge:
                        result[start] = number
                        start = self.opposite(start, edge)

            result[end] = number

        return result.field
Esempio n. 5
0
 def setUp(self):
     field = generator.Generator.generate_triangle_field(5)
     self.constructor = Generator(TriangleField(field))
     self.field = TriangleField(field)
Esempio n. 6
0
 def assert_count_numbered_neighbours(self, expected, position, number):
     constructor = Generator(self.field)
     actual = constructor.count_number_neighbours(position, number)
     assert expected == actual
Esempio n. 7
0
 def assert_count_busy_neighbours(self, expected, pos):
     constructor = Generator(self.field)
     actual = constructor.count_busy_neighbours(pos)
     assert expected == actual
Esempio n. 8
0
 def generate_level(self):
     size = self.menu.size_editor.text()
     self.create_game(Generator.generate_field(int(size)))