//Best-first search informed search public string BestFS() { var heap = new NodesMinHeap(new Node(null, this, null, 0)); Node ans = null; while (ans == null) { //While we haven't found solution var top = heap.Remove(); //Get from the heap the best move foreach (var move in top.state.PossibleMoves()) { RushHour r = top.state.Clone(); r.Move(move); Node next = new Node(top, r, move, top.height + 1); if (r.CanReachGoal()) { //Found solution ans = new Node(next, null, "XR" + r.Heuristic2(), top.height + 2); } else { //Add node to the heap (if the state is new) heap.Insert(next); } } } return(ans.GetSolution()); }
public Node(Node p, RushHour r, string a, int h) { action = a; parent = p; height = h; if (r != null) { state = r.Clone(); heuristic = r.Heuristic1() + h; } }