Example #1
0
    def gradient_descent(self, current: Point, grid: Map) -> List[Point]:
        """
        Search backward from the given point the next lowest number until we reach the agent position
        :param current: The position from witch to start the descent
        :param grid: the map
        :return: The trace
        """
        trace: List[Point] = [current]
        # find the trace of the path by looking at neighbours at each point and moving the current towards the agent position. (number to next lowest numb(-1))
        while self.step_grid[current.values] != 1:
            for n in grid.get_next_positions(current):
                if self.step_grid[n.values] == self.step_grid[current.values] - 1:
                    trace.append(n)
                    current = n
                    break

        return trace[1:]
Example #2
0
    def gradient_descent(self, current: Point, grid: Map) -> List[Point]:
        """
        Search backward from the given point the next lowest number until we reach the agent position
        :param current: The position from witch to start the descent
        :param grid: the map
        :return: The trace
        """
        trace: List[Point] = [current]

        while self.step_grid[current.y][current.x] != 1:
            for n in grid.get_next_positions(current):
                if self.step_grid[n.y][
                        n.x] == self.step_grid[current.y][current.x] - 1:
                    trace.append(n)
                    current = n
                    break

        return trace[1:]