コード例 #1
0
ファイル: DNA.cs プロジェクト: GorkemSvn/AILibrary
            public static Node NewNode()
            {
                Node node = new Node();

                node.bias      = AiMath.RandomRange(-1f, 1f);
                node.inovation = ++_inovation;
                return(node);
            }
コード例 #2
0
ファイル: SigmoidNeuron.cs プロジェクト: Sejoslaw/KD.AutoBot
 public override void Pulse(INeuralLayer <double> source)
 {
     lock (key)
     {
         base.Pulse(source);
         this.Value = AiMath.Sigmoid(this.Value);
     }
 }
コード例 #3
0
ファイル: DNA.cs プロジェクト: GorkemSvn/AILibrary
            public Node Mutated()
            {
                Node node = new Node();

                node.bias      = bias + AiMath.RandomRange(-0.1f, 0.1f);
                node.inovation = _inovation;
                return(node);
            }
コード例 #4
0
ファイル: DNA.cs プロジェクト: GorkemSvn/AILibrary
            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);
            }
コード例 #5
0
ファイル: DNA.cs プロジェクト: GorkemSvn/AILibrary
            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);
            }
コード例 #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));
    }
コード例 #7
0
ファイル: DNA.cs プロジェクト: GorkemSvn/AILibrary
            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);
            }
コード例 #8
0
ファイル: DNA.cs プロジェクト: GorkemSvn/AILibrary
            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);
            }
コード例 #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);
        }
コード例 #10
0
ファイル: DNA.cs プロジェクト: GorkemSvn/AILibrary
        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);
        }
コード例 #11
0
ファイル: AiAttack.cs プロジェクト: shrubba/planetexplorers
    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);
    }
コード例 #12
0
ファイル: Projectile.cs プロジェクト: shrubba/planetexplorers
    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);
    }
コード例 #13
0
ファイル: DNA.cs プロジェクト: GorkemSvn/AILibrary
        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);
        }