コード例 #1
0
 public SimpleNeuralNet getBrain()
 {
     if (brain == null)
     {
         brain = new SimpleNeuralNet(network_struct);
     }
     return(brain);
 }
コード例 #2
0
 public void inheritBrain(SimpleNeuralNet other, bool mutate)
 {
     brain = new SimpleNeuralNet(other);
     if (mutate)
     {
         brain.mutate(swap_rate, mutate_rate, swap_strength, mutate_strength);
     }
 }
コード例 #3
0
 void Update()
 {
     if (brain == null)
     {
         brain = new SimpleNeuralNet(network_struct);
     }
     checkConstraint();
     fly();
 }
コード例 #4
0
 public SimpleNeuralNet(SimpleNeuralNet other)
 {
     all_weights = new List <float[, ]>();
     all_results = new List <float[]>();
     for (int i = 0; i < other.all_weights.Count; i++)
     {
         all_weights.Add((float[, ])other.all_weights[i].Clone());
         all_results.Add((float[])other.all_results[i].Clone());
     }
 }
コード例 #5
0
    void Update()
    {
        if (brain == null)
        {
            brain = new SimpleNeuralNet(network_struct);
        }
        if (terrain == null)
        {
            return;
        }
        if (details == null)
        {
            updateSetup();
            return;
        }


        energy -= energy_loss;
        int dx = (int)((tfm.position.x / terrain_sz.x) * detail_sz.x);
        int dy = (int)((tfm.position.z / terrain_sz.y) * detail_sz.y);

        // If over grass, eat it, gain energy and spawn offspring
        lookAround(dx, dy);

        /*if (dx >= 0 && dx < details.GetLength(1) &&
         *  dy >= 0 && dy < details.GetLength(0) &&
         *  details[dy, dx] > 0) {
         *  details[dy, dx] = 0;
         *  energy += energy_gain;
         *  if (energy > max_energy)
         *      energy = max_energy;
         *  genetic_algo.addOffspring(this);
         * }*/
        // Die when out of energy
        if (energy < 0)
        {
            energy = 0.0f;
            genetic_algo.removeAnimal(this);
        }
        if (mat != null)
        {
            mat.color = Color.white * (energy / max_energy);
        }

        // Update receptor
        updateVision();
        // Use brain
        float[] output = brain.getOutput(vision);
        // Act using actuators
        float angle = (output[0] * 2.0f - 1.0f) * max_angle;

        tfm.Rotate(0.0f, angle, 0.0f);
    }
コード例 #6
0
        private void HandleKeyPress(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.B:
                SimpleNeuralNet.Run(brainWindow);
                break;

            default:
                Game.HandleKeyPress(sender, e);
                break;
            }
        }