namespace Holo.Virtual.Rooms.Pathfinding { using System; using System.Collections; public sealed class AStar { private Heap FClosedList = new Heap(); private AStarNode FGoalNode; private Heap FOpenList = new Heap(); private ArrayList FSolution = new ArrayList(); private AStarNode FStartNode; private ArrayList FSuccessors = new ArrayList(); public void FindPath(AStarNode AStartNode, AStarNode AGoalNode) { this.FStartNode = AStartNode; this.FGoalNode = AGoalNode; this.FOpenList.Add(this.FStartNode); while (this.FOpenList.Count > 0) { AStarNode parent = (AStarNode) this.FOpenList.Pop(); if (parent.IsGoal()) { while (parent != null) { this.FSolution.Insert(0, parent); parent = parent.Parent; } break; } parent.GetSuccessors(this.FSuccessors); foreach (AStarNode node2 in this.FSuccessors) { AStarNode node3 = null; if (this.FOpenList.Contains(node2)) { node3 = (AStarNode) this.FOpenList[this.FOpenList.IndexOf(node2)]; } if ((node3 == null) || (node2.TotalCost <= node3.TotalCost)) { AStarNode node4 = null; if (this.FClosedList.Contains(node2)) { node4 = (AStarNode) this.FClosedList[this.FClosedList.IndexOf(node2)]; } if ((node4 == null) || (node2.TotalCost <= node4.TotalCost)) { this.FOpenList.Remove(node3); this.FClosedList.Remove(node4); this.FOpenList.Push(node2); } } } this.FClosedList.Add(parent); } } private void PrintNodeList(object ANodeList) { Console.WriteLine("Node list:"); foreach (AStarNode node in ANodeList as IEnumerable) { node.PrintNodeInfo(); } Console.WriteLine("====="); } public ArrayList Solution { get { return this.FSolution; } } } }