static void challenges(void) { destroyBattle(); game.currentMission = NULL; initChallengeHome(); }
void updateValueFunction(struct ValueFunction *valueFunction,struct GeneScore *geneScore){ testGene(valueFunction,geneScore); // printf("New gene total score: %d\n",geneScore->score); if(geneScore->score > getGeneScore(valueFunction,0)->score) { struct Battle *battleA; struct Battle *battleB; int i; for(i=1;i<VF_SIZE;i++) { battleA = duel(getGene(valueFunction,i),geneScore->gene); battleB = duel(getGene(valueFunction,i),getGene(valueFunction,0)); getGeneScore(valueFunction,i)->score += (battleA->score - battleB->score); destroyBattle(battleA); destroyBattle(battleB); } memcpy(valueFunction->geneScores[0],geneScore,sizeof(struct GeneScore)); insertionSort(valueFunction->geneScores,VF_SIZE); } }
// test genescore against the value function void testGene(struct ValueFunction *valueFunction,struct GeneScore *geneScore){ int i; struct Battle *battle; // don't test against lowest-valued gene for(i=1;i<VF_SIZE;i++) { battle = duel(geneScore->gene,getGene(valueFunction,i)); geneScore->score += battle->score; destroyBattle(battle); } }
void initTitle(void) { startSectionTransition(); stopMusic(); app.delegate.logic = &logic; app.delegate.draw = &draw; memset(&app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS); battle.camera.x = battle.camera.y = 0; destroyBattle(); logo = getTexture("gfx/title/logo.png"); pandoranWar = getTexture("gfx/title/pandoran.png"); background = getTexture("gfx/backgrounds/background02.jpg"); earthTexture = getTexture("gfx/planets/earth.png"); earth.x = rand() % SCREEN_WIDTH; earth.y = -(128 + (rand() % 128)); initBackground(); initEffects(); initFighters(); updateAllMissions(); getWidget("campaign", "title")->action = campaign; getWidget("challenges", "title")->action = challenges; getWidget("trophies", "title")->action = trophies; getWidget("stats", "title")->action = stats; getWidget("fighterDB", "title")->action = fighterDatabase; getWidget("options", "title")->action = options; getWidget("credits", "title")->action = credits; getWidget("quit", "title")->action = quit; getWidget("ok", "stats")->action = ok; getWidget("ok", "trophies")->action = ok; getWidget("ok", "fighterDB")->action = ok; show = SHOW_TITLE; endSectionTransition(); playMusic("music/main/Rise of spirit.ogg", 0); }
void cleanup(void) { SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Cleaning up ..."); SDL_DestroyRenderer(app.renderer); SDL_DestroyWindow(app.window); destroyLookups(); destroyTextures(); expireTexts(1); destroyFonts(); destroySounds(); destroyGame(); destroyFighterDefs(); destroyCapitalShipDefs(); destroyBulletDefs(); destroyItemDefs(); destroyStarSystems(); destroyBattle(); destroyGalacticMap(); destroyWidgets(); destroyResources(); destroyCredits(); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Done"); TTF_Quit(); SDL_Quit(); }
int main(){ int iterations; int print; int silent; printf("Enter total number of iterations:\n"); scanf("%d",&iterations); printf("Enter number of iterations to average score over: \n"); scanf("%d",&print); printf("Enter 1 to run program in background and save results to results.txt: \n"); scanf("%d",&silent); if(silent == 1) { daemon(1,0); } // creates a value function set with VF_SIZE random good genes struct ValueFunction *valueFunction = createValueFunction(); if(silent != 1) printf("Genes built\n"); int i; int j; struct Battle *battle; // makes each gene fight each other gene and calculates their total score for(i=0;i<VF_SIZE;i++) { for(j=i;j<VF_SIZE;j++) { battle = duel(getGene(valueFunction,i),getGene(valueFunction,j)); getGeneScore(valueFunction,i)->score += battle->score; getGeneScore(valueFunction,j)->score += (20 - battle->score); destroyBattle(battle); } } geneSort(valueFunction->geneScores,VF_SIZE); // print the score of every gene // for(i=0;i<VF_SIZE;i++) // { // printf("Gene %d total score: %d\n",i,getGeneScore(valueFunction,i)->score); // } char *threes = "33333333333333333333333333333333333333333333333333"; // battle = duel(getGene(valueFunction,VF_SIZE-1),threes); // printf("Best gene score against threes: %d\n",battle->score); // destroyBattle(battle); // test adding another gene struct GeneScore *geneScore = createBetterGeneScore(); float average = 0; for(i=0;i<iterations;i++) { updateValueFunction(valueFunction,geneScore); average += ((float)geneScore->score)/(float)print; if(i % print == 0 && i != 0){ if(silent == 1) { FILE *fptr; fptr = fopen("results.txt","w"); for(i=0;i<VF_SIZE;i++) { fprintf(fptr,"%s #%d average score: %f\n",getGene(valueFunction,i),i,(float)getGeneScore(valueFunction,i)->score/VF_SIZE); } battle = duel(getGene(valueFunction,VF_SIZE-1),threes); fprintf(fptr,"Best gene score against threes: %d\n",battle->score); destroyBattle(battle); fclose(fptr); average = (float)0; } else { printf("Average score: %f\n",average); average = (float)0; } } // geneScore = createBetterGeneScore(); geneScore = createNthGeneScore(3); } destroyGeneScore(geneScore); battle = duel(getGene(valueFunction,VF_SIZE-1),threes); // print the score of every gene if(silent == 1) { FILE *fptr; fptr = fopen("results.txt","w"); for(i=0;i<VF_SIZE;i++) { fprintf(fptr,"%s #%d average score: %f\n",getGene(valueFunction,i),i,(float)getGeneScore(valueFunction,i)->score/VF_SIZE); } fprintf(fptr,"Best gene score against threes: %d\n",battle->score); fclose(fptr); } else { for(i=0;i<VF_SIZE;i++) { printf("Gene %d average score: %f\n",i,(float)getGeneScore(valueFunction,i)->score/VF_SIZE); printf("Gene: %s\n",getGene(valueFunction,i)); } } destroyBattle(battle); destroyValueFunction(valueFunction); return 0; }
static void campaign(void) { destroyBattle(); initGalacticMap(); }