コード例 #1
0
        public void traverseMapStep()
        {
            SearchAlgorithm search;

            search = new AStar(knownMap, positionX, positionY, targetX, targetY);

            givenPath = search.getPath();

            if ((positionX == targetX) && (positionY == targetY))
            {
                atTarget = true;
            }

            if (givenPath.Count == 0)
            {
                atTarget = true;

            }

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

            if (isNextNodeSafe(nextNode) == true)
            {
                positionX = nextNode.x;
                positionY = nextNode.y;
                takenPath.Add(nextNode);

                updateOwnMap(positionX, positionY);
            }
            else
            {
                updateOwnMap(nextNode.x, nextNode.y);
            }
        }
コード例 #2
0
        public void findPath(int startX , int startY , int targetX , int targetY)
        {
            SearchAlgorithm aStar = new AStar(hazardModel , startX , startY , targetX , targetY);

            pathNodes = aStar.getPath();
        }
コード例 #3
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;

            bool atTarget = false;

            SearchAlgorithm search;

            do
            {
                search = new AStar(knownMap,positionX , positionY , targetX , targetY);

                givenPath = search.getPath();

                do
                {
                    if (steps >= 1600)
                    {
                        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 (isNextNodeSafe(nextNode) == true)
                    {
                        previousX = positionX;
                        previousY = positionY;
                        positionX = nextNode.x;
                        positionY = nextNode.y;

                        takenPath.Add(nextNode);

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

                }while(true);

            } while (atTarget == false);
        }