void mutate(float chance, int *population, int population_size, int **playable_dates, int *playable_date_sizes, int team_size) { int treshold = chance * 1000; for (int i = 0; i < team_size; i++) { if (arc4random_uniform(1000) <= treshold) { choose_random((population + (i * (team_size - 1))), team_size - 1, playable_dates[i], playable_date_sizes[i]); } } }
int* generate_random_population(int **playable_dates, int *playable_date_sizes, int team_size) { int population_size = team_size * (team_size - 1); int *population = calloc(population_size, sizeof(int)); for (int i = 0; i < team_size; i++) { choose_random((population + (i * (team_size - 1))), team_size - 1, playable_dates[i], playable_date_sizes[i]); } return population; }
/** * If node->type is T_TEXT then appends append->content * to destination. * * @param *node Node deals with * @param *destination String to appending node->content * @param *pos Pointer to current position in destination string * @param max_symbols Length of buffer (destination) * * TODO: Rename */ static void compile(Node *node, char *destination, unsigned int *pos, unsigned int max_symbols) { char *dst = NULL; Node *random = NULL; int i; switch (node->type) { case T_TEXT: dst = node->content; while (*dst && *pos < max_symbols - 1) { destination[(*pos)++] = *dst++; } break; case T_CHOISE: random = choose_random(node->childs, node->number_of_childs); if (random) { compile(random, destination, pos, max_symbols); } break; case T_LIST: for (i = 0; i < node->number_of_childs; ++i) { compile(node->childs[i], destination, pos, max_symbols); } break; case T_POSSIBILITY: if (random_lt(2) == 1 && node->number_of_childs != 0) { compile(node->childs[0], destination, pos, max_symbols); } break; default: /* Ignore other types */ /* TODO: Error on T_UNDEFINED */ break; } /* Moved from T_TEXT section here for security reasons Error occurs While node->number_of_childs == 0 */ destination[*pos] = '\0'; }