예제 #1
0
        public List <Point> GetTravelList(Point startPoint, Point endPoint, ShrunkNode[,] shrunkMap, int findTownId)
        {
            List <Point> routeList = new List <Point>();

            if (startPoint == endPoint)  //return an empty list
            {
                return(routeList);
            }

            this.startPoint = startPoint;
            this.endPoint   = endPoint;
            checkNode       = new CheckNode();
            newPoint        = this.startPoint;
            checkNode.Update(startPoint, startPoint, newPointScore);
            listToCheck.Add(checkNode);


            for (int i = 0; i < maximumToCheck; i++)
            {
                if (listToCheck.Count < 1)  //list is empty
                {
                    break;
                }

                lowestNumber     = listToCheck[0].score;
                listToCheckIndex = 0;

                for (int p = 1; p < listToCheck.Count; p++)
                {
                    if (listToCheck[p].score < lowestNumber)
                    {
                        lowestNumber     = listToCheck[p].score;
                        listToCheckIndex = p;
                    }
                }

                checkNode    = listToCheck[listToCheckIndex]; //getting the next node to check
                currentPoint = checkNode.currentPoint;        //setting the next node to check to be the current point.

                if (currentPoint == this.endPoint)            //checking to see if we reached the end;
                {
                    found = true;
                    break;
                }

                listToCheck.RemoveAt(listToCheckIndex);  //remove the point from the list

                UpdateNewPoints(shrunkMap, findTownId);  //looking for new points
            }


            if (found)
            {
                UpdateTravelList(routeList);
            }

            return(routeList);  //we are returning an empty list
        }
예제 #2
0
 private void AddToList(byte direction)
 {
     newNode = new CheckNode();
     newNode.Update(newPoint, currentPoint, newPointScore);
     listToCheck.Add(newNode);
     score[newPoint.X, newPoint.Y]         = newPointScore;
     IsSearched[newPoint.X, newPoint.Y]    = true;
     comeFrom[newPoint.X, newPoint.Y]      = currentPoint;
     hScore[newPoint.X, newPoint.Y]        = newHscore;
     directionFrom[newPoint.X, newPoint.Y] = direction; //the direction we come from
 }