Exemplo n.º 1
0
class PathTest(TestCase):
    def setUp(self):
        self.path = Path()
        self.path.append(Node((0, 100)))
        self.path.append(Node((0, 0)))

    def test_whenAdjustDistanceIsCalledThenDistanceIsUpdated(self):
        self.path.ajustDistance()
        goodDistance = 100

        self.assertEqual(goodDistance, self.path.totalDistance)

    def test_whenIsOpenIsCalledThenReturnGoodValue(self):
        theValue = self.path.isOpen()
        isOpen = False

        self.assertEqual(theValue, isOpen)

    def test_whenCloneIsCalledThenCopyIsEqual(self):
        pathClone = self.path.clone()
        for compteur in range(0, self.path.__len__()):
            self.assertTrue(pathClone.contains(self.path.nodeList[0]))
Exemplo n.º 2
0
    def findPath(self, positionRobot, pointToMoveTo):
        print(
            "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
        )
        goodPositionRobot = self.findGoodPoint(positionRobot)
        startingPathNode = self.graph.findGoodSafeNodeToGo(goodPositionRobot)
        endingPathNode = self.graph.findGoodSafeNodeToGo(pointToMoveTo)
        print pointToMoveTo, endingPathNode.positionX, endingPathNode.positionY
        self.theGoodPath = Path()
        self.pathsList = []
        self.goodPaths = []
        path = Path()
        path.append(Node(positionRobot))
        path.append(startingPathNode)
        self.pathsList.append(path)
        self.__findAllPaths(path, endingPathNode)

        goodPath = Path()
        goodPath.append(Node((0, 0)))
        goodPath.totalDistance = 99999
        for compteur in range(0, self.goodPaths.__len__()):
            currentPath = self.goodPaths[compteur]
            currentPath.append(Node(pointToMoveTo))

        self.__polishGoodPaths()
        self.lineOfSightCalculator.tryStraightLine(self.goodPaths)

        for compteur in range(0, self.goodPaths.__len__()):
            currentPath = self.goodPaths[compteur]
            currentPath.ajustDistance()
            if currentPath.totalDistance < goodPath.totalDistance:
                goodPath = currentPath
        self.printPath(goodPath)
        if goodPath.totalDistance == 99999:
            self.__displayPathfinder(goodPath, positionRobot)
            return False
        self.theGoodPath = goodPath
        self.__displayPathfinder(goodPath, positionRobot)
        return goodPath
Exemplo n.º 3
0
    def findPath(self, positionRobot, pointToMoveTo):
        print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
        goodPositionRobot = self.findGoodPoint(positionRobot)
        startingPathNode = self.graph.findGoodSafeNodeToGo(goodPositionRobot)
        endingPathNode = self.graph.findGoodSafeNodeToGo(pointToMoveTo)
        print pointToMoveTo, endingPathNode.positionX, endingPathNode.positionY
        self.theGoodPath = Path()
        self.pathsList = []
        self.goodPaths = []
        path = Path()
        path.append(Node(positionRobot))
        path.append(startingPathNode)
        self.pathsList.append(path)
        self.__findAllPaths(path, endingPathNode)

        goodPath = Path()
        goodPath.append(Node((0,0)))
        goodPath.totalDistance = 99999
        for compteur in range(0, self.goodPaths.__len__()):
            currentPath = self.goodPaths[compteur]
            currentPath.append(Node(pointToMoveTo))

        self.__polishGoodPaths()
        self.lineOfSightCalculator.tryStraightLine(self.goodPaths)

        for compteur in range(0, self.goodPaths.__len__()):
            currentPath= self.goodPaths[compteur]
            currentPath.ajustDistance()
            if currentPath.totalDistance < goodPath.totalDistance:
                    goodPath = currentPath
        self.printPath(goodPath)
        if goodPath.totalDistance == 99999:
            self.__displayPathfinder(goodPath, positionRobot)
            return False
        self.theGoodPath = goodPath
        self.__displayPathfinder(goodPath, positionRobot)
        return goodPath