Exemplo n.º 1
0
    def set_grid(self, grid: List[List[int]]) -> None:
        self.grid = grid
        self.size = Size(len(grid[0]), len(grid))

        for i in range(len(self.grid)):
            for j in range(len(self.grid[i])):
                if self.grid[i][j] == self.AGENT_ID:
                    self.agent = Agent(Point(j, i))
                if self.grid[i][j] == self.GOAL_ID:
                    self.goal = Goal(Point(j, i))
                if self.grid[i][j] == self.WALL_ID:
                    self.obstacles.append(Obstacle(Point(j, i)))
                if self.grid[i][j] == self.EXTENDED_WALL:
                    self.obstacles.append(ExtendedWall(Point(j, i)))
Exemplo n.º 2
0
 def extend_obstacle_bound() -> None:
     for b in bounds:
         for x in range(b.x - self.agent.radius,
                        b.x + self.agent.radius + 1):
             for y in range(b.y - self.agent.radius,
                            b.y + self.agent.radius + 1):
                 if not self.is_out_of_bounds_pos(Point(x, y)):
                     dist: Union[float, np.ndarray] = np.linalg.norm(
                         np.array([x, y]) - np.array(b))
                     if dist <= self.agent.radius and self.grid[y][
                             x] == DenseMap.CLEAR_ID:
                         self.grid[y][x] = DenseMap.EXTENDED_WALL
                         self.obstacles.append(ExtendedWall(Point(x,
                                                                  y)))
                         visited[y][x] = True
Exemplo n.º 3
0
    def set_grid(self, grid: np.array, transpose) -> None:
        # We transpose here to not worry about flipping coordinates later on
        # Please take care I'm not sure why everythng works but it does atm
        self.grid = np.transpose(grid) if transpose else grid

        self.size = Size(*self.grid.shape)
        for index in np.ndindex(*self.size):
            val: int = self.grid[index]
            if val == self.AGENT_ID:
                self.agent = Agent(Point(*index))
            elif val == self.GOAL_ID:
                self.goal = Goal(Point(*index))
            elif val == self.WALL_ID:
                self.obstacles.append(Obstacle(Point(*index)))
            elif val == self.EXTENDED_WALL_ID:
                self.obstacles.append(ExtendedWall(Point(*index)))
Exemplo n.º 4
0
 def extend_obstacle_bound() -> None:
     for b in bounds:
         for index in np.ndindex(*(len(self.size) *
                                   [self.agent.radius * 2 + 1])):
             p = [
                 elem + b[i] - self.agent.radius
                 for i, elem in enumerate(index)
             ]
             pt = Point(*p)
             if not self.is_out_of_bounds_pos(pt):
                 dist: Union[float, np.ndarray] = np.linalg.norm(
                     np.array(p) - np.array(b))
                 if dist <= self.agent.radius and self.at(
                         pt) == DenseMap.CLEAR_ID:
                     self.grid[pt.values] = DenseMap.EXTENDED_WALL_ID
                     self.obstacles.append(ExtendedWall(pt))
                     visited.add(pt)
Exemplo n.º 5
0
 def test_ne_instance(self) -> None:
     entity1: ExtendedWall = ExtendedWall(Point(2, 3), 10)
     entity2: Entity = Entity(Point(2, 3), 10)
     self.assertNotEqual(entity1, entity2)
Exemplo n.º 6
0
 def test_ne_all(self) -> None:
     entity1: ExtendedWall = ExtendedWall(Point(2, 3), 10)
     entity2: ExtendedWall = ExtendedWall(Point(2, 15), 15)
     self.assertNotEqual(entity1, entity2)
Exemplo n.º 7
0
 def test_eq(self) -> None:
     entity1: ExtendedWall = ExtendedWall(Point(2, 3), 10)
     entity2: ExtendedWall = ExtendedWall(Point(2, 3), 10)
     self.assertEqual(entity1, entity2)
Exemplo n.º 8
0
 def test_str(self) -> None:
     entity: ExtendedWall = ExtendedWall(Point(2, 3), 10)
     self.assertEqual("ExtendedWall: {position: Point(2, 3), radius: 10}",
                      str(entity))
Exemplo n.º 9
0
 def test_deep_copy(self) -> None:
     entity1: ExtendedWall = ExtendedWall(Point(2, 3), 10)
     entity2: ExtendedWall = copy.deepcopy(entity1)
     self.assertEqual(entity1, entity2)