//------------------------------------------------------------------------------------- public node solve(node start, bool huristic)//true for hamming , false manhatten { queue.add_to_priority_queue(start, huristic); node new_node = new node(start); close_open_set.Add(new_node.puzzle_string, new_node); return(find_goal(huristic)); }
//-------------------------------------------------------------------------------- public void search_exist_befor(ref SortedDictionary <String, node> closed, ref priority_queue queue, bool huristic, String direction, ref SortedDictionary <String, node> to_del) { if (closed.ContainsKey(this.puzzle_string)) { node temp = new node(); temp = closed[this.puzzle_string]; if (temp.flag_open_or_closed == true) ////exit in open list { if (temp.fn > this.fn) { to_del.Add(this.puzzle_string, closed[this.puzzle_string]); closed.Remove(this.puzzle_string); node nody = new node(this); nody.node_direction = direction; queue.add_to_priority_queue(nody, huristic); closed.Add(this.puzzle_string, nody); } } else //exist in closed list { if (temp.fn > this.fn) { closed.Remove(this.puzzle_string); node nody = new node(this); nody.node_direction = direction; queue.add_to_priority_queue(nody, huristic); closed.Add(this.puzzle_string, nody); } } } else { node success_node = new node(this); success_node.node_direction = direction; queue.add_to_priority_queue(success_node, huristic); closed.Add(success_node.puzzle_string, success_node); } //################################################## if (direction == "down") { this.move_up(huristic); } else if (direction == "up") { this.move_down(huristic); } else if (direction == "left") { this.move_right(huristic); } else { this.move_left(huristic); } //##################################################### this.moves--; this.moves--; this.calculate_fn(huristic); }