Example #1
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();
    }