Esempio n. 1
0
            public static Node NewNode()
            {
                Node node = new Node();

                node.bias      = AiMath.RandomRange(-1f, 1f);
                node.inovation = ++_inovation;
                return(node);
            }
Esempio n. 2
0
 public override void Pulse(INeuralLayer <double> source)
 {
     lock (key)
     {
         base.Pulse(source);
         this.Value = AiMath.Sigmoid(this.Value);
     }
 }
Esempio n. 3
0
            public Node Mutated()
            {
                Node node = new Node();

                node.bias      = bias + AiMath.RandomRange(-0.1f, 0.1f);
                node.inovation = _inovation;
                return(node);
            }
Esempio n. 4
0
            public Axon Mutated()
            {
                Axon axon = new Axon();

                axon.weight   += AiMath.RandomRange(-0.1f, 0.1f);
                axon.A         = A;
                axon.B         = B;
                axon.inovation = inovation;
                return(axon);
            }
Esempio n. 5
0
            public static Axon NewAxon(int range)
            {
                range = Math.Max(1, range);
                Axon axon = new Axon();

                axon.weight    = AiMath.RandomRange(-1f, 1f);
                axon.A         = AiMath.random.Next(0, range);
                axon.B         = AiMath.random.Next(0, range);
                axon.inovation = ++_inovation;
                return(axon);
            }
Esempio n. 6
0
    private bool IsExist(string whole, string subString)
    {
        if (!whole.StartsWith(subString))
        {
            return(false);
        }

        string str = whole.Substring(subString.Length);

        int result;

        return(AiMath.IsNumberic(str, out result));
    }
Esempio n. 7
0
            public Node Clone()
            {
                Node node = new Node();

                if (AiMath.PercentChance(mutationChance))
                {
                    node.bias = bias + AiMath.RandomRange(-0.1f, 0.1f);
                }
                else
                {
                    node.bias = bias;
                }

                node.inovation = _inovation;
                return(node);
            }
Esempio n. 8
0
            public Axon Clone()
            {
                Axon axon = new Axon();

                if (AiMath.PercentChance(mutationChance))
                {
                    axon.weight = weight + AiMath.RandomRange(-0.1f, 0.1f);
                }
                else
                {
                    axon.weight = weight;
                }

                axon.A         = A;
                axon.B         = B;
                axon.inovation = inovation;
                return(axon);
            }
Esempio n. 9
0
        public void Feed(float[] feeds, int expectedOutputLenght)
        {
            foreach (Core c in cores)
            {
                c.Reset();
            }

            for (int i = 0; i < feeds.Length; i++)
            {
                cores[i].Charge(feeds[i]);
            }

            output = new float[expectedOutputLenght];
            for (int i = feeds.Length; i < feeds.Length + expectedOutputLenght; i++)
            {
                output[i - feeds.Length] = cores[i].activation;
            }
            decision = AiMath.IndexIfOrder(output, 0);
        }
Esempio n. 10
0
        public DNA Mitosis()
        {
            DNA baby = new DNA(0, 0);

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

            baby.CloneInto(nodes, axons);

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

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

            baby.GetSpecie(specie);
            baby.ID = inovation + "/" + baby.inovation;
            return(baby);
        }
Esempio n. 11
0
    internal override List <ISkillTarget> GetTargetlistInScope(EffScope scope, int targetMask, ISkillTarget target)
    {
        //if (target == null) return null;

        List <ISkillTarget> targetList  = new List <ISkillTarget>();
        Vector3             scopeCenter = transform.position;

        if (scope.m_centerType == -1)
        {
            scopeCenter = transform.position;
        }

        if (scope.m_centerType == -2)
        {
            scopeCenter = center;
        }

        Collider[] colliders = Physics.OverlapSphere(scopeCenter, scope.m_radius + radius, 0);
        // Edit by zhouxun
        // we need check the parent gameobject also.

        foreach (Collider c in colliders)
        {
            if (c.isTrigger || c.gameObject == this.gameObject)
            {
                continue;
            }

            if (GameConfig.IsMultiMode)
            {
                SkillRunner obj = VCUtils.GetComponentOrOnParent <SkillRunner>(c.gameObject);
                if (null == obj)
                {
                    continue;
                }

                int targetHarm = AiUtil.GetHarm(obj.gameObject);
                if (AiHarmData.GetHarmValue(harm, targetHarm) == 0)
                {
                    continue;
                }
            }
            else
            {
                int targetHarm = AiUtil.GetHarm(c.gameObject);
                if (AiHarmData.GetHarmValue(harm, targetHarm) == 0)
                {
                    continue;
                }
            }

            float cosAngle = AiMath.Dot(transform, c.transform);
            float angle    = Mathf.Acos(cosAngle) * Mathf.Rad2Deg;

            if (angle > scope.m_degEnd || angle < scope.m_degStart)
            {
                continue;
            }

            SkillRunner runner = VCUtils.GetComponentOrOnParent <SkillRunner>(c.gameObject);
            if (runner != null && (runner != this) && !targetList.Contains(runner))
            {
                targetList.Add(runner);
            }
        }
        return(targetList);
    }
Esempio n. 12
0
    internal override List <ISkillTarget> GetTargetlistInScope(EffScope scope, int targetMask, ISkillTarget target)
    {
        List <ISkillTarget> targetList = new List <ISkillTarget>();

        if (emitRunner == null)
        {
            return(targetList);
        }

        Collider[]       cs         = Physics.OverlapSphere(transform.position, scope.m_radius);
        List <Transform> transforms = new List <Transform>();

        foreach (Collider item in cs)
        {
            if (item.isTrigger)
            {
                continue;
            }

            if (!transforms.Contains(item.transform) &&
                !item.gameObject.Equals(this.gameObject) &&
                !item.gameObject.Equals(emitRunner.gameObject))
            {
                transforms.Add(item.transform);
            }

            Transform           root     = item.transform;
            CreationSkillRunner creation = VCUtils.GetComponentOrOnParent <CreationSkillRunner>(root.gameObject);
            if (creation != null)
            {
                if (!transforms.Contains(creation.transform))
                {
                    transforms.Add(creation.transform);
                }
            }
        }

        foreach (Transform tr in transforms)
        {
            if (tr == null || emitTransform == null)
            {
                continue;
            }

            float cosAngle = AiMath.Dot(emitTransform, tr);
            float angle    = Mathf.Acos(cosAngle) * Mathf.Rad2Deg;

            int emitHarm = AiUtil.GetHarm(emitRunner.gameObject);

            if (GameConfig.IsMultiMode)
            {
                SkillRunner obj = tr.GetComponent <SkillRunner>();
                if (null == obj)
                {
                    continue;
                }

                int targetHarm = AiUtil.GetHarm(obj.gameObject);

                if (AiHarmData.GetHarmValue(emitHarm, targetHarm) == 0)
                {
                    continue;
                }
            }
            else
            {
                int targetHarm = AiUtil.GetHarm(tr.gameObject);

                if (AiHarmData.GetHarmValue(emitHarm, targetHarm) == 0)
                {
                    continue;
                }
            }

            Ray   rayStart = new Ray(transform.position, tr.position - transform.position);
            float distance = Vector3.Distance(transform.position, tr.position);

            if (Physics.Raycast(rayStart, distance,
                                AiUtil.groundedLayer | AiUtil.obstructLayer))
            {
                continue;
            }

            if (angle > scope.m_degEnd || angle < scope.m_degStart)
            {
                continue;
            }

            SkillRunner runner = tr.GetComponent <SkillRunner>();

            if (runner == null)
            {
                runner = VCUtils.GetComponentOrOnParent <SkillRunner>(tr.gameObject);
            }

            if (runner != null && !targetList.Contains(runner))
            {
                targetList.Add(runner);
            }
        }

        return(targetList);
    }
Esempio n. 13
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);
        }