public void mctsSearch(int numIterations) { MyLineRenderer.Init(); for (int i = 0; i < numIterations; i++) { currentState.Save(); birdPosList = new List <Vector3>(); birdPosList.Add(currentState.birdPos); MCTS_TreeNode selected = treePolicy(); float reward = selected.rollOut(); backUp(selected, reward); MyLineRenderer.lineStrips.Add(birdPosList); } }
public override Action GetAction() { MyLineRenderer.Init(); //Initialize population for (int i = 0; i < 2; i++) { populations[i].Clear(); } popIndex = 0; for (int i = 0; i < sizeGeneration; i++) { populations[popIndex].Add(RandomChromosome()); } if (lastBestChromosome != "") { //TODO: Your code here (Q1): Overwrite populations[popIndex][0] with the shifted version of last best chromosome. } for (int g = 1; g <= numGenerations; g++) { EvaluateCurrentPopulation(); FillMatingPool(); CrossOver(); Mutation(); Elitism(); popIndex = 1 - popIndex; } //Go over the population one last time to find the best answer found by GA EvaluateCurrentPopulation(); //print(populations[popIndex][eliteIndex]); //Now extract first action from populations[popIndex][eliteIndex] lastBestChromosome = populations[popIndex][eliteIndex]; int actionIdx = lastBestChromosome[0] == '0' ? 0 : 1; return((Action)(actionIdx)); }