コード例 #1
0
ファイル: pickup.cs プロジェクト: pelcz/Climber
	void Start()
	{
		player_ref =  GameObject.FindGameObjectWithTag("Player").transform;
		brain_ref =  Camera.main.GetComponent<brain>();
		collectSound = brain_ref.collectSound;
		GetComponent<CircleCollider2D> ().radius = pickUpDis;
	}
コード例 #2
0
    private void InitCarNeuralNetworks()
    {
        nets = new List <brain>();//initialize list of brains

        for (int i = 0; i < populationSize; i++)
        {
            brain net = new brain(layers); //create new list
            net.Mutate();                  //mutate the generated brain
            nets.Add(net);                 //add it to the list
        }
    }
コード例 #3
0
    public void  GetMapByShopsJSON(int id1, int id2)
    {
        Point storeCurr, storeDest;

        storeCurr = getI_J(id1);
        storeDest = getI_J(id2);

        brain b = new brain();

        optimalPathPic = b.checkFloor(id1, storeCurr.X, storeCurr.Y, id2, storeDest.X, storeDest.Y);
        Context.Response.Write(String.Join(",", optimalPathPic.ToArray()));
    }
コード例 #4
0
    // Update is called once per frame
    void Update()
    {
        //restart function
        if (isTraining == false)
        {
            if (generationNumber == 0)
            {
                InitCarNeuralNetworks(); //start list of neural networks
            }
            else
            {
                nets.Sort();    //uses the compare function to sort the list of neural networks
                nets.Reverse(); //reverses list so the best scoring is at the start

                best.text = "Best score: " + nets[0].GetFitness();
                Debug.Log(nets[0].GetFitness());//for best ftness

                for (int i = 1; i < populationSize / 4; i++)
                {
                    nets[i] = new brain(nets[0]);//first 25% excluding the best are mutated
                    nets[i].Mutate();
                }

                for (int i = populationSize / 4; i < populationSize * 0.9f; i++)
                {
                    nets[i] = new brain(nets[0]);//next 65% are mutated twice
                    nets[i].Mutate();
                    nets[i].Mutate();
                }
                for (int i = (int)(populationSize * 0.9f); i < populationSize; i++)
                {
                    nets[i] = new brain(layers);//last 10% are completely random
                    nets[i].Mutate();
                }

                for (int i = 0; i < populationSize; i++)
                {
                    nets[i].SetFitness(0f);//reset list of nets to 0 fitness
                }
            }

            generationNumber++;
            genText.text = "Generation: " + generationNumber;
            isTraining   = true;
            Invoke("Timer", genTime);//timer for generations
            CreateCars();
        }
    }
コード例 #5
0
    public GameObject breed(GameObject parent1, GameObject parent2)
    {
        Vector3    pos       = new Vector3(this.transform.position.x + UnityEngine.Random.Range(-2, 2), this.transform.position.y, this.transform.position.z + UnityEngine.Random.Range(-2, 2));
        GameObject offspring = Instantiate(bot, pos, this.transform.rotation);
        brain      b         = offspring.GetComponent <brain>();

        if (UnityEngine.Random.Range(0, 100) == 1)
        {
            b.init();
            b.dna.mutate();
        }
        else
        {
            b.init();
            b.dna.combine(parent1.GetComponent <brain>().dna, parent2.GetComponent <brain>().dna);
        }

        return(offspring);
    }
コード例 #6
0
 public void Init(brain net)
 {
     this.net = net;
     //pointer to its brain in the manager script.
     initilized = true;
 }