def add_content_in(self, row, col, content: BaseCellContent): super().add_content_in(row, col, content) if content == BaseCellContent.ROBOT: self._robot = Point(y=row, x=col) if content == BaseCellContent.DOCKING_STATION: self._docking_station = Point(y=row, x=col) if content == BaseCellContent.BLOCK: self._blocks.append( Block(theid=self._next_block_id, position=Point(y=row, x=col))) self._next_block_id += 1
def _convert_pos_into_cell(self, pos_value: str) -> Point: """ Concvert string s like "POS-05-08" into points like <5,8> :param pos_value: the string to convert :return: the point converted """ x, y = list(map(lambda x: int(x), pos_value.split('-')[1:3])) # consider only the last 2 position in the arrya splitted by - return Point(x, y)
def is_empty(self, row, col): """ :param row: the row of the cell involved :param col: the column of the cell involved :return: False if in the cell there is a ROBOT, UNTRAVERSABLE or a BLOCK; true otherwise or if there is nothing """ if BaseCellContent.UNTRAVERSABLE in self[Point(y=row, x=col)]: return False if BaseCellContent.BLOCK in self[Point(y=row, x=col)]: return False if BaseCellContent.ROBOT in self[Point(y=row, x=col)]: return False if BaseCellContent.DOCKING_STATION in self[Point(y=row, x=col)]: return True # goal doesn't count for clear cell if BaseCellContent.GOAL in self[Point(y=row, x=col)]: return True # goal doesn't count for clear cell return len(self[Point(y=row, x=col)]) == 0
def is_traversable(self, row, col): return BaseCellContent.UNTRAVERSABLE not in self[Point(y=row, x=col)]
def is_visited(self, row, col): return BaseCellContent.VISITED in self[Point(y=row, x=col)]
def cells(self) -> typing.Iterable[Point]: return (Point(x=t[1], y=t[0]) for t in itertools.product(range(0, self.rows), range(0, self.cols)))
def get_right(self, row, col): if col == (self._colums - 1): raise ValueError("can't go right") return Point(x=col + 1, y=row)
def get_left(self, row, col): if col == 0: raise ValueError("can't go left") return Point(x=col - 1, y=row)
def get_down(self, row, col): if row == (self._rows - 1): raise ValueError("can't go down!") return Point(x=col, y=row + 1)
def get_up(self, row, col): if row == 0: raise ValueError("can't go up!") return Point(x=col, y=row - 1)
def _1d22d(self, index) -> Point: return Point(y=divmod(index, self._colums)[0], x=divmod(index, self._colums)[1])