static Node A_Star(Node root) { var goal = new Node(-1, Goal); Open.Add(root); while (Open.Count != 0) { var node = Open.First(); Closed.Add(node); Open.RemoveAt(0); if (node.Equals(goal)) { return(node); } foreach (var child in node.GenerateChildren()) { var nodeInOpen = Open.Where(x => x.Equals(child)).FirstOrDefault(); var nodeInClosed = Closed.Where(x => x.Equals(child)).FirstOrDefault(); if (child.Equals(goal)) { return(child); } if (nodeInOpen != null) { if (nodeInOpen.Level > child.Level) { Open.Remove(nodeInOpen); Open.Add(child); } } else if (nodeInClosed != null) { if (nodeInClosed.Level > child.Level) { Closed.Remove(nodeInClosed); Open.Add(child); } } else { Open.Add(child); } } Open.Sort((a, b) => a.FScore.CompareTo(b.FScore)); //Open= Open.OrderBy(x => x.FScore).ToList(); } Console.WriteLine("Unsolvable problem"); return(null); }