def test_group_by_x_3_dots_in_line_vertically(self): player = occupier = Player(-1) c1 = Cell.Cell(0, 0, player, occupier) c2 = Cell.Cell(0, 1, player, occupier) c3 = Cell.Cell(0, 2, player, occupier) cells = {c1, c2, c3} expected = {} self.assertEqual(expected, Cell.group_by_x(cells))
def test_group_by_x_3_dots_in_line_horizontally(self): player = occupier = Player(-1) c1 = Cell.Cell(0, 0, player, occupier) c2 = Cell.Cell(1, 0, player, occupier) c3 = Cell.Cell(2, 0, player, occupier) cells = {c1, c2, c3} expected = {1: {c2}} self.assertEqual(expected, Cell.group_by_x(cells))
def get_occupied_cells(cycle_dots, field): """returns set of occupied cells""" occupied_dots = set() dots_on_vertical = Cell.group_by_x(cycle_dots) for vertical in dots_on_vertical.keys(): # dict[x_coord]==set of cells is_inner = False upper, lower = Cell.bounds(dots_on_vertical[vertical]) for y in range(lower, upper + 1): if Cell.contains_by_y(dots_on_vertical[vertical], y): is_inner = not is_inner elif is_inner: occupied_dots.add(field.field_array[vertical][y]) return occupied_dots