// loads genome from list of saved children, and the index taken from the 'child index' parameter public void load_genome(List <List <List <int> > > children, int index) { Debug.Log("Genome is being loaded from saved genomes"); Debug.Log("child index"); Debug.Log(child_index); Debug.Log("saved_genomes count"); Debug.Log(children.Count); List <List <int> > child = children [index]; inst = Instantiate(inst_prefab); inst.GetComponent <MeshRenderer> ().material.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)); instrument = inst.GetComponent <Rigidbody> (); Genome gen = new Genome(instrument, child [0], child [1], child [2], child [3]); // lib_control = new LibControl (instrument, gen); lib_control = inst.AddComponent <LibControl> (); Debug.Log("Assigning genome to lib_control"); lib_control.instrument_genome = gen; current_genome = lib_control.get_genome(); }
// Use this for initialization void Start() { // make a new instrument // Instantiate(inst_prefab, base_position, Quaternion.identity, true); saved_genomes = new List <List <List <int> > > (); genomes_to_load = new List <List <List <int> > > (); gui_text.enable_text("Generation: 1, first instrument"); generation = 1; inst = Instantiate(inst_prefab); inst.GetComponent <MeshRenderer> ().material.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)); instrument = inst.GetComponent <Rigidbody> (); // Genome gen = new Genome (instrument); // lib_control = new LibControl (instrument, gen); lib_control = inst.AddComponent <LibControl>(); current_genome = lib_control.get_genome(); Debug.Log(genome_string(genome_to_list())); genome_text.enable_text(genome_string(genome_to_list())); Debug.Log("maybe it's a lib control error"); Debug.Log(current_genome); first_generation = true; // instrument_number = 1; }
// create a new instrument with a new genome if the number of instruments is below a threshold public void new_instrument() { Debug.Log("Making a new instrument!"); // for now, always destroy the last instrument destroy_instrument(); // check if it's the first generation, and then if so, don't load any genomes if (generation == 1) { // check the number of saved is <= to the threshold for next generation // if so make new instrument if (saved_genomes.Count <= count_before_evolution) { gui_text.enable_text("New instrument made!"); inst = Instantiate(inst_prefab); inst.GetComponent <MeshRenderer> ().material.color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)); instrument = inst.GetComponent <Rigidbody> (); // Genome gen = new Genome (instrument); // lib_control = new LibControl (instrument, gen); lib_control = inst.AddComponent <LibControl> (); current_genome = lib_control.get_genome(); // instrument_number += 1; // otherwise if the number of instruments has surpassed threshold // need to assign saved genomes to other List, and load first genome } else { // mutate_genome (); generation = generation + 1; child_index = 0; gui_text.enable_text("Generation: " + generation + ". Genome mutated."); Debug.Log("Generation: " + generation); genomes_to_load = mutate_genome(); // blank out saved genomes, so that can assign new genomes to it saved_genomes = new List <List <List <int> > > (); load_genome(genomes_to_load, child_index); child_index++; } // otherwise the genome needs to be loaded from the mutated list } else { // check if limit has been received, and if not, we're just loading the next instrument if (child_index < genomes_to_load.Count) { gui_text.enable_text("instrument number " + child_index + "loaded."); load_genome(genomes_to_load, child_index); child_index++; } // otherwise we need to move on to another generation // for now this just happens when all the mutated instruments have been tested // but could potentially add some random instruments in there, just test and see perhaps. else { generation++; Debug.Log("Generation: " + generation); child_index = 0; genomes_to_load = mutate_genome(); // blank out saved genomes, so that can assign new genomes to it saved_genomes = new List <List <List <int> > > (); load_genome(genomes_to_load, child_index); child_index++; } } }