Beispiel #1
0
        private void Mutate_WeightRandomize(Random rand)
        {
            if (connGeneSet.Count > 0)
            {
                ConnectionGene conn = ConnectionGeneSet.Select(x => x).OrderBy(x => rand.Next()).FirstOrDefault();

                conn.RandomizeWeight();
            }
        }
Beispiel #2
0
        private void Mutate_Node(Random rand)
        {
            //UnityEngine.Debug.Log("starting mutate node");
            if (ConnectionGeneSet.Count > 0)
            {
                ConnectionGene conn = ConnectionGeneSet.OrderBy(x => rand.Next()).FirstOrDefault();

                //for(int i=0;i<ConnectionGeneSet.Count;i++)
                //{

                //ConnectionGene conn = ConnectionGeneSet.ElementAt(i);


                NodeGene nodeFrom = NodeGeneSet.Where(x => x.Id.Equals(conn.NodeIn)).FirstOrDefault(),
                         nodeTo   = NodeGeneSet.Where(x => x.Id.Equals(conn.NodeOut)).FirstOrDefault();

                NodeGene node = pool.NodeGene_Get(conn.ReplaceIndex);


                node.x = (nodeFrom.x + nodeTo.x) * .5f;
                node.y = (nodeFrom.y + nodeTo.y) * (.4f + rand.Next(1, 20) * .01f);

                node.y = (node.y >= 1f) ? 0.99f : (node.y <= 0f) ? 0.01f : node.y;

                ConnectionGene connA = pool.ConnectionGene_GetOrCreate(conn.NodeIn, node.Id),
                               connB = pool.ConnectionGene_GetOrCreate(node.Id, conn.NodeOut);

                connA.RandomizeWeight();
                connA.IsEnabled = true;

                connB.IsEnabled = conn.IsEnabled;
                connB.Weight    = conn.Weight;

                connGeneSet.Add(connA);
                connGeneSet.Add(connB);

                conn.IsEnabled = false;

                nodeGeneSet.Add(node);

                //}


                // UnityEngine.Debug.Log("mutate node succesfull");
            }
        }