void choose_action(t_data *data) { int prior1; int prior2; prior1 = data->shared->pos == 0 ? 6 : data->shared->pos - 1; prior2 = (data->shared->pos + 1) % 7; if (data->i == prior1 || data->i == prior2) { repos(data); choose_action(data); } prior2 = 0; prior1 = gauche(data); if (prior1 == 1) prior2 = data->i; if (data->etat == 2) { if (prior1 == 1) reflechi_other(data); else repos(data); choose_action(data); } prior1 += droite(data); choose_action2(data, prior1, prior2); choose_action(data); }
std::string facebook_client::choose_request_url( int request_type, std::string* data, std::string* get_data ) { std::string url = choose_proto( request_type ); url.append( choose_server( request_type, data, get_data ) ); url.append( choose_action( request_type, data, get_data ) ); return url; }
std::string Omegle_client::choose_request_url( int request_type, std::string* data, std::string* get_data ) { std::string url = ""; url.append( choose_server( request_type, data, get_data )); url.append( choose_action( request_type, data, get_data )); return url; }
/* FUNCION MAIN DEL PROGRAMA BUSCA */ int main(int argc, char *argv[]) { char *list[256]; int num_filts; /*int ejec; int i;*/ accfunc actfunc = NULL; filtfunc filt = NULL; opt_t *opt = (opt_t *) malloc(sizeof(opt_t) + sizeof(char *) * (argc - 6)); if (opt == NULL) exit(ENOMEM); /*Falta memoria*/ if(argc<5 || !strcmp(argv[1],"-h")) { fprintf(POCARG); return 0; } parse_args(argc, argv, opt); actfunc = choose_action((*opt).accion); filt = choose_filter((*opt).filtro); num_filts = parse_dir(opt, filt, list); ejecuta(opt, actfunc, num_filts, list); free(opt); return (RET_VAL); }
/* * Find the best "action path" available from the given state. * * We also return the score of the endstate that will result. * * We return -1 if no legal actions are available. * * This function is recursive. */ static double find_action(game *g) { game sim; player *p; int old_turn; int i, n; action legal[MAX_ACTION], best_act; double score, b_s = -1; /* Get player pointer */ p = &g->p[g->turn]; /* Get current player's turn */ old_turn = g->turn; /* Check for game over */ if (g->game_over) { /* Clear any choice nodes that haven't been examined */ node_len = node_pos; /* Return end of game score */ return eval_game(g, g->sim_turn); } /* Check for choice to make */ if (node_pos < node_len) { /* Handle choice node instead of normal */ return choose_action(g); } /* Avoid needlees work when checking for forced retreat */ if (checking_retreat && !must_retreat) return 0; /* Get legal actions to take */ n = legal_act(g, legal); /* Check for no legal actions */ if (!n) return -1; /* Check for only one possible action */ if (n == 1) { /* Increase path position for future searching */ best_path_pos++; #ifdef DEBUG /* Remember current path */ cur_path[best_path_pos] = legal[0]; #endif /* Perform that action */ perform_act(g, legal[0]); /* Check for turn change */ if (g->turn != old_turn) { /* Are we checking opponent's response */ if (checking_retreat) { /* Score is unimportant */ score = 0.0; /* We must not be forced to retreat */ must_retreat = 0; } else { /* Check for inevitable retreat from opponent */ check_retreat(g); /* Get score */ score = eval_game(g, g->sim_turn); /* Clear must retreat flag */ must_retreat = 0; } } /* Continue searching */ else score = find_action(g); /* Return to current path position */ best_path_pos--; /* Check for better actions than previously discovered */ if (!checking_retreat && score >= best_path_score) { /* Store action in best path */ best_path[best_path_pos] = legal[0]; /* Save best score seen */ best_path_score = score; } /* Return score */ return score; } /* Increase path position for future searching */ best_path_pos++; /* Loop over available actions */ for (i = 0; i < n; i++) { #ifdef DEBUG /* Remember current path */ cur_path[best_path_pos] = legal[i]; #endif /* Avoid unnecessary work when checking for forced retreat */ if (checking_retreat && !must_retreat) break; /* Copy game */ simulate_game(&sim, g); /* Perform action */ perform_act(&sim, legal[i]); /* Check for retreat */ if (legal[i].act == ACT_RETREAT && node_pos == node_len) { /* Are we checking for forced retreat */ if (checking_retreat) { /* Score is unimportant */ score = 0; } else { /* Get score */ score = eval_game(&sim, sim.sim_turn); } } /* Normal action */ else { /* Continue searching */ score = find_action(&sim); } /* Check for better score among actions */ if (score >= b_s) { /* Remember best */ b_s = score; best_act = legal[i]; } } /* Return to current path position */ best_path_pos--; /* Check for better actions than previously discovered */ if (!checking_retreat && b_s >= best_path_score) { /* Store action in best path */ best_path[best_path_pos] = best_act; /* Save best score seen */ best_path_score = b_s; } /* Return best score */ return b_s; }
http::response facebook_client::flap(RequestType request_type, std::string* request_data, std::string* request_get_data, int method) { NETLIBHTTPREQUEST nlhr = {sizeof(NETLIBHTTPREQUEST)}; nlhr.requestType = !method ? choose_method(request_type) : method; std::string url = choose_proto(request_type); url.append(choose_server(request_type, request_data, request_get_data)); url.append(choose_action(request_type, request_data, request_get_data)); nlhr.szUrl = (char*)url.c_str(); nlhr.flags = NLHRF_HTTP11 | choose_security_level(request_type); nlhr.headers = get_request_headers(nlhr.requestType, &nlhr.headersCount); #ifdef _DEBUG nlhr.flags |= NLHRF_DUMPASTEXT; #else nlhr.flags |= NLHRF_NODUMP; #endif switch (request_type) { case REQUEST_MESSAGES_RECEIVE: nlhr.timeout = 1000 * 65; break; default: nlhr.timeout = 1000 * 20; break; } if (request_data != NULL) { nlhr.pData = (char*)(*request_data).c_str(); nlhr.dataLength = (int)request_data->length(); } parent->debugLogA("@@@@@ Sending request to '%s'", nlhr.szUrl); switch (request_type) { case REQUEST_LOGIN: nlhr.nlc = NULL; break; case REQUEST_MESSAGES_RECEIVE: nlhr.nlc = hMsgCon; nlhr.flags |= NLHRF_PERSISTENT; break; default: WaitForSingleObject(fcb_conn_lock_, INFINITE); nlhr.nlc = hFcbCon; nlhr.flags |= NLHRF_PERSISTENT; break; } NETLIBHTTPREQUEST* pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)handle_, (LPARAM)&nlhr); mir_free(nlhr.headers[3].szValue); mir_free(nlhr.headers); http::response resp; switch (request_type) { case REQUEST_LOGIN: case REQUEST_SETUP_MACHINE: break; case REQUEST_MESSAGES_RECEIVE: hMsgCon = pnlhr ? pnlhr->nlc : NULL; break; default: ReleaseMutex(fcb_conn_lock_); hFcbCon = pnlhr ? pnlhr->nlc : NULL; break; } if (pnlhr != NULL) { parent->debugLogA("@@@@@ Got response with code %d", pnlhr->resultCode); store_headers(&resp, pnlhr->headers, pnlhr->headersCount); resp.code = pnlhr->resultCode; resp.data = pnlhr->pData ? pnlhr->pData : ""; CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pnlhr); } else { parent->debugLogA("!!!!! No response from server (time-out)"); resp.code = HTTP_CODE_FAKE_DISCONNECTED; // Better to have something set explicitely as this value is compaired in all communication requests } // Get Facebook's error message if (resp.code == HTTP_CODE_OK) { std::string::size_type pos = resp.data.find("\"error\":"); if (pos != std::string::npos) { pos += 8; int error_num = atoi(resp.data.substr(pos, resp.data.find(",", pos) - pos).c_str()); if (error_num != 0) { std::string error = ""; pos = resp.data.find("\"errorDescription\":\"", pos); if (pos != std::string::npos) { pos += 20; error = resp.data.substr(pos, resp.data.find("\"", pos) - pos); error = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(error))); error = ptrA( mir_utf8decodeA(error.c_str())); } std::string title = ""; pos = resp.data.find("\"errorSummary\":\"", pos); if (pos != std::string::npos) { pos += 16; title = resp.data.substr(pos, resp.data.find("\"", pos) - pos); title = utils::text::trim(utils::text::special_expressions_decode(utils::text::slashu_to_utf8(title))); title = ptrA( mir_utf8decodeA(title.c_str())); } bool silent = resp.data.find("\"silentError\":1") != std::string::npos; resp.error_number = error_num; resp.error_text = error; resp.error_title = title; resp.code = HTTP_CODE_FAKE_ERROR; parent->debugLogA(" ! ! Received Facebook error: %d -- %s", error_num, error.c_str()); if (notify_errors(request_type) && !silent) client_notify(_A2T(error.c_str())); } } } return resp; }
http::response Omegle_client::flap(const int request_type, std::string *post_data, std::string *get_data) { http::response resp; // Prepare the request NETLIBHTTPREQUEST nlhr = { sizeof(NETLIBHTTPREQUEST) }; // Set request URL std::string url = choose_server(request_type) + choose_action(request_type, get_data); nlhr.szUrl = (char*)url.c_str(); // Set timeout (bigger for channel request) nlhr.timeout = 1000 * ((request_type == OMEGLE_REQUEST_EVENTS) ? 65 : 20); // Set request type (GET/POST) and eventually also POST data if (post_data != NULL) { nlhr.requestType = REQUEST_POST; nlhr.pData = (char*)(*post_data).c_str(); nlhr.dataLength = (int)post_data->length(); } else { nlhr.requestType = REQUEST_GET; } // Set headers - it depends on requestType so it must be after setting that nlhr.headers = get_request_headers(nlhr.requestType, &nlhr.headersCount); // Set flags nlhr.flags = NLHRF_HTTP11; #ifdef _DEBUG nlhr.flags |= NLHRF_DUMPASTEXT; #else nlhr.flags |= NLHRF_NODUMP; #endif // Set persistent connection (or not) switch (request_type) { case OMEGLE_REQUEST_HOME: nlhr.nlc = NULL; break; case OMEGLE_REQUEST_EVENTS: nlhr.nlc = hEventsConnection; nlhr.flags |= NLHRF_PERSISTENT; break; default: WaitForSingleObject(connection_lock_, INFINITE); nlhr.nlc = hConnection; nlhr.flags |= NLHRF_PERSISTENT; break; } parent->debugLogA("@@@@@ Sending request to '%s'", nlhr.szUrl); // Send the request NETLIBHTTPREQUEST *pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)handle_, (LPARAM)&nlhr); mir_free(nlhr.headers); // Remember the persistent connection handle (or not) switch (request_type) { case OMEGLE_REQUEST_HOME: break; case OMEGLE_REQUEST_EVENTS: hEventsConnection = pnlhr ? pnlhr->nlc : NULL; break; default: ReleaseMutex(connection_lock_); hConnection = pnlhr ? pnlhr->nlc : NULL; break; } // Check and copy response data if (pnlhr != NULL) { parent->debugLogA("@@@@@ Got response with code %d", pnlhr->resultCode); store_headers(&resp, pnlhr->headers, pnlhr->headersCount); resp.code = pnlhr->resultCode; resp.data = pnlhr->pData ? pnlhr->pData : ""; parent->debugLogA("&&&&& Got response: %s", resp.data.c_str()); CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pnlhr); } else { parent->debugLogA("!!!!! No response from server (time-out)"); resp.code = HTTP_CODE_FAKE_DISCONNECTED; // Better to have something set explicitely as this value is compaired in all communication requests } return resp; }
Consume_item Medical_bag::activate(Actor* const actor) { if (player_bon::bg() == Bg::ghoul) { msg_log::add("It is of no use to me."); cur_action_ = Med_bag_action::END; return Consume_item::no; } std::vector<Actor*> seen_foes; map::player->seen_foes(seen_foes); if (!seen_foes.empty()) { msg_log::add("Not while an enemy is near."); cur_action_ = Med_bag_action::END; return Consume_item::no; } cur_action_ = choose_action(); msg_log::clear(); if (cur_action_ == Med_bag_action::END) { return Consume_item::no; } //Check if chosen action can be done switch (cur_action_) { case Med_bag_action::treat_wounds: if (map::player->hp() >= map::player->hp_max(true)) { msg_log::add("I have no wounds to treat."); cur_action_ = Med_bag_action::END; return Consume_item::no; } break; case Med_bag_action::sanitize_infection: if (!actor->has_prop(Prop_id::infected)) { msg_log::add("I have no infection to sanitize."); cur_action_ = Med_bag_action::END; return Consume_item::no; } break; case Med_bag_action::END: {} break; } bool is_enough_suppl = true; switch (cur_action_) { case Med_bag_action::sanitize_infection: is_enough_suppl = tot_suppl_for_sanitize() <= nr_supplies_; break; case Med_bag_action::treat_wounds: //Costs one supply per turn case Med_bag_action::END: {} break; } if (!is_enough_suppl) { msg_log::add("I do not have enough supplies for that."); cur_action_ = Med_bag_action::END; return Consume_item::no; } //Action can be done map::player->active_medical_bag = this; switch (cur_action_) { case Med_bag_action::treat_wounds: msg_log::add("I start treating my wounds..."); nr_turns_until_heal_wounds_ = MEDICAL_BAG_NR_TRN_BEFORE_HEAL; break; case Med_bag_action::sanitize_infection: msg_log::add("I start to sanitize an infection..."); nr_turns_left_sanitize_ = tot_turns_for_sanitize(); break; case Med_bag_action::END: break; } game_time::tick(); return Consume_item::no; }
int main (int argc , char* argv[]){ char dir[PATH_MAX]; char BUFFER[LINE_LENGTH]; int commands_counter = 0; linked_list *head = 0; var_list *var_head = 0; cmdLine *command; while(1){ getcwd(dir, PATH_MAX); printf("The current dir is: %s \n", dir); fgets(BUFFER, LINE_LENGTH, stdin); command = parseCmdLines(BUFFER); if(strncmp(command->arguments[0], "!", 1) == 0){ int place = atoi(&command->arguments[0][1]); if(place < 0 || place > commands_counter){ perror("Error, out of bounds"); }else{ freeCmdLines(command); char *repeat = getCommand(head, place); command = parseCmdLines(repeat); strcpy(BUFFER, repeat); } } int i; for(i = 0; i<command->argCount; i++){ if(strncmp(command->arguments[i], "$", 1) == 0){ char *change = &command->arguments[i][1]; char *fut_change = getArgu(var_head, change); replaceCmdArg(command, i, fut_change); } } if(strcmp(command->arguments[0], "set") == 0){ var_list *newVar = malloc(sizeof(var_list)); char *str1 = calloc(strlen(command->arguments[1])+1, sizeof(char)); char *str2 = calloc(strlen(command->arguments[2])+1, sizeof(char)); strcpy(str1, command->arguments[1]); strcpy(str2, command->arguments[2]); newVar->name = str1; newVar->value = str2; newVar->next = 0; var_head = setValue(var_head, newVar); } else if(strcmp(command->arguments[0], "delete") == 0){ var_head = delete_var(var_head, command->arguments[1]); } else if((choose_action(command, head, var_head)) == 1){ freeCmdLines(command); break; } linked_list *newNode = malloc(sizeof(linked_list)); char *str = calloc(strlen(BUFFER)+1, sizeof(char)); strcpy(str, BUFFER); newNode->command = str; newNode->next = 0; head = list_append(head, newNode); freeCmdLines(command); commands_counter++; } list_free(head); var_free(var_head); return 0; }