Пример #1
0
        public void FindPath(T start, T end, float minHeuristic, int maxPositionsToCheck)
        {
            if (Path == null)
            {
                throw new InvalidOperationException("Path not specified.");
            }
            if (World == null)
            {
                throw new InvalidOperationException("AStar World not specified.");
            }
            if (OpenStorage == null)
            {
                throw new InvalidOperationException("AStar OpenStorage not specified.");
            }
            if (OpenStorage == null)
            {
                throw new InvalidOperationException("AStar ClosedStorage not specified.");
            }
            m_nodesCacheIndex = 0;
            m_openHeap.Clear();
            OpenStorage.Clear();
            ClosedStorage.Clear();
            Node node = NewNode(start, default(T), 0f, 0f);

            OpenStorage.Set(start, node);
            HeapEnqueue(node);
            Node node2 = null;
            int  num   = 0;
            Node node3;

            while (true)
            {
                node3 = ((m_openHeap.Count > 0) ? HeapDequeue() : null);
                if (node3 == null || num >= maxPositionsToCheck)
                {
                    if (node2 != null)
                    {
                        BuildPathFromEndNode(node, node2);
                        return;
                    }
                    Path.Clear();
                    PathCost = 0f;
                    return;
                }
                if (World.IsGoal(node3.Position))
                {
                    break;
                }
                ClosedStorage.Set(node3.Position, node3);
                OpenStorage.Set(node3.Position, null);
                num++;
                m_neighbors.Clear();
                World.Neighbors(node3.Position, m_neighbors);
                for (int i = 0; i < m_neighbors.Count; i++)
                {
                    T val = m_neighbors.Array[i];
                    if (ClosedStorage.Get(val) != null)
                    {
                        continue;
                    }
                    float num2 = World.Cost(node3.Position, val);
                    if (num2 == float.PositiveInfinity)
                    {
                        continue;
                    }
                    float num3 = node3.G + num2;
                    float num4 = World.Heuristic(val, end);
                    if (node3 != node && (node2 == null || num4 < node2.H))
                    {
                        node2 = node3;
                    }
                    Node node4 = (Node)OpenStorage.Get(val);
                    if (node4 != null)
                    {
                        if (num3 < node4.G)
                        {
                            node4.G = num3;
                            node4.F = num3 + node4.H;
                            node4.PreviousPosition = node3.Position;
                            HeapUpdate(node4);
                        }
                    }
                    else
                    {
                        node4 = NewNode(val, node3.Position, num3, num4);
                        OpenStorage.Set(val, node4);
                        HeapEnqueue(node4);
                    }
                }
            }
            BuildPathFromEndNode(node, node3);
        }
Пример #2
0
 public OpenController(OpenStorage storage)
 {
     this._Storage = storage;
 }