private void Initialize(BirdBrain bb) { _state = bb; _startPoint = new Vector3(-4, Random.Range(0, 10), 0); transform.position = _startPoint; _lastAttack = Time.time; }
public double Compute(double[] inputs) { double output = 0; for (int i = 0; i < weights.Length; i++) { output += weights[i] * inputs[i]; } output += bias; output = BirdBrain.activation(output); return(output); }
void SpawnBirds() { aliveBirds = birdCount; birds = new GameObject[birdCount]; for (int i = 0; i < birds.Length; i++) { birds[i] = Instantiate(bird); birds[i].GetComponent <SpriteRenderer>().color = Color.HSVToRGB((float)i / birdCount, 1, 1); BirdBrain bb = birds[i].GetComponent <BirdBrain>(); bb.birdManager = this; //if (i == 0) birds[i].GetComponent<Flap>().human = true; bb.Randomize(); bb.Reset(); } }
void EvolveBirds() { Array.Sort <GameObject>(birds, (a, b) => (int)(b.GetComponent <BirdBrain>().distance - a.GetComponent <BirdBrain>().distance)); BirdBrain topBird = birds[0].GetComponent <BirdBrain>(); if (topBird.distance > hiscore) { hiscore = topBird.distance; } prevScore = topBird.distance; for (int i = (int)(0.1f * birds.Length); i < (int)(0.9f * birds.Length); i++) { birds[i].GetComponent <BirdBrain>().Mutate(.2f); } for (int i = (int)(0.9f * birds.Length); i < birds.Length; i++) { birds[i].GetComponent <BirdBrain>().Randomize(); } }