void Allocator::move(index_t original_start, index_t final_start, size_t original_blocks, size_t final_blocks) { void* origin = get_address(original_start); void* destination = get_address(final_start); size_t bytes = std::min(original_blocks, final_blocks) * block_size; memcpy(destination, origin, bytes); fill_map(original_start, original_blocks, false); fill_map(final_start, final_blocks, true); }
int try_castles(int side_length, char * city_map, int ipos) { int max_castles = 0; int cnt_castles = 0; char * search_map = (char *)malloc(side_length * side_length); memcpy (search_map, city_map, side_length * side_length); for(;ipos < side_length * side_length - 1; ++ipos) { if ('.' == search_map[ipos]){ //find the blank and position a castle search_map[ipos] = 'O'; fill_map(side_length, search_map, ipos); cnt_castles = try_castles(side_length, search_map, ipos + 1); cnt_castles += 1; max_castles = max_castles > cnt_castles ? max_castles : cnt_castles; //find the blank but do not position a castle cnt_castles = try_castles(side_length, city_map, ipos + 1); max_castles = max_castles > cnt_castles ? max_castles : cnt_castles; } } //last point if (ipos == side_length * side_length - 1 ) { if ('.' == search_map[ipos]) max_castles = max_castles > 1 ? max_castles : 1; } free(search_map); return max_castles; }
int main(void) { struct map map; int i; srand((unsigned int)time(NULL)); printf("** zDemineur **\n\n"); if(!load(&map)) fill_map(&map); map_gen(&map); while(!iswon(&map)) { #if defined (_WIN32) || defined (_WIN64) system("cls"); #else printf("________________________________________________________\n"); #endif display_map(&map); action(&map); } printf("\nYou won ! Here is the completely visible map :\n"); display_map_debug(&map); for(i = 0; i < map.rows; ++i) free(map.Map[i]); free(map.Map); return 0; }
void Allocator::shrink(index_t pointer_id, size_t required_blocks) { index_t start_block = get_start_block(pointer_id); size_t original_blocks = get_size_blocks(pointer_id); fill_map(start_block + required_blocks, original_blocks - required_blocks, false); this->hash_map[pointer_id].n_blocks = required_blocks; }
void Allocator::free(Pointer &p) { index_t start_block = get_start_block(p.get_id()); size_t n_blocks = get_size_blocks(p.get_id()); fill_map(start_block, n_blocks, false); remove(p.get_id()); p.set_id(-1); }
static void kill_unit (Unit *u){ Node *n = extruct_node(&units, data2node(units, u)); push_node(&dead_units, n); if(u == selected_unit) selected_unit = NULL; else fill_map(selected_unit); }
static void load_game(const gchar * file, gboolean is_reload) { const gchar *gamefile; GameParams *new_params; gchar *new_filename; gint i; if (file == NULL) gamefile = default_game; else gamefile = file; new_params = params_load_file(gamefile); if (new_params == NULL) { error_dialog(_("Failed to load '%s'"), file); return; } if (file == NULL) { g_free(new_params->title); new_params->title = g_strdup("Untitled"); map_free(new_params->map); new_params->map = map_new(); for (i = 0; i < 6; i++) { map_modify_row_count(new_params->map, MAP_MODIFY_INSERT, MAP_MODIFY_ROW_BOTTOM); } for (i = 0; i < 11; i++) { map_modify_column_count(new_params->map, MAP_MODIFY_INSERT, MAP_MODIFY_COLUMN_RIGHT); } new_params->map->chits = g_array_new(FALSE, FALSE, sizeof(gint)); new_filename = NULL; } else { new_filename = g_strdup(file); config_set_string("editor/last-game", new_filename); } guimap_reset(gmap); if (params != NULL) params_free(params); params = new_params; apply_params(params); if (open_filename != NULL) g_free(open_filename); open_filename = new_filename; map_move_robber(gmap->map, -1, -1); fill_map(gmap->map); if (is_reload) { scale_map(gmap); guimap_display(gmap); } update_resize_buttons(); }
static void save_game(const gchar * file) { params = get_params(); canonicalize_map(gmap->map); if (!params_write_file(params, file)) error_dialog(_("Failed to save to '%s'"), file); else config_set_string("editor/last-game", file); fill_map(gmap->map); }
static void apply_move (Event_move e){ Unit *u = id2unit(e.u); if(find_skill(u, S_IGNR)) u->mv -= e.cost; else u->mv = 0; u->stamina -= e.cost; u->m = neib(u->m, e.dir); fill_map(selected_unit); if(u->player == current_player->id) update_fog_after_move(u); }
bool Allocator::realloc_inplace(Pointer &p, size_t required_blocks) { index_t pointer_id = p.get_id(); size_t current_size = get_size_blocks(pointer_id); index_t end_block = get_start_block(pointer_id) + current_size; if(count_free_blocks(end_block) + current_size >= required_blocks) { fill_map(end_block, required_blocks - current_size, true); hash_map[pointer_id].n_blocks = required_blocks; return true; } else { return false; } }
Pointer Allocator::alloc(size_t required_bytes) { size_t required_blocks = bytes_to_blocks(required_bytes); index_t position = find_position(required_blocks); if(position == -1) { throw AllocError(AllocErrorType::NoMemory); } fill_map(position, required_blocks); index_t pointer_id = insert(position, required_blocks); return Pointer(this, pointer_id); }
void Initiator::get_terminals_and_nonterminals(vector<string>* lines) { int i = -1; for (vector<string>::iterator it = lines->begin(); it != lines->end(); it++) { i++; string x = get_nonterminal(*it); if (trim(x).compare("") != 0) non_terminals->push_back(trim(x)); if (i == 0) { starting = x; } vector<string>* y = get_terminals(*it); for (vector<string>::iterator it = y->begin(); it != y->end(); it++) { if (trim((*it)).compare("") != 0) terminals->push_back(trim((*it))); } } fill_map(lines); }
void init_shm_sub(t_share *shared) { t_data *data; data = init_data(); shared = shmat(data->shm_id, 0, 0); if (shared == (void *)-1) exit_error("shmat error\n"); printf("Creating GameP\n"); team_handle_init(shared); shared->nb_team = 0; fill_map(shared); shared->end = FALSE; shared->nb_player = 0; shared->kill = 0; create_sem(); shared->sem_id = data->sem_id; if (shmdt(shared) == -1) exit_error("shmdt() error\n"); }
void get_randmap(t_map **map) { int column; int line; line = 0; srand(time(NULL)); while (line < (*map)->line) { column = 0; while (column < (*map)->column) { if (column == 0 || column == (*map)->line - 1 || line == 0 || line == (*map)->column - 1) (*map)->mapgen[line][column] = 1; else fill_map(map, column, line); column++; } line++; } }
int store_map(Uint32 size, Uint32 line, t_map *info, FILE *fd) { Uint32 i; i = 0; if ((info->data = malloc(sizeof(char *) * (info->x + 1))) == NULL || (info->c_map = malloc(sizeof(int *) * (line + 1))) == NULL) { write(2, "Malloc Failed.\n", 15); return (-1); } while (i != line) if ((info->data[i] = malloc(sizeof(char) * (size + 1))) == NULL || (info->c_map[i++] = malloc(sizeof(int) * (size + 1))) == NULL) { write(2, "Malloc Failed.\n", 15); return (-1); } info->data[i] = NULL; info->c_map[i] = NULL; fill_map(info, fd); return (1); }
/* ** Un quota de ressources doit etre trouver en fonction ** du nombre de joueurs ainsi que la taille de la map. ** On remplit la map aleatoirement selon ce quota ** (x, y en rand). */ void init_map(t_desc *serv) { int quota[7]; int i; int x; int y; i = 0; serv->map = 0; srand(time(0)); get_quota(serv, quota); while (i < 7) { if (quota[i] > 0) { x = rand() % serv->x; y = rand() % serv->y; if (update_exist_case(serv->map, x, y, i) < 0) fill_map(&serv->map, x, y, i); } if (quota[i]-- <= 0) i++; } }
void Cconfig::fill_maps(const Cconfig* v) { { t_attribute<bool> attributes[] = { "bind_before_connect", &m_bind_before_connect, false, "log_peer_connect_failures", &m_log_peer_connect_failures, false, "log_peer_connection_closures", &m_log_peer_connection_closures, false, "log_peer_recv_failures", &m_log_peer_recv_failures, false, "log_peer_send_failures", &m_log_peer_send_failures, false, "log_piece_valid", &m_log_piece_valid, false, "send_stop_event", &m_send_stop_event, false, "upnp", &m_upnp, true, NULL }; fill_map(attributes, v ? &v->m_attributes_bool : NULL, m_attributes_bool); } { t_attribute<int> attributes[] = { "admin_port", &m_admin_port, 6879, "peer_limit", &m_peer_limit, 0, "peer_port", &m_peer_port, 6881, "seeding_ratio", &m_seeding_ratio, 0, "torrent_limit", &m_torrent_limit, 0, "torrent_upload_slots_max", &m_torrent_upload_slots_max, 0, "torrent_upload_slots_min", &m_torrent_upload_slots_min, 0, "upload_rate", &m_upload_rate, 0, "upload_slots", &m_upload_slots, 8, NULL }; fill_map(attributes, v ? &v->m_attributes_int : NULL, m_attributes_int); } { t_attribute<std::string> attributes[] = { "admin_user", &m_admin_user, "xbt", "admin_pass", &m_admin_pass, "", "completes_dir", &m_completes_dir, "Completes", "incompletes_dir", &m_incompletes_dir, "Incompletes", "peer_id_prefix", &m_peer_id_prefix, "", "public_ipa", &m_public_ipa, "", "torrents_dir", &m_torrents_dir, "Torrents", "user_agent", &m_user_agent, "", NULL, NULL, "" }; fill_map(attributes, v ? &v->m_attributes_string : NULL, m_attributes_string); } if (v) { m_local_app_data_dir = v->m_local_app_data_dir; } else { #ifdef WIN32 char path[MAX_PATH]; std::string home = SHGetSpecialFolderPath(NULL, path, CSIDL_PERSONAL, true) ? path : "C:"; #else std::string home = get_env("HOME"); #endif if (home.empty()) m_local_app_data_dir = "."; else { m_completes_dir = home + "/XBT/Completes"; m_local_app_data_dir = home + "/XBT"; m_incompletes_dir = home + "/XBT/Incompletes"; m_torrents_dir = home + "/XBT/Torrents"; } } }
static void reset(void) { bank_reg = 0; fill_map(); }
/* Setup information needed for a specific process. The debugger * assumes that this will hang something onto the process, if nothing * is attached to it, then TV will believe that this process has no * message queue information. */ int mpidbg_init_per_process(mqs_process *process, const mqs_process_callbacks *pcb, struct mpidbg_handle_info_t *handle_types) { mqs_image *image; mpi_image_info *i_info; /* Extract the addresses of the global variables we need and save them away */ mpi_process_info *p_info = (mpi_process_info *) mqs_malloc(sizeof(mpi_process_info)); printf("mpidbg_init_per_process\n"); if (NULL == p_info) { return MPIDBG_ERR_NO_MEM; } /* Setup the callbacks first */ p_info->process_callbacks = pcb; /* Nothing extra (yet) */ p_info->extra = NULL; /* Now we can get the rest of the info */ image = mqs_get_image(process); i_info = (mpi_image_info *) mqs_get_image_info(image); /* Get process info sizes */ mqs_get_type_sizes (process, &p_info->sizes); /* Save the info */ mqs_put_process_info(process, (mqs_process_info *) p_info); /* Fill in pre-defined MPI handle name mappings (because OMPI uses #define's for the pre-defined names, such as "#define MPI_COMM_WORLD &ompi_mpi_comm_world"). */ /* Communicators */ mpidbg_comm_name_map = alloc_map(image, 4); if (NULL != mpidbg_comm_name_map) { int i = 0; fill_map(image, "MPI_COMM_WORLD", "ompi_mpi_comm_world", &mpidbg_comm_name_map[i++]); fill_map(image, "MPI_COMM_SELF", "ompi_mpi_comm_self", &mpidbg_comm_name_map[i++]); fill_map(image, "MPI_COMM_NULL", "ompi_mpi_comm_null", &mpidbg_comm_name_map[i++]); /* Sentinel value */ mpidbg_comm_name_map[i].map_name = NULL; } /* Error handlers */ mpidbg_errhandler_name_map = alloc_map(image, 4); if (NULL != mpidbg_errhandler_name_map) { int i = 0; fill_map(image, "MPI_ERRORS_ARE_FATAL", "ompi_mpi_errors_are_fatal", &mpidbg_errhandler_name_map[i++]); fill_map(image, "MPI_ERRORS_RETURN", "ompi_mpi_errors_return", &mpidbg_errhandler_name_map[i++]); fill_map(image, "MPI_ERRHANDLER_NULL", "ompi_mpi_errhandler_null", &mpidbg_errhandler_name_map[i++]); /* MPI::ERRORS_THROW_EXCEPTIONS exists as a symbol in OMPI; no need to alias it here */ /* Sentinel value */ mpidbg_errhandler_name_map[i].map_name = NULL; } /* Requests */ mpidbg_request_name_map = alloc_map(image, 2); if (NULL != mpidbg_request_name_map) { int i = 0; fill_map(image, "MPI_REQUEST_NULL", "ompi_request_null", &mpidbg_request_name_map[i++]); /* Sentinel value */ mpidbg_request_name_map[i].map_name = NULL; } /* Statuses */ mpidbg_status_name_map = alloc_map(image, 2); if (NULL != mpidbg_status_name_map) { int i = 0; fill_map(image, "MPI_STATUS_IGNORE", NULL, &mpidbg_status_name_map[i++]); /* Sentinel value */ mpidbg_status_name_map[i].map_name = NULL; } /* All done */ return MPIDBG_SUCCESS; }
void Cconfig::fill_maps(const Cconfig* v) { { t_attribute<bool> attributes[] = { { "auto_register", &m_auto_register, false }, { "anonymous_announce", &m_anonymous_announce, true }, { "anonymous_scrape", &m_anonymous_scrape, true }, { "daemon", &m_daemon, true }, { "debug", &m_debug, false }, { "full_scrape", &m_full_scrape, false }, { "gzip_scrape", &m_gzip_scrape, true }, { "log_access", &m_log_access, false }, { "log_announce", &m_log_announce, false }, { "log_scrape", &m_log_scrape, false }, { NULL, NULL, false } }; fill_map(attributes, v ? &v->m_attributes_bool : NULL, m_attributes_bool); } { t_attribute<int> attributes[] = { { "announce_interval", &m_announce_interval, 1800 }, { "clean_up_interval", &m_clean_up_interval, 60 }, { "read_config_interval", &m_read_config_interval, 60 }, { "read_db_interval", &m_read_db_interval, 60 }, { "scrape_interval", &m_scrape_interval, 0 }, { "write_db_interval", &m_write_db_interval, 15 }, { NULL, NULL, 0 } }; fill_map(attributes, v ? &v->m_attributes_int : NULL, m_attributes_int); } { t_attribute<std::string> attributes[] = { { "column_files_completed", &m_column_files_completed, "completed" }, { "column_files_fid", &m_column_files_fid, "fid" }, { "column_files_leechers", &m_column_files_leechers, "leechers" }, { "column_files_seeders", &m_column_files_seeders, "seeders" }, { "column_users_uid", &m_column_users_uid, "uid" }, { "mysql_database", &m_mysql_database, "xbt" }, { "mysql_host", &m_mysql_host, "" }, { "mysql_password", &m_mysql_password, "" }, { "mysql_table_prefix", &m_mysql_table_prefix, "xbt_" }, { "mysql_user", &m_mysql_user, "" }, { "offline_message", &m_offline_message, "" }, { "pid_file", &m_pid_file, "" }, { "query_log", &m_query_log, "" }, { "redirect_url", &m_redirect_url, "" }, { "table_announce_log", &m_table_announce_log, "" }, { "table_files", &m_table_torrents, "" }, { "table_files_users", &m_table_torrents_users, "" }, { "table_scrape_log", &m_table_scrape_log, "" }, { "table_users", &m_table_users, "" }, { "torrent_pass_private_key", &m_torrent_pass_private_key, "" }, { NULL, NULL, "" } }; fill_map(attributes, v ? &v->m_attributes_string : NULL, m_attributes_string); } if (v) { m_listen_ipas = v->m_listen_ipas; m_listen_ports = v->m_listen_ports; } }
void Cconfig::fill_maps(const Cconfig* v) { { t_attribute<bool> attributes[] = { "auto_register", &m_auto_register, false, "anonymous_connect", &m_anonymous_connect, true, "anonymous_announce", &m_anonymous_announce, true, "anonymous_scrape", &m_anonymous_scrape, true, "daemon", &m_daemon, true, "debug", &m_debug, false, "full_scrape", &m_full_scrape, false, "gzip_debug", &m_gzip_debug, true, "gzip_scrape", &m_gzip_scrape, true, "log_access", &m_log_access, false, "log_announce", &m_log_announce, false, "log_scrape", &m_log_scrape, false, // TorrentPier begin "gdc", &m_gdc, true, "free_leech", &m_free_leech, false, "trust_ipv6", &m_trust_ipv6, false, // TorrentPier end NULL }; fill_map(attributes, v ? &v->m_attributes_bool : NULL, m_attributes_bool); } { t_attribute<int> attributes[] = { "announce_interval", &m_announce_interval, 1800, "clean_up_interval", &m_clean_up_interval, 60, "read_config_interval", &m_read_config_interval, 60, "read_db_interval", &m_read_db_interval, 60, "scrape_interval", &m_scrape_interval, 0, "write_db_interval", &m_write_db_interval, 15, // TorrentPier begin "read_files_interval", &m_read_files_interval, 60, // TorrentPier end "read_db_expeers_interval", &m_read_db_expeers_interval, 30, NULL }; fill_map(attributes, v ? &v->m_attributes_int : NULL, m_attributes_int); } { t_attribute<std::string> attributes[] = { "column_files_completed", &m_column_files_completed, "completed", "column_files_fid", &m_column_files_fid, "fid", "column_files_leechers", &m_column_files_leechers, "leechers", "column_files_seeders", &m_column_files_seeders, "seeders", "column_users_uid", &m_column_users_uid, "uid", "mysql_database", &m_mysql_database, "xbt", "mysql_host", &m_mysql_host, "localhost", "mysql_password", &m_mysql_password, "", "mysql_table_prefix", &m_mysql_table_prefix, "xbt_", "mysql_user", &m_mysql_user, "", "offline_message", &m_offline_message, "", "pid_file", &m_pid_file, "", "query_log", &m_query_log, "", "redirect_url", &m_redirect_url, "", "table_announce_log", &m_table_announce_log, "", "table_deny_from_hosts", &m_table_deny_from_hosts, "", "table_files", &m_table_files, "", "table_files_users", &m_table_files_users, "", "table_scrape_log", &m_table_scrape_log, "", "table_users", &m_table_users, "", "torrent_pass_private_key", &m_torrent_pass_private_key, "", // TorrentPier begin "column_files_dl_percent", &m_column_files_dl_percent, "", "column_users_can_leech", &m_column_users_can_leech, "", "column_users_torrents_limit", &m_column_users_torrents_limit, "", // TorrentPier end // VIP begin "column_users_vip_status", &m_column_users_vip_status, "0", // VIP end // X-Real-IP "set_real_ip", &m_set_real_ip, "127.0.0.1", NULL, NULL, "" }; fill_map(attributes, v ? &v->m_attributes_string : NULL, m_attributes_string); } if (v) { m_listen_ipas = v->m_listen_ipas; m_listen_ports = v->m_listen_ports; } }