private static List <PositionBehavior> GetPath(PositionBehavior start, PositionBehavior target, List <PositionBehavior> visited) { List <PositionBehavior> bestPath = null; foreach (var node in start.GetAdjacentNodes()) { var currentPath = visited.ToList(); if (target == node) { currentPath.Add(node); if (PathDistance(start, bestPath) > PathDistance(start, currentPath)) { bestPath = currentPath; } return(bestPath); } else { if (!currentPath.Contains(node) && node != start && CloserNode(node, start, target)) { currentPath.Add(node); var path = GetPath(node, target, currentPath); if (path != null && (PathDistance(start, bestPath) > PathDistance(start, path))) { bestPath = path; } } } } return(bestPath); }
private PositionBehavior DetermineTargetNode(PositionBehavior from, PositionBehavior to) { var currentPathLength = PathFinder.NodeWorldDistance(from, to); PositionBehavior bestNode; var distances = PathFinder.GetNodeDistances(to, from.GetAdjacentNodes()); if (movementRecieved.Direction == MovementDirection.Forward) { bestNode = distances.OrderBy(e => e.Lengh).First().Node; if (PathFinder.NodeWorldDistance(bestNode, to) > PathFinder.NodeWorldDistance(from, to)) { return(null); } } else if (movementRecieved.Direction == MovementDirection.Backward) { bestNode = distances.OrderByDescending(e => e.Lengh).First().Node; if (PathFinder.NodeWorldDistance(bestNode, to) < PathFinder.NodeWorldDistance(from, to)) { return(null); } } else { throw new NotImplementedException(); } return(bestNode); }