Esempio n. 1
0
 public void ReplaceBrains(SNN targetBrain)
 {
     if (lockMutations)
     {
         return;
     }
     brain = targetBrain.DeepClone();
 }
Esempio n. 2
0
 private void Start()
 {
     brain = new SNN(new List <int> {
         5, 5, 1
     }, random);
     mover           = GetComponent <CarMover>();
     sensorDistances = new List <double>();
 }
Esempio n. 3
0
    public static SNN Combine(SNN snn1, SNN snn2)
    {
        SNN newSNN = new SNN();

        newSNN.rand    = new Random();
        newSNN.shape   = snn1.shape;
        newSNN.weigths = new List <Matrix <double> >();
        newSNN.weigths.Add(snn1.weigths[0].Clone());
        newSNN.weigths.Add(snn2.weigths[1].Clone());
        return(newSNN);
    }
Esempio n. 4
0
    public SNN DeepClone()
    {
        SNN newSNN = new SNN();

        newSNN.weigths = new List <Matrix <double> >();
        newSNN.rand    = rand;
        newSNN.shape   = shape;
        for (int i = 0; i < weigths.Count; i++)
        {
            newSNN.weigths.Add(weigths[i].Clone());
        }
        return(newSNN);
    }
    private void BestOfTwo()
    {
        if (generatedCars.Count < 2)
        {
            Debug.LogWarning("You need at least 2 cars to use BO2 method");
            return;
        }
        List <Car> bestCars       = generatedCars.Take(2).ToList();
        SNN        combinedBrains = SNN.Combine(bestCars[0].carBrain.brain, bestCars[1].carBrain.brain);

        foreach (var car in generatedCars)
        {
            if (bestCars.Contains(car))
            {
                continue;
            }
            car.carBrain.ReplaceBrains(combinedBrains);
            car.carBrain.MutateBrains(new System.Random(mutationRandomizer.Next()));
        }
    }
Esempio n. 6
0
 public override int GetHashCode()
 {
     return(SNN.GetHashCode());
 }