Пример #1
0
 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
Пример #2
0
 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)
Пример #3
0
    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
Пример #4
0
 def is_traversable(self, row, col):
     return BaseCellContent.UNTRAVERSABLE not in self[Point(y=row, x=col)]
Пример #5
0
 def is_visited(self, row, col):
     return BaseCellContent.VISITED in self[Point(y=row, x=col)]
Пример #6
0
 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)))
Пример #7
0
 def get_right(self, row, col):
     if col == (self._colums - 1):
         raise ValueError("can't go right")
     return Point(x=col + 1, y=row)
Пример #8
0
 def get_left(self, row, col):
     if col == 0:
         raise ValueError("can't go left")
     return Point(x=col - 1, y=row)
Пример #9
0
 def get_down(self, row, col):
     if row == (self._rows - 1):
         raise ValueError("can't go down!")
     return Point(x=col, y=row + 1)
Пример #10
0
 def get_up(self, row, col):
     if row == 0:
         raise ValueError("can't go up!")
     return Point(x=col, y=row - 1)
Пример #11
0
 def _1d22d(self, index) -> Point:
     return Point(y=divmod(index, self._colums)[0], x=divmod(index, self._colums)[1])