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)
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)
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)
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
def setUp(self): field = generator.Generator.generate_triangle_field(5) self.constructor = Generator(TriangleField(field)) self.field = TriangleField(field)
def assert_count_numbered_neighbours(self, expected, position, number): constructor = Generator(self.field) actual = constructor.count_number_neighbours(position, number) assert expected == actual
def assert_count_busy_neighbours(self, expected, pos): constructor = Generator(self.field) actual = constructor.count_busy_neighbours(pos) assert expected == actual
def generate_level(self): size = self.menu.size_editor.text() self.create_game(Generator.generate_field(int(size)))