private IEnumerator FullSimulation() { Debug.Log("Starting simulation"); Debug.Log("Seeding initial generation"); List <Individual> originalPop = init.CreateInitialGeneration(generationSize, individualLength); generations.CurrentGeneration.Add(originalPop); while (true) { Debug.Log("Simulating generation " + generations.GenerationCount); simulationStep = StartCoroutine(GenerationStep()); while (lockedInGenerationStep) { yield return(new WaitForSeconds(.1f)); } generations.CurrentGeneration.Sort(); if (CheckTerminator()) { break; } Debug.Log("Selecting using " + selector.GetType().Name); List <string> parents = selector.SelectFromGeneration(generations.CurrentGeneration); List <string> children = new List <string>(); Debug.Log("Recombining using " + recombiner.GetType().Name); for (int i = 0; i < parents.Count;) { children.Add(recombiner.Combine(parents[i++], parents[i++])); } Debug.Log("Mutating using " + mutator.GetType().Name); for (int i = 0; i < children.Count; i++) { children[i] = mutator.Mutate(children[i]); } generations.NewGeneration.Add(children); } Debug.Log("The end of days has arrived, kneel before your master and accept your DOOM!"); generations.UpdateHighScoreList(generations.CurrentGeneration); Time.timeScale = 1; individualDisplay.SetActive(true); carExecutors[cars[0]].CurrentIndividual = generations.GetFittestIndividualFromHistory(); for (int i = cars.Count - 1; i > 0; i--) { GameObject car = cars[i]; cars.Remove(car); carStates.Remove(car); carExecutors.Remove(car); Destroy(car); } while (true) { yield return(new WaitUntil(() => carExecutors[cars[0]].IsFinished)); yield return(new WaitForSeconds(4f)); carStates[cars[0]].Reset(); carExecutors[cars[0]].CurrentIndividual = generations.GetFittestIndividualFromHistory(); } }
static void Postfix(ISelector ___focusSelector, ref HomeTarget __result) { if (!enabled || Module <ScenarioModule> .Self.CurrentScenarioName != "Main" || __result == null) { return; } if (___focusSelector.GetType() != typeof(FarmViewer) || !outsideUnits.ContainsKey(__result.itemPutInfo.cellIndex)) { return; } Vector3 vector = GetValidPos(__result.pos); if (vector != Vector3.zero) { __result.pos = vector; } }
private IEnumerator FullSimulation() { Debug.Log("Starting simulation"); Debug.Log("Seeding initial generation"); List <Individual> originalPop = init.CreateInitialGeneration(generationSize, individualLength); generations.CurrentGeneration.Add(originalPop); while (true) { Debug.Log("Simulating generation " + generations.GenerationCount); StartCoroutine(GenerationStep()); while (lockedInGenerationStep) { yield return(new WaitForSeconds(.1f)); } generations.CurrentGeneration.Sort(); if (CheckTerminator()) { break; } Debug.Log("Selecting using " + selector.GetType().Name); List <string> parents = selector.SelectFromGeneration(generations.CurrentGeneration); List <string> children = new List <string>(); Debug.Log("Recombining using " + recombiner.GetType().Name); for (int i = 0; i < parents.Count;) { children.Add(recombiner.Combine(parents[i++], parents[i++])); } Debug.Log("Mutating using " + mutator.GetType().Name); for (int i = 0; i < children.Count; i++) { children[i] = mutator.Mutate(children[i]); } generations.NewGeneration.Add(children); } //ui.SetVisibility(true); Debug.Log("The end of days has arrived, kneel before your master and accept your DOOM!"); generations.UpdateHighScoreList(generations.CurrentGeneration); generations.CurrentGeneration.Individuals.Sort((i1, i2) => (int)(i1.Fitness * 100 - i2.Fitness * 100)); for (int i = 0; i < 10; i++) { Debug.Log((i + 1) + ".: " + generations.CurrentGeneration.Individuals[i].GeneSequence + " (" + generations.CurrentGeneration.Individuals[i].Fitness + ")"); } Time.timeScale = 1; carExecutors[cars[0]].CurrentIndividual = generations.CurrentGeneration.Individuals[0]; for (int i = 1; i < cars.Count; i++) { Destroy(cars[i]); } while (true) { yield return(new WaitUntil(() => carExecutors[cars[0]].IsFinished)); fireworks.time = 0; fireworks.Play(); yield return(new WaitForSeconds(4f)); carStates[cars[0]].Reset(); carExecutors[cars[0]].CurrentIndividual = generations.CurrentGeneration.Individuals[0]; } }