Beispiel #1
0
    private void Start()
    {
        GUIHelper.AddToDisplay("Best fitness", () => bestFitness);
        GUIHelper.AddToDisplay("Generation", () => currentGeneration);
        GUIHelper.AddToDisplay("Genome", () => currentGenome);

        CreatePopulation();
    }
Beispiel #2
0
    private void Awake()
    {
        _neatManager             = FindObjectOfType <NEAT_Manager>();
        _isNeuralNetworkImported = jsonFile != null;
        _rigidbody        = gameObject.GetComponent <Rigidbody>();
        _vpResetVehicle   = gameObject.GetComponent <VPResetVehicle>();
        _vpVehicleToolkit = GetComponent <VPVehicleToolkit>();
        _checkpoints      = path.GetComponentsInChildren <Transform>();

        Array.Sort(_checkpoints, (t1, t2) => string.Compare(t1.name, t2.name, StringComparison.Ordinal));

        GUIHelper.AddToDisplay("Fitness", () => _globalFitness);
        GUIHelper.AddToDisplay("Time", () => _runningTime);
        GUIHelper.AddToDisplay("Avg speed", () => _avgSpeed);
        GUIHelper.AddToDisplay("Current checkpoint", () => _currentCheckpoint + 1);

        SensorByTypeResolver.Add(SensorType.Front, sensorFPosition);
        SensorByTypeResolver.Add(SensorType.Back, sensorBPosition);
        SensorByTypeResolver.Add(SensorType.Right, sensorRPosition);
        SensorByTypeResolver.Add(SensorType.Left, sensorLPosition);
        SensorByTypeResolver.Add(SensorType.FrontLeft, sensorFLPosition);
        SensorByTypeResolver.Add(SensorType.FrontRight, sensorFRPosition);
        SensorByTypeResolver.Add(SensorType.FrontLeftCenter, sensorFLCPosition);
        SensorByTypeResolver.Add(SensorType.FrontRightCenter, sensorFRCPosition);

        SensorReadActionByTypeResolver.Add(SensorType.Speed, () => _vpVehicleToolkit.speed / 40);
        SensorReadActionByTypeResolver.Add(SensorType.AxeX, () => NormalizeEuler(transform.eulerAngles.x));
        SensorReadActionByTypeResolver.Add(SensorType.AxeY, () => (transform.eulerAngles.y - 180) / 180);
        SensorReadActionByTypeResolver.Add(SensorType.AxeZ, () => (transform.eulerAngles.z - 180) / 180);

        inputsAmount = SensorByTypeResolver.Count + SensorReadActionByTypeResolver.Count;

        var curTransform = transform;

        _initPosition    = curTransform.position;
        _initEulerAngles = curTransform.eulerAngles;
        _initRotation    = curTransform.rotation;
        _lastPosition    = _initPosition;

        if (_isNeuralNetworkImported)
        {
            Destroy(_neatManager);
            _network = SerializationHelper.DeserializeNeuralNetwork(this);
        }
        else
        {
            _network = NeuralNetwork.Of(inputsAmount, outputsAmount, ActivationsFunctions);
        }
    }