Ejemplo n.º 1
0
        public DNA Mate(DNA mother)
        {
            DNA baby = new DNA(0, 0);

            baby.specie.RemoveMember(baby);
            baby.specie = null;

            baby.CloneInto(nodes, axons);

            for (int n = 0; n < mother.nodes.Count; n++)
            {
                if (n < baby.nodes.Count)
                {
                    Node fnode = nodes[n];
                    Node mnode = mother.nodes[n];

                    if (fnode.inovation == mnode.inovation)
                    {
                        if (AiMath.PercentChance(50f))
                        {
                            baby.nodes[n] = mnode.Clone();
                        }
                        else
                        {
                            baby.nodes[n] = fnode.Clone();
                        }
                    }
                }
                else
                {
                    baby.nodes.Add(mother.nodes[n]);
                }
            }

            for (int a = 0; a < mother.axons.Count; a++)
            {
                if (a < baby.axons.Count)
                {
                    Axon faxon = axons[a];
                    Axon maxon = mother.axons[a];

                    if (faxon.inovation == maxon.inovation)
                    {
                        if (AiMath.PercentChance(50f))
                        {
                            baby.axons[a] = maxon.Clone();
                        }
                        else
                        {
                            baby.axons[a] = faxon.Clone();
                        }
                    }
                }
                else
                {
                    baby.axons.Add(mother.axons[a]);
                }
            }

            if (AiMath.PercentChance(Node.mutationChance / 100f))
            {
                nodes.Add(Node.NewNode());
            }

            if (AiMath.PercentChance(Axon.mutationChance))
            {
                SafeAxon();
            }

            baby.GetSpecie(specie);
            baby.ID = inovation + "-" + mother.inovation + "/" + baby.inovation;
            return(baby);
        }