void handle_food_pop(t_server *server) { int i; int x; int y; i = 0; server_log(1, 0, "Don't worry, be happy ! Food pop !\n"); x = rand() % server->game_infos.size_x; y = rand() % server->game_infos.size_y; new_object_list(new_object(FOOD), &(server->map[y][x])); update_food_gra(server, x, y); i++; }
//Returns an array of all the threads that are running.... thread_container* init_dds_python(Dict* config){ Py_Initialize(); if(dict_has_key(config, "plugins")){ Dict* val = dict_get_val(config, "plugins"); char* cur_plugin; char* plugins_list_str = val->value; obj_list plugin_list = new_object_list(); cur_plugin = strtok(plugins_list_str, ","); while(cur_plugin){ //import_plugin(cur_plugin); init_plugin(cur_plugin, plugin_list); cur_plugin = strtok(NULL, ","); } int index = 0; int len = obj_list_len(plugin_list); PyObject* cb_dict = make_callback_dict(plugin_list); for(;index < len;index++){ give_callback_registration_oppertunity(obj_list_get(plugin_list, index), cb_dict); } thread_container* result = make_thread_container(); PyObject* mt_tuple = PyTuple_New(0); for(index = 0; index < len;index++){ PyObject* cur = obj_list_get(plugin_list, index); PyObject* needsThread = PyObject_GetAttrString(cur, "needsThread"); if(!needsThread){ printf("Couldn't get the needsThread method...\n"); PyErr_Print(); } PyObject* doesNeed = PyObject_Call(needsThread, mt_tuple, NULL); if(!doesNeed){ printf("Couldn't call the needsThread method...\n"); PyErr_Print(); } if(PyObject_IsTrue(doesNeed)){ PyObject* getName = PyObject_GetAttrString(cur, "getName"); if(!getName){ printf("Couldn't get the getName function...\n"); PyErr_Print(); } PyObject* nameStr = PyObject_Call(getName, mt_tuple, NULL); if(!nameStr){ printf("Couldn't call the get name function...\n"); PyErr_Print(); } Py_DECREF(getName); plugin_thread* tmp_thread = make_plugin_thread(PyString_AS_STRING(nameStr)); Py_DECREF(nameStr); PyObject* runMethod = PyObject_GetAttrString(cur, "run"); if(!runMethod){ printf("Couldn't get the run method...\n"); PyErr_Print(); }else{ pthread_create(&tmp_thread->thread, NULL, run_plugin, (void*)runMethod); } thread_container_add(result, tmp_thread); }else{ //TODO figure out what we want to happen here xD } Py_DECREF(doesNeed); Py_DECREF(needsThread); } Py_DECREF(mt_tuple); Py_DECREF(cb_dict); del_object_list(plugin_list); return result; } }
/**************************************************************************** * Return a list containing the empirical column frequency distributions * for all alignments in the input. * * Each file in the list of filenames is read and the species list is * determined. The counts of each occurring column are tallied. * All files with the same species lists get their counts combined. * * The returned list contains one distribution per species list that * occurs in some alignment. ****************************************************************************/ OBJECT_LIST_T* get_alignment_column_freqs_list (ALPH_T alph, STRING_LIST_T* filenames, BOOLEAN_T remove_allgap_seqs) { int file_index; int num_filenames = get_num_strings(filenames); ARRAY_T* alignment_column_freqs = NULL; OBJECT_LIST_T* alignment_column_freqs_list = new_object_list(equal_string_lists, (void*)copy_string_list, free_string_list, free_array); // Consider each alignment in turn. for(file_index = 0; file_index < num_filenames; file_index++) { char* filename = get_nth_string(file_index, filenames); if (verbosity >= NORMAL_VERBOSE && !(file_index % 1)) { fprintf( stderr, "Computing column freqs: alignment file number %d of %d total files.\n", file_index+1, num_filenames ); } // Read the alignment int ref_seq_index = 0; ALIGNMENT_T* alignment = read_alignment_from_file(filename, TRUE, remove_allgap_seqs, &ref_seq_index); STRING_LIST_T* alignment_species = get_species_names(alignment); // Try to retrieve the counts so far for this list of species. alignment_column_freqs = (ARRAY_T*)retrieve_object( alignment_species, alignment_column_freqs_list ); // Found counts for current species list? if (alignment_column_freqs) { // Add counts from current alignment. (void) build_alignment_column_counts(alph, alignment, alignment_column_freqs); // Note: objects in lists are references, so no need to re-store // after modification. } // Didn't find counts for this species list, so create new array of counts. else { alignment_column_freqs = build_alignment_column_counts(alph, alignment, NULL); store_object( (void*)alignment_column_freqs, (void*)alignment_species, 0.0, // Score alignment_column_freqs_list ); } // free space used by alignment free_alignment(alignment); } // each filename fprintf(stderr, "\n"); // Convert counts to frequencies by retrieving each array of counts // and dividing by the total counts for that list of species. while ( (alignment_column_freqs = retrieve_next_object(alignment_column_freqs_list) ) != NULL ) { int i; int num_freqs = get_array_length(alignment_column_freqs); double total_counts; // Get total counts. for (i=total_counts=0; i<num_freqs; i++) { total_counts += get_array_item(i, alignment_column_freqs); } // Get frequencies. for (i=0; i<num_freqs; i++) { double f = get_array_item(i, alignment_column_freqs); set_array_item(i, f/total_counts, alignment_column_freqs); #ifdef DEBUG int asize = alph_size(alph, ALPH_SIZE); int num_leaves = NINT(log(num_freqs)/log(asize)); char* alignment_col = mm_malloc((num_leaves + 1) * sizeof(char)); unhash_alignment_col( alph, i, //col_index alignment_col, num_leaves ); printf("%s %g %g\n", alignment_col, f, f/total_counts); myfree(alignment_col); #endif } // get frequencies } // while more species lists return(alignment_column_freqs_list); } // get_alignment_column_freqs_list