Beispiel #1
0
    private static void UpdateNetInputs(NeuralCreature c)
    {
        List <ISensor> sensors = c.Body.Sensors;
        int            i       = 0;

        for (int s = 0; s < sensors.Count; s++)
        {
            for (int sp = 0; sp < sensors[s].SensorCount; sp++)
            {
                c.Mind.Inputs[i] = sensors[s].Get(sp);
                i++;
            }
        }
    }
Beispiel #2
0
    private static void Reset(NeuralCreature c)
    {
        c.Score = 0f;
        c.Goal  = UnityEngine.Random.insideUnitCircle.normalized;
        c.Goal  = new Vector3(c.Goal.x, 0f, c.Goal.y);
        c.Body.Root.Transform.GetComponent <AngleSensor>().Goal = c.Goal;

        List <ISensor> sensors = c.Body.Sensors;

        for (int i = 0; i < sensors.Count; i++)
        {
            sensors[i].OnReset();
        }
    }
Beispiel #3
0
    private static void UpdateNetOutputs(NeuralCreature c)
    {
        List <IActuator> actuators = c.Body.Actuators;

        int i = 0;

        for (int s = 0; s < actuators.Count; s++)
        {
            for (int sp = 0; sp < actuators[s].ActuatorCount; sp++)
            {
                actuators[s].Set(sp, c.Mind.Last.Outputs[i]);
                i++;
            }
        }
    }
Beispiel #4
0
    private void Awake()
    {
        Application.runInBackground = true;

        var protoCreature = QuadrotorFactory.CreateCreature(
            Vector3.zero,
            Quaternion.identity);

        var config = new FCNetworkConfig();

        config.Layers.Add(new FCLayerConfig {
            NumNeurons = protoCreature.NumInputs
        });
        config.Layers.Add(new FCLayerConfig {
            NumNeurons = 30
        });
        config.Layers.Add(new FCLayerConfig {
            NumNeurons = protoCreature.NumOutputs
        });

        Destroy(protoCreature.gameObject);

        // Create creature bodies
        _creatures = new List <NeuralCreature>(_populationSize);
        for (int i = 0; i < _populationSize; i++)
        {
            NeuralCreature nc = new NeuralCreature();

            Vector3 spawnPos = GetSpawnPosition(i, _populationSize);
            nc.Body = QuadrotorFactory.CreateCreature(
                spawnPos,
                GetSpawnRotation());

            nc.Mind = new FCNetwork(config);
            NeuralUtils.Initialize(nc.Mind, ref _rng);

            _creatures.Add(nc);
        }

        // Create a random genotype to seed the population
        _genotype = new FCNetwork(config);
        NeuralUtils.Initialize(_genotype, ref _rng);

        PrepareNewEpisode();
        MutatePopulation();

        // Store initial pose so we can reuse creature gameplay objects across tests
        _creatureInitPose = new List <ITransform>();
        CreatureFactory.SerializePose(_creatures[0].Body, _creatureInitPose);

        Physics.autoSimulation     = false;
        Physics.autoSyncTransforms = false;

        var colliders = FindObjectsOfType <CapsuleCollider>();

        for (int i = 0; i < colliders.Length; i++)
        {
            // Bug this doesn't work, why?
            colliders[i].material = _physicsMaterial;
        }

        StartEpisode();
    }