void main() { int i, test = 0; // set from global variable int generation = m; Individual best; randomize(); worldInit(); populationInit(1); // 100% of population fitness(); // explicit, not in populationInit() best = getBestIndividual(); for(i = 0; i < maxGenerations; i++){ if(test){ printf("#generation: %4d, fitness: %4d\n", i, best.fitness); }else{ printf("#generation: %4d, fitness: %4d\n", i, best.fitness); printAxisOfBest(best); } if(generation == 0){ // a) (K == xAxis) ? K = 1 : K++; // b) //K = random(xAxis); // c) //if(K == 10) K = 25; else K = 10; worldInit(); populationInit(3); // reinicialize 30% of population fitness(); generation = m; }else{ generation--; } selection(); crossover(); mutation(); fitness(); best = getBestIndividual(); } printf("#generation: %4d, fitness: %4d\n", i, best.fitness); if(!test) printAxisOfBest(best); }
int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition(0, 0); glutInitWindowSize(800, 800); glutCreateWindow("OutingWithLove"); worldInit(); glutReshapeFunc(myReshape); glutDisplayFunc(&display); glutMainLoop(); return 0; }
int main(int argc, char *argv[]) { printf("MMB version %s, \"%s\"\n\n", VERSION, CODENAME); render = renderInit(argc, argv); camera = &(render->camera); generatorInit(); world = worldInit(generatorGetBlock); worldrenderInit(world, camera); ray = worldrenderGetRay(world, camera); glutDisplayFunc(&onDisplay); glutReshapeFunc(&onReshape); renderHookMouse(&onMouse, NULL); renderRun(); return EXIT_SUCCESS; }
void main() { int i; int isUnique; Individual best; randomize(); worldInit(); // max 4 unique individuals, 5 and more last long to find while(uniques < 4){ populationInit(); fitness(); for(i = 0; i < maxGenerations; i++){ selection(); crossover(); mutation(); fitness(); best = getBestIndividual(); if(best.fitness == maxFitness){ isUnique = unique(best); if(isUnique){ theBestOf[uniques] = best; uniques++; } break; } } } printAxisOfBest(); }
int main(){ int quit=0; world_t * clarkson; room_t * prev = NULL; char cmd[MAX_CMD_ARGS][BUF_LEN]; char inp[BUF_LEN]; inp[BUF_LEN-1] = 0; srand(time(NULL)); clarkson = malloc(sizeof(world_t)); worldInit(clarkson); /* Load data, create world */ init(clarkson); /* This loop takes commands until one works */ while(!quit) { /* Show room updates */ if (prev != clarkson->room) { watsup(clarkson->room); prev = clarkson->room; } printf("What do? "); fgets(inp, BUF_LEN-1, stdin); /* Get commands */ parse(inp, cmd); if (striEqu(cmd[0],"quit")) quit=1; else if (striEqu(cmd[0],"north")) go(NORTH, &clarkson->room); else if (striEqu(cmd[0],"south")) go(SOUTH, &clarkson->room); else if (striEqu(cmd[0],"east")) go(EAST, &clarkson->room); else if (striEqu(cmd[0],"west")) go(WEST, &clarkson->room); else if (striEqu(cmd[0],"up")) go(UP, &clarkson->room); else if (striEqu(cmd[0],"down")) go(DOWN, &clarkson->room); else if (striEqu(cmd[0],"go")) go(direction(cmd[1]), &clarkson->room); else if (striEqu(cmd[0],"take")) take(clarkson->room->items, clarkson->inventory, cmd[1]); else if (striEqu(cmd[0],"drop")) drop(clarkson->room->items, clarkson->inventory, cmd[1]); else if (striEqu(cmd[0],"look")) watsup(clarkson->room); else if (striEqu(cmd[0],"inv")) showinv(clarkson->inventory); else if (striEqu(cmd[0],"examine")) examine(clarkson->inventory, clarkson->room->items, cmd[1]); else idontunderstand(cmd[0]); trigVerify(clarkson); } /* free() everything */ for (quit = 0; quit < clarkson->allItems->capacity; quit++) { free(clarkson->allItems->itemArray[quit]->name); free(clarkson->allItems->itemArray[quit]->description); free(clarkson->allItems->itemArray[quit]->examine); free(clarkson->allItems->itemArray[quit]); } free(clarkson->allItems->itemArray); free(clarkson->allItems); /* TODO Fix freeing of triggers. */ /* This kludgery reduces it to 81 bytes per run */ free(clarkson->allTrigs[0].res->param[0].s); free(clarkson->allTrigs); for (quit = 0; quit < clarkson->numRooms; quit++) { free(clarkson->allRooms[quit].items->itemArray); free(clarkson->allRooms[quit].items); free(clarkson->allRooms[quit].description); } free(clarkson->allRooms); free(clarkson->inventory->itemArray); free(clarkson->inventory); free(clarkson); return 0; }