def test_bigger_field(self) -> None: c = CellState.CELL_DECK.value field = [[0, 0, 0, 0, 0, 0], [0, c, 0, 0, 0, 0], [0, 0, 0, 0, c, 0], [0, 0, 0, 0, 0, 0]] self.assertEqual( py_.map_([(0, 3), (0, 4), (0, 5), (3, 0), (3, 1), (3, 2)], Coord), sorted(get_available_cells(field, Coord((4, 6)))))
def test_singular(self) -> None: c = CellState.CELL_DECK.value field = [[0, 0, 0, 0], [0, c, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] self.assertEqual( [[Coord((0, 3))], [Coord((1, 3))], [Coord((2, 3))], [Coord((3, 0)), Coord((3, 1)), Coord((3, 2)), Coord((3, 3))]], find_straight_segments(get_available_cells(field, Coord((4, 4)))))
def test_basic(self) -> None: c = CellState.CELL_DECK.value field = [[0, 0, 0, 0], [0, c, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] self.assertEqual([ Coord((0, 3)), Coord((1, 3)), Coord((2, 3)), Coord((3, 0)), Coord((3, 1)), Coord((3, 2)), Coord((3, 3)) ], sorted(get_available_cells(field, Coord((4, 4)))))
def _try_place(acc: MatrixInt, desired_length: int) -> MatrixInt: available_cells = get_available_cells(acc, FIELD_DIMENSIONS) segments = find_straight_segments(available_cells, True) + \ find_straight_segments(available_cells, False) available_segments = py_.filter_( segments, lambda segment: len(segment) >= desired_length) chosen_segment = choice(available_segments) len_diff = len(chosen_segment) - desired_length available_subsegments = py_.map_( list(range(len_diff + 1)), lambda x: chosen_segment[x:x + desired_length]) chosen_subsegment = choice(available_subsegments) new_field = py_.clone_deep(acc) for c in chosen_subsegment: new_field[c.i][c.j] = CellState.CELL_DECK.value return new_field