*/bool AStarPath::path_search(MapCoord &start, MapCoord &goal) {//DEBUG(0,LEVEL_DEBUGGING,"SEARCH: %d: %d,%d -> %d,%d\n",actor->get_actor_num(),start.x,start.y,goal.x,goal.y); astar_node *start_node = new astar_node; start_node->loc = start; start_node->to_start = 0; start_node->to_goal = path_cost_est(start, goal); start_node->score = start_node->to_start + start_node->to_goal; start_node->len = 0; push_open_node(start_node); const uint32 max_score = get_max_score(start_node->to_goal); const uint32 max_steps = 8*2*4; // walk up to four screen lengths before searching again while(!open_nodes.empty()) { astar_node *nnode = pop_open_node(); // next closest if(nnode->loc == goal || nnode->len >= max_steps) { if(nnode->loc != goal) DEBUG(0,LEVEL_DEBUGGING,"out of steps, making partial path (nnode->len=%d)\n",nnode->len); //DEBUG(0,LEVEL_DEBUGGING,"GOAL\n"); final_node = nnode; create_path(); delete_nodes(); return(true); // reached goal - success } // check cardinal neighbors (starting at top going clockwise) search_node_neighbors(nnode, goal, max_score); // node and neighbors checked, put into closed closed_nodes.push_back(nnode); } //DEBUG(0,LEVEL_DEBUGGING,"FAIL\n"); delete_nodes(); return(false); // out of open nodes - failure }/* Return the cost of moving one step from `c1' to `c2', which is always 1. This
/* * @brief Function to delete nodes of the tree */ void delete_nodes(struct node *tree_node) { if (tree_node == NULL) return; else { delete_nodes(tree_node->left); delete_nodes(tree_node->right); printf("Deleting node: %d\n", tree_node->data); free(tree_node); } }
void try_reclaim(node* old_head) { if (threads_in_pop == 1) { // claim list of to-be-deleted nodes node* nodes_to_delete = to_be_deleted.exchange(nullptr); // are you the only thread in pop()? if (!--threads_in_pop) { // on other thread can be accessing this list of pending nodes. // There may be new pending nodes, but you're not bothered // about them for now, as long as it's safe to reclaim your // list. delete_nodes(nodes_to_delete); } else if (nodes_to_delete) { // not safe to reclaim the nodes, so if there are any, // you must chain them back onto the list of nodes // pending deletion. // This can happen if there are multiple threads accessing the // data structure concurrently. Other threads might have // called pop() in between the first tet of thread_in_pop and // the "claiming" of the list, potentially adding new nodes to // the list that are still being accesed by one or more of // those other threads. chain_pending_nodes(nodes_to_delete); } delete old_head; } else { // not safe to delete any nodes, add the node to the pending list chain_pending_node(old_head); --threads_in_pop; } }
static void delete_duplicates (slist_t **head, size_t *list_size) { slist_t *entry = *head; while (entry) { delete_nodes (&entry->next, list_size, entry->val); entry = entry->next; } }
/* -------------------------------------------------------------------------------------- void delete_state(CHESS_STATE *cs) purpose: deletes the children from a chess state (and all children recursively). ---------------------------------------------------------------------------------------*/ void delete_nodes(CHESS_STATE *cs) { CHESS_STATE *p; CHESS_STATE *q; for (p = cs->child_head; p != NULL; p = q) { q = p->next; delete_nodes(p); free(p); p=NULL; } cs->child_head=NULL; }
void try_reclaim(node* old_head) { if (1 == threads_in_pop) { node* nodes_to_delete = to_be_deleted.exchange(nullptr); if (!--threads_in_pop) { delete_nodes(nodes_to_delete); } else if(nodes_to_delete) { chain_pending_nodes(nodes_to_delete); } delete old_head; } else { chain_pending_node(old_head); --threads_in_pop; } }
/* ----------------------------------------------------- This gets all the child moves and compares them to a string of moves ALL the moves must match ----------------------------------------------------*/ void check_contains_moves(CHESS_STATE *current_state, char *expected_moves) { CHESS_STATE *child_states; char buffer[100] = {0}; strcpy(buffer,expected_moves); generate_moves(current_state); char *next_expected_move = strtok(buffer, ","); while(next_expected_move != NULL) { char *move_text; int found = 0; for (child_states = current_state->child_head; child_states != NULL; child_states = child_states->next) { move_text = get_move(child_states,0); if (strcmp(move_text, next_expected_move)==0) { found=1; break; } } if (found==0) { printf("%s not found!\n",next_expected_move); for (child_states = current_state->child_head; child_states!=NULL; child_states = child_states->next) { move_text=get_move(child_states,0); printf("%s ",move_text); } exit(1); } next_expected_move = strtok(NULL,","); } delete_nodes(current_state); }
void xed_dot_graph_deallocate(xed_dot_graph_t* g) { delete_nodes(g); delete_edges(g); free(g); }
/* * @brief Function to delete the tree */ void delete_tree(struct node **node) { delete_nodes(*node); *node = NULL; }
void delete_nodes (ACE_Allocator* allocator) { this->allocator_ = allocator; delete_nodes (); }
void modify_selected_meshes(document_state& DocumentState, iplugin_factory* Modifier) { return_if_fail(Modifier); idocument& document = DocumentState.document(); if (Modifier->implements(typeid(imulti_mesh_sink))) { // Mesh modifier taking multiple inputs uint_t count = 0; ipipeline::dependencies_t dependencies; const nodes_t selected_nodes = selection::state(DocumentState.document()).selected_nodes(); // Create the node inode* multi_sink = pipeline::create_node(document, *Modifier); record_state_change_set changeset(document, string_cast(boost::format(_("Add Modifier %1%")) % Modifier->name()), K3D_CHANGE_SET_CONTEXT); nodes_t nodes_to_delete; for(nodes_t::const_iterator node = selected_nodes.begin(); node != selected_nodes.end(); ++node) { imesh_sink* const mesh_sink = dynamic_cast<imesh_sink*>(*node); if(!mesh_sink) continue; imatrix_sink* const matrix_sink = dynamic_cast<imatrix_sink*>(*node); iproperty* source_mesh = document.pipeline().dependency(mesh_sink->mesh_sink_input()); if (!source_mesh) continue; if (matrix_sink) // Insert a transform node { iproperty* const source_transformation = document.pipeline().dependency(matrix_sink->matrix_sink_input()); if (source_transformation) { inode* transform_points = plugin::create<inode>("TransformPoints", document, unique_name(document.nodes(), "TransformPoints")); return_if_fail(transform_points); imatrix_sink* transform_points_matrix_sink = dynamic_cast<imatrix_sink*>(transform_points); return_if_fail(transform_points_matrix_sink); imesh_sink* transform_points_mesh_sink = dynamic_cast<imesh_sink*>(transform_points); return_if_fail(transform_points_mesh_sink); dependencies.insert(std::make_pair(&transform_points_matrix_sink->matrix_sink_input(), source_transformation)); dependencies.insert(std::make_pair(&transform_points_mesh_sink->mesh_sink_input(), source_mesh)); imesh_source* transform_points_mesh_source = dynamic_cast<imesh_source*>(transform_points); return_if_fail(transform_points_mesh_source); source_mesh = &transform_points_mesh_source->mesh_source_output(); imesh_selection_sink* selection_sink = dynamic_cast<imesh_selection_sink*>(transform_points); return_if_fail(selection_sink); property::set_internal_value(selection_sink->mesh_selection_sink_input(), k3d::geometry::selection::create(1.0)); } } ++count; // Create a new user property std::stringstream name, label; name << "input_mesh" << count; label << "Input Mesh " << count; iproperty* sink = property::get(*multi_sink, name.str()); if (!sink) sink = property::create<mesh*>(*multi_sink, name.str(), label.str(), "", static_cast<mesh*>(0)); // Store the connection dependencies.insert(std::make_pair(sink, source_mesh)); // Delete the input node nodes_to_delete.push_back(*node); } document.pipeline().set_dependencies(dependencies); delete_nodes(document, nodes_to_delete); // Give nodes a chance to initialize their property values based on their inputs, if any ... if(ireset_properties* const reset_properties = dynamic_cast<ireset_properties*>(multi_sink)) reset_properties->reset_properties(); panel::mediator(DocumentState.document()).set_focus(*multi_sink); } else { // Normal mesh modifier nodes_t new_modifiers; const nodes_t selected_nodes = selection::state(DocumentState.document()).selected_nodes(); for(nodes_t::const_iterator node = selected_nodes.begin(); node != selected_nodes.end(); ++node) { new_modifiers.push_back(modify_mesh(DocumentState, **node, Modifier)); assert_warning(new_modifiers.back()); } // Show the new modifier properties if only one was processed if(selected_nodes.size() == 1) { panel::mediator(DocumentState.document()).set_focus(*new_modifiers.front()); } else // otherwise connect all parameter properties to the first node and show that one { iproperty_collection* first_property_collection = dynamic_cast<iproperty_collection*>(new_modifiers.front()); if (first_property_collection) { // Get the in-and output property names, to exclude them from the connections imesh_sink* const modifier_sink = dynamic_cast<imesh_sink*>(new_modifiers.front()); return_if_fail(modifier_sink); imesh_source* const modifier_source = dynamic_cast<imesh_source*>(new_modifiers.front()); return_if_fail(modifier_source); const std::string sink_name = modifier_sink->mesh_sink_input().property_name(); const std::string source_name = modifier_source->mesh_source_output().property_name(); ipipeline::dependencies_t dependencies; const iproperty_collection::properties_t& first_properties = first_property_collection->properties(); nodes_t::iterator modifier = new_modifiers.begin(); ++modifier; for (modifier; modifier != new_modifiers.end(); ++modifier) { iproperty_collection* property_collection = dynamic_cast<iproperty_collection*>(*modifier); return_if_fail(property_collection); const iproperty_collection::properties_t& properties = property_collection->properties(); iproperty_collection::properties_t::const_iterator property = properties.begin(); for (iproperty_collection::properties_t::const_iterator first_property = first_properties.begin(); first_property != first_properties.end(); ++first_property) { return_if_fail(property != properties.end()); return_if_fail((*property)->property_name() == (*first_property)->property_name()); if ((*property)->property_name() == sink_name || (*property)->property_name() == source_name || (*property)->property_name() == "name") { ++property; continue; } dependencies.insert(std::make_pair(*property, *first_property)); ++property; } } document.pipeline().set_dependencies(dependencies); panel::mediator(DocumentState.document()).set_focus(*new_modifiers.front()); } } } }
/* -------------------------------------------------------------------------------------- int alpha_beta(CHESS_STATE *node, int depth, int alpha, int beta) purpose: alpha-beta pruning evaluation of minimax algorithm the algorithm always returns an absolute number regardless of player's color. + = good - = bad beta represents previous player's best choice. Doesn't want it if alpha would worsen it. ---------------------------------------------------------------------------------------*/ int alpha_beta(CHESS_STATE *node, int current_depth, int fixed_depth_horizon, int alpha, int beta, ITERATIVE_DEEPENING_INFO *id_info) { // leaf node test (include quiescence search) // note that we extend the current depth to go 1 PAST // the fixed depth horizon, to allow for check validation // at the leaf node. The quiescence search will automatically // cater for check validation if (current_depth>fixed_depth_horizon && !node->flg_is_noisy) { id_info[current_depth-1].moves_evaluated++; return node->board_value; } // otherwise, get opponents moves generate_moves(node); current_depth++; CHESS_STATE *p; CHESS_STATE *q; for (p = node->child_head; p != NULL; p = q) { q = p->next; if (node->flg_is_white_move) { // maximiser if (alpha>=beta) { break; // cutoff } int ab = alpha_beta(p, current_depth, fixed_depth_horizon, alpha, beta, id_info); if (ab > alpha) { alpha=ab; int d; if (current_depth==1) id_info[fixed_depth_horizon].best_move = get_move(p,0); } } else { // minimiser if (alpha>=beta) { break; // cutoff } int ab = alpha_beta(p, current_depth, fixed_depth_horizon, alpha, beta, id_info); if (ab < beta)// { beta=ab; int d; if (current_depth==1) id_info[fixed_depth_horizon].best_move = get_move(p,0); } } } // legal moves (only required for depth 1) if (current_depth==1) { CHESS_STATE *child; int i=0; for (child=node->child_head; child!=NULL; child=child->next) { if (child->flg_is_illegal==0) { id_info[1].legal_moves[i] = get_move(child,0); i++; } } id_info[1].legal_move_count=i; } delete_nodes(node); if (node->flg_is_white_move) { // maximier return alpha; } else { return beta; } }