void Start() { player_ref = GameObject.FindGameObjectWithTag("Player").transform; brain_ref = Camera.main.GetComponent<brain>(); collectSound = brain_ref.collectSound; GetComponent<CircleCollider2D> ().radius = pickUpDis; }
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 } }
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())); }
// 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(); } }
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); }
public void Init(brain net) { this.net = net; //pointer to its brain in the manager script. initilized = true; }