public IEnumerable <MOVE> Solve(NPuzzle Puzzle, IEvaluation Eval) { List <NPuzzleNode> Open = new List <NPuzzleNode>(); List <NPuzzleNode> Closed = new List <NPuzzleNode>(); NPuzzleNode Goal = null; Open.Add(new NPuzzleNode(null, Puzzle, Eval)); while (Open.Count > 0) { NPuzzleNode U = Open[0]; Open.RemoveAt(0); Closed.Add(U); if (U.H == 0.0f) { Goal = U; break; } foreach (NPuzzleNode S in U.Successors()) { if (!Open.Contains(S) && !Closed.Contains(S)) { Open.Add(S); } } } return(Goal.State.PreviousMoves); }
public IEnumerable <N_Puzzle.MOVE> Solve(NPuzzle Puzzle, IEvaluation Eval) { List <NPuzzleNode> Open = new List <NPuzzleNode>(); List <NPuzzleNode> Closed = new List <NPuzzleNode>(); NPuzzleNode Goal = null; Open.Add(new NPuzzleNode(null, Puzzle, Eval)); while (Open.Count > 0) { NPuzzleNode Q = Open[0]; Open.Remove(Q); if (Q.H == 0.0f) { Goal = Q; break; } foreach (NPuzzleNode S in Q.Successors()) { if (!Closed.Contains(S)) { NPuzzleNode AlreadyExploredOpen = Open.Find(N => N.Equals(S)); if (AlreadyExploredOpen != null) { if (AlreadyExploredOpen.F > S.F) { Open.Remove(AlreadyExploredOpen); Open.InsertSorted(S); } } else { Open.InsertSorted(S); } } } Closed.Add(Q); } return(Goal.State.PreviousMoves); }