示例#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);
        }
示例#2
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);
        }
示例#3
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));
            }
        }