Example #1
0
        private Food GetBestFood()
        {
            Food bestFood  = null;
            int  bestScore = 0;
            int  currentScore;

            foreach (Food f in World.Instance.Foods)
            {
                currentScore = f.Size + GameLogic.Random.Next(_pathfindingRandomness);

                // Score cannot be negative
                if (currentScore - Node.GetFScore(PathingUtils.NodeAt(f.Location),
                                                  PathingUtils.NodeAt(Location.X, Location.Y)) < 0)
                {
                    currentScore = 0;
                }

                if (currentScore >= bestScore)
                {
                    bestFood  = f;
                    bestScore = currentScore;
                }
            }

            return(bestFood);
        }
Example #2
0
        public static double GetFScore(Node destination, Node nodeToCheck)
        {
            double distance  = nodeToCheck.GScore;
            int    manhattan = PathingUtils.GetHScore(nodeToCheck, destination);

            return(distance + manhattan);
        }
Example #3
0
        private void AddInitialNode(Location l)
        {
            _closed = new LinkedList <Node>();
            _open   = new PriorityQueue <Node>();

            _open.Add(PathingUtils.NodeAt(l.X, l.Y));
            _closed.AddFirst(PathingUtils.NodeAt(l.X, l.Y));
            _closed.First().AddNeigbours(_open, _closed);
        }
Example #4
0
        private void GetRoute()
        {
            Node current = _open.First;

            LinkedListNode <Node> previous = _closed.First;

            while (!current.IsAt(_destination))
            {
                _closed.AddAfter(previous, current);
                previous = previous.Next;

                current.AddNeigbours(_open, _closed);

                _open.Remove(current);

                current = _open.PriorityItem(Node.GetFScore, PathingUtils.CompareScores,
                                             PathingUtils.NodeAt(_destination));
            }
        }