Ejemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="grid"></param>
 /// <param name="startLoc"></param>
 /// <param name="goalLoc"></param>
 public AStarSearch(int[,] grid, Location startLoc, Location goalLoc)
 {
     this.grid = grid;
     this.startLoc = startLoc;
     this.goalLoc = goalLoc;
     open = new Dictionary<Location, Node>(grid.Length);
     closed = new Dictionary<Location, Node>(grid.Length);
 }
Ejemplo n.º 2
0
 public PathFinder(int[,] grid, Location startLoc, Location goalLoc, 
     ISearchStrategy searchStrategy)
 {
     _grid = grid;
     _startLoc = startLoc;
     _goalLoc = goalLoc;
     _searchStrategy = searchStrategy;
 }
Ejemplo n.º 3
0
 public SearchNode(Location location, INode parent)
 {
     Location = location;
     Parent = parent;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="location1"></param>
 /// <param name="location2"></param>
 /// <returns></returns>
 private static decimal FindActualCost(Location location1, Location location2)
 {
     return (decimal)Math.Sqrt(Math.Abs(location2.X - location1.X) +
         Math.Abs(location2.Y - location1.Y));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="addTo"></param>
        /// <param name="loc"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        private void AddConditional(IList<Node> addTo, Location loc, int x, int y)
        {
            int newX = loc.X + x, newY = loc.Y + y;
            if (newX < 0 || newX >= grid.GetLength(0))
            {
                return;
            }
            if (newY < 0 || newY >= grid.GetLength(1))
            {
                return;
            }
            if (grid[newX, newY] == Constants.SOLID)
                return;

            var location = new Location(newX, newY);

            var newNode = new Node() {Location = location};
            addTo.Add(newNode);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="startLoc"></param>
 /// <param name="goalLoc"></param>
 /// <returns></returns>
 private static decimal FindHeuristic(Location startLoc, Location goalLoc)
 {
     decimal dx = Math.Abs(goalLoc.X - startLoc.X);
     decimal dy = Math.Abs(goalLoc.Y - startLoc.Y);
     return ((decimal)0.5 * (dx + dy));
 }