Exemplo n.º 1
0
    public void newWeapon(NEAT.Person weaponC)
    {
        weapon[wIndex] = weaponC;
        chosenW        = weaponC;

        newWeaponEvent.Raise();
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        time  += Time.deltaTime;
        timeB -= Time.deltaTime;
        if (ga != null)
        {
            if (time > 5f)
            {
                time = 0f;
                GameObject gb = GameObject.Instantiate(objs.Find(n => n.name == "weapon").objectItem);
                gb.transform.position = objectTransform.position;
                WeaponObject wp = gb.GetComponent <WeaponObject>();
                NEAT.Person  p  = ga.results[random.Next(ga.results.Count - 1)];
                wp.contained = p;
            }
        }

        if (timeB < 0f)
        {
            timeB = 10f;
            if (player.usedWepons.Count > 1)
            {
                breed();
            }
        }
    }
Exemplo n.º 3
0
 // Start is called before the first frame update
 void Start()
 {
     weapon[0]  = weapon[0].Clone();
     weapon[1]  = weapon[1].Clone();
     weapon[2]  = weapon[2].Clone();
     playerData = playerData.Clone();
     plane      = new Plane(Vector3.up, Vector3.zero);
     chosenW    = weapon[wIndex];
 }
Exemplo n.º 4
0
    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());
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        t += Time.deltaTime;
        Ray   ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        float distance;

        if (plane.Raycast(ray, out distance))
        {
            // some point of the plane was hit - get its coordinates
            Vector3 hitPoint = ray.GetPoint(distance);
            // use the hitPoint to aim your cannon
            player.transform.position = Vector3.MoveTowards(player.transform.position, hitPoint, Time.deltaTime * playerData.speed);
        }

        //if (Input.GetMouseButton(0))
        //{
        if (t > 1F / playerData.freq)
        {
            for (int i = 0; i < drone.Count; ++i)
            {
                GameObject gb = ParticlePooling.Instance.instantiate(this.tag, drone[i], chosenW);

                Transform enPos = null;
                float     dist  = 100000f;
                foreach (GameObject enemy in GameObject.FindGameObjectsWithTag("Enemy"))
                {
                    if (dist > Vector3.Distance(enemy.transform.position, transform.position))
                    {
                        enPos = enemy.transform;
                        dist  = Vector3.Distance(enemy.transform.position, transform.position);
                    }
                }
                //gb.GetComponent<ParticleHomingForce>().target = enPos;
            }

            chosenW.usage++;
            if (!usedWepons.Contains(chosenW))
            {
                usedWepons.Add(chosenW);
            }
            t = 0f;
        }
        //}

        if (Input.GetMouseButtonDown(0))
        {
            wIndex  = (wIndex + 1) % weapon.Count;
            chosenW = weapon[wIndex];
            changeWeapon.Raise(wIndex);
            //Debug.Log(wIndex);
        }
    }
Exemplo n.º 6
0
    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);
    }
Exemplo n.º 7
0
    public void enemyDead(Transform transform)
    {
        double item = random.NextDouble();

        if (item > 0.5f)
        {
            float r       = (float)random.NextDouble();
            float percSum = objs.Select(n => n.sizePerc).Sum();

            double        sum          = 0;
            List <double> cumulatedSum = objs.Select(f => sum += f.sizePerc / percSum).ToList();

            int        index = cumulatedSum.FindIndex(f => f > r);
            GameObject gb    = GameObject.Instantiate(objs[index].objectItem);
            gb.transform.position = transform.position;
            if (gb.GetComponent <WeaponObject>() != null)
            {
                WeaponObject wp = gb.GetComponent <WeaponObject>();
                NEAT.Person  p  = ga.results[random.Next(ga.results.Count - 1)];
                wp.contained = p;
            }
        }
    }
Exemplo n.º 8
0
 public void newWeapon(NEAT.Person weaponC)
 {
     //newWeaponEvent.Raise();
 }
Exemplo n.º 9
0
    // 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;
    }