// returns the linked list in reverse order action* reverse(action *strategy) { // make sure there's at least one element if (strategy == NULL) { return NULL; } // create first element action *copy = make_action(strategy->name, NULL); action *cursor = strategy->next; while (cursor != NULL) { copy = make_action(cursor->name, copy); cursor = cursor->next; } return copy; }
gboolean rra_di_change_hive_name(rra_diff_info *in_info, ustring *in_name) { if (in_info == NULL || in_name == NULL || ustr_strlen(in_name) == 0) { return FALSE; } return add_action(in_info, make_action(RRA_DI_HIVE_NAME_CHANGE, in_name)); }
gboolean rra_di_change_version(rra_diff_info *in_info, HiveVersion *in_version) { if (in_info == NULL || in_version == NULL) { return FALSE; } return add_action(in_info, make_action(RRA_DI_VERSION_CHANGE, in_version)); }
gboolean rra_di_delete_key(rra_diff_info *in_info, ustring *in_path) { if (in_info == NULL || in_path == NULL || ustr_strlen(in_path) == 0) { return FALSE; } return add_action(in_info, make_action(RRA_DI_DELETE_KEY, in_path)); }
int main() { auto add = make_action([](std::string str) { std::cout << str << std::endl; return "(o ) ( o)";}, "ukaz kozy"); auto val = add.execute(); std::cout << val << std::endl; return 0; }
action* create_RHS_action_list(agent* thisAgent, action* actions, condition* cond, ExplainTraceType ebcTraceType) { action* old, *New, *prev, *first; char first_letter; prev = NIL; first = NIL; old = actions; while (old) { New = make_action(thisAgent); if (prev) { prev->next = New; } else { first = New; } prev = New; New->type = old->type; New->preference_type = old->preference_type; New->support = old->support; if (old->type == FUNCALL_ACTION) { New->value = create_RHS_value(thisAgent, old->value, cond, 'v', ebcTraceType); } else { New->id = create_RHS_value(thisAgent, old->id, cond, 's', ebcTraceType); New->attr = create_RHS_value(thisAgent, old->attr, cond, 'a', ebcTraceType); first_letter = first_letter_from_rhs_value(New->attr); New->value = create_RHS_value(thisAgent, old->value, cond, first_letter, ebcTraceType); if (preference_is_binary(old->preference_type)) { New->referent = create_RHS_value(thisAgent, old->referent, cond, first_letter, ebcTraceType); } } old = old->next; } if (prev) { prev->next = NIL; } else { first = NIL; } return first; }
int protocol_parse(char* msg, int msg_len, clientconn_t *c, hash *clients, char* curr_topic) { char *token = NULL; if (msg_len > MAXTOKENSIZE*3) { client_write(c, "* BAD Do not overflow.\r\n", 24); return 0; } char tag[MAXTOKENSIZE]; char command[MAXTOKENSIZE]; char message[MAXTOKENSIZE]; memset(tag,'\0',MAXTOKENSIZE); memset(command,'\0',MAXTOKENSIZE); memset(message,'\0',MAXTOKENSIZE); // Remove trailing \r \n. if (msg!=NULL && strlen(msg) > 2) { msg=remove_crlf(msg, msg_len); } else { return badly_formed(c, msg); } token=strtok(msg, " "); int tok=0; char is_quoted = 0; while(token!=NULL) { if(strlen(token)+1>MAXTOKENSIZE) { client_write(c, "* BAD Do not overflow.\r\n", 24); return 0; } if(tok==0) { strncpy(tag, token, strlen(token)); } else if(tok==1){ strncpy(command, token, strlen(token)); } else if(tok==2){ if(token[0]=='\''||token[0]=='\"') { is_quoted=token[0]; } strncpy(message, token, strlen(token)); } else { strncat(message, " ", 1); strncat(message, token, strlen(token)); } tok++; token = strtok(NULL, " "); } fprintf(stderr, "TAG [%s]\t COMMAND [%s]\t ARGUMENTS [%s]\n", tag, command, message); return make_action(tag, command, message, c, is_quoted, clients, curr_topic); }
void QLearning::play (size_t n_step) { assert(current_state != NULL); QAction action; QCredit credit; /*??? the initial state */ while (n_step--) { action = utility->select_action(current_state); last_state = current_state; current_state = new REAL[state_size]; credit = make_action(action, current_state); add_to_lessons(last_state, action, credit, current_state); } }
action* copy_action(agent* thisAgent, action* pAction) { action* new_action = make_action(thisAgent); new_action->type = pAction->type; new_action->preference_type = pAction->preference_type; new_action->support = pAction->support; if (pAction->type == FUNCALL_ACTION) { new_action->value = copy_rhs_value(thisAgent, pAction->value); } else { new_action->id = copy_rhs_value(thisAgent, pAction->id); new_action->attr = copy_rhs_value(thisAgent, pAction->attr); new_action->value = copy_rhs_value(thisAgent, pAction->value); if (preference_is_binary(pAction->preference_type)) new_action->referent = copy_rhs_value(thisAgent, pAction->referent); } return new_action; }
gboolean rra_di_delete_value(rra_diff_info *in_info, ustring *in_path, ustring *in_name, Value *in_val) { if (in_info == NULL || in_path == NULL || ustr_strlen(in_path) == 0 || in_name == NULL || in_val == NULL) { return FALSE; } rra_di_value_action* va = rra_di_value_action_new(in_path, in_name, in_val, NULL); if (va == NULL) { return FALSE; } return add_action(in_info, make_action(RRA_DI_DELETE_VALUE, va)); }
gboolean rra_di_change_value(rra_diff_info *in_info, ustring *in_path, ustring *in_name, Value *in_val_old, Value *in_val_new) { if (in_info == NULL || in_path == NULL || ustr_strlen(in_path) == 0 || in_name == NULL || in_val_old == NULL || in_val_new == NULL) { return FALSE; } rra_di_value_action* va = rra_di_value_action_new(in_path, in_name, in_val_old, in_val_new); if (va == NULL) { return FALSE; } return add_action(in_info, make_action(RRA_DI_CHANGE_VALUE, va)); }
int main(void) { int n, m; char **maze = read_maze(&n, &m); // initialization fringe *f = fringe_init(); fringe_enqueue(f, make_fringe_item(make_state(0, 0), NULL)); int **closed_set = init_closed_set(n, m); // set up search helper-variables fringe_item *current_item; state *current_state; action *current_strategy; state *next_state; int num_actions, i; int *available_actions; int strategy_found = 0; action *strategy; // perform breadth first search while (!is_empty(f)) { current_item = fringe_dequeue(f); current_state = current_item->state; current_strategy = current_item->strategy; // goal state-check if (is_goal_state(current_state, n, m)) { strategy = current_strategy; strategy_found = 1; break; } // only proceed if the node has not been visited if (is_in_closed_set(current_state, closed_set)) { // free item? continue; } // put the current node into the closed set insert_into_closed_set(current_state, closed_set); // expand current node available_actions = get_actions(current_state, maze, &num_actions); for (i = 0; i < num_actions; i++) { next_state = apply(current_state, available_actions[i]); // add this state/action-pair to the fringe action *new_action = make_action(available_actions[i], current_strategy); fringe_enqueue(f, make_fringe_item(next_state, new_action)); } free(current_item); } if (!strategy_found) { // don't do anything } else { display_and_free(reverse(strategy), make_state(0, 0)); printf("[%d, %d]\n", n - 1, m - 1); } // free maze memory return 0; }