Ejemplo n.º 1
0
        public void traverseMap(int startXt, int startYt, int endXt, int endYt)
        {
            steps = 0;

            startX = startXt;
            startY = startYt;
            targetX = endXt;
            targetY = endYt;
            positionX = startX;
            positionY = startY;

            atTarget = false;

            SearchAlgorithm search;

            do
            {
                search = new A_Star(map.getMap(), positionX, positionY, targetX, targetY);
                givenPath = search.getPath();

                do
                {
                    if (steps >= stepLimit)
                    {
                        atTarget = true;
                        break;
                    }

                    steps++;

                    if ((positionX == targetX) && (positionY == targetY))
                    {
                        atTarget = true;
                        break;
                    }
                    if (givenPath.Count == 0)
                    {
                        atTarget = true;
                        break;
                    }

                    PathNode nextNode = givenPath.Last();
                    givenPath.Remove(nextNode);

                    if (sensorManager.isAreaSafe(nextNode) == true)
                    {
                        previousX = positionX;
                        previousY = positionY;
                        positionX = nextNode.x;
                        positionY = nextNode.y;

                        takenPath.Add(nextNode);

                        sensorManager.updateOwnLocation(positionX, positionY);
                    }
                    else
                    {
                        sensorManager.updateOwnLocation(nextNode.x, nextNode.y);
                        break;
                    }

                } while (true);
            } while (atTarget == false);
        }
 public void findPath(int startX, int startY, int targetX, int targetY)
 {
     SearchAlgorithm aStar = new A_Star(hazardModel, startX, startY, targetX, targetY);
     pathNodes = aStar.getPath();
 }
Ejemplo n.º 3
0
        public void traverseCompare(int startXt, int startYt, int endXt, int endYt)
        {
            startX = startXt;
            startY = startYt;
            targetX = endXt;
            targetY = endYt;

            positionX = startX;
            positionY = startY;

            atTarget = false;

            SearchAlgorithm search;

            search = new A_Star(map.getMap(), positionX, positionY, targetX, targetY);
            givenPath = search.getPath();

            takenPath = givenPath;
            atTarget = true;
        }