public void breed() { ga.breed(); System.Random random = new System.Random(); chosen = ga.results[random.Next(ga.results.Count)]; Debug.Log(chosen); chosen.buildModel(); ga.updatePopulation(ga.results.Take(3).ToList()); }
public GameObject instantiate(string tag, Transform transform, NEAT.Person part) { GameObject res = null; if (pool.Count > 0) { res = pool[pool.Count - 1]; pool.RemoveAt(pool.Count - 1); res.transform.parent = activesTransform; res.transform.position = transform.position; res.transform.rotation = transform.rotation; if (part.network == null) { part.buildModel(); } res.GetComponent <Particle>().weapon = part.network; res.GetComponent <Particle>().shooterTag = tag; res.GetComponent <Particle>().enabled = true; res.SetActive(true); } return(res); }
// Start is called before the first frame update void Start() { /*var watch = System.Diagnostics.Stopwatch.StartNew(); * * * a = (NEAT.Person)ScriptableObject.CreateInstance("NEAT.Person"); * * NEAT.GENES.Node a1 = new NEAT.GENES.Node(NEAT.GENES.Node.NODE.IN, 0); * NEAT.GENES.Node a2 = new NEAT.GENES.Node(NEAT.GENES.Node.NODE.IN, 1); * NEAT.GENES.Node b1 = new NEAT.GENES.Node(NEAT.GENES.Node.NODE.HIDDEN, 2); * NEAT.GENES.Node c1 = new NEAT.GENES.Node(NEAT.GENES.Node.NODE.HIDDEN, 3); * NEAT.GENES.Node d1 = new NEAT.GENES.Node(NEAT.GENES.Node.NODE.OUT, 4); * NEAT.GENES.Node d2 = new NEAT.GENES.Node(NEAT.GENES.Node.NODE.OUT, 5); * * NEAT.GENES.Connection a1b1 = new NEAT.GENES.Connection(a1.nb, b1.nb, 0.5f); * NEAT.GENES.Connection a2b1 = new NEAT.GENES.Connection(a2.nb, b1.nb, 0.5f); * NEAT.GENES.Connection b1c1 = new NEAT.GENES.Connection(b1.nb, c1.nb, 0.5f); * NEAT.GENES.Connection c1d1 = new NEAT.GENES.Connection(c1.nb, d1.nb, 0.5f); * NEAT.GENES.Connection a1d1 = new NEAT.GENES.Connection(a1.nb, d1.nb, 0.5f); * NEAT.GENES.Connection c1d2 = new NEAT.GENES.Connection(c1.nb, d2.nb, 0.5f); * NEAT.GENES.Connection b1d2 = new NEAT.GENES.Connection(b1.nb, d2.nb, 0.2f); * a.node_gene.Add(a1); * a.node_gene.Add(a2); * a.node_gene.Add(b1); * a.node_gene.Add(c1); * a.node_gene.Add(d1); * a.node_gene.Add(d2); * * a.node_connect.Add(a1b1); * a.node_connect.Add(a2b1); * a.node_connect.Add(b1c1); * a.node_connect.Add(c1d1); * a.node_connect.Add(a1d1); * a.node_connect.Add(c1d2); * a.node_connect.Add(b1d2); * * a.buildModel(); * watch.Stop(); * Debug.Log(watch.ElapsedMilliseconds); * * List<float> inputs = new List<float>(); * inputs.Add(0.5f); * inputs.Add(0.5f); * Debug.Log(a.network.evaluate(inputs)[0]); * Debug.Log(a.network.evaluate(inputs)[1]);*/ //a.instantiate(); a.buildModel(); //b.instantiate(); b.buildModel(); c.buildModel(); foreach (NEAT.GENES.Connection connection in a.node_connect) { NEAT.GENES.Connection.addConnection(connection); } foreach (NEAT.GENES.Connection connection in b.node_connect) { NEAT.GENES.Connection.addConnection(connection); } foreach (NEAT.GENES.Connection connection in c.node_connect) { NEAT.GENES.Connection.addConnection(connection); } List <NEAT.Person> population = new List <NEAT.Person>(); population.Add(a); population.Add(b); population.Add(c); Debug.Log(a); Debug.Log(b); Debug.Log(c); NEAT.GENES.Connection.global_innov = 7; ga = new GA.GA <NEAT.Person>(population, new GA.Selection.NEAT_Selection(), new GA.Crossover.NEAT_Crossover(), new GA.Mutation.NEAT_Mutation(), new GA.Fitness.NEAT_Fitness(), 10, 0.05f, 0.2f); //ga.breed(); //for (int i = 0; i < ga.results.Count; i++) // Debug.Log(ga.results[i]); //a.network.randomizeWeight(); chosen = a; }