Example #1
0
    private void Start()
    {
        Game_Manager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>();

        //Calculate Weights Number In Neural Network
        for (int i = 1; i < NeuralNetworkShape.Length; i++)
        {
            WeightNum += NeuralNetworkShape[i - 1] * NeuralNetworkShape[i];
        }

        //Calculate Biases Number In Neural Network
        BiasesNum = NeuralNetworkShape.Length - 1;

        //Instantiate Populition
        Populition = new Agent[PopulitionSize];
        saveDouble w = Car.ReadFromXmlFile <saveDouble>("weights.xml");


        for (int i = 0; i < PopulitionSize; i++)
        {
            //Instantiate Agent Dna
            Populition[i] = new Agent();

            Populition[i].Fitness = 0;
            //Instantiate new Agent Weights
            Populition[i].Weights = new double[WeightNum];
            //Instantiate new Agent Biases
            Populition[i].Biases = new double[BiasesNum];
            w.weights.CopyTo(Populition[i].Weights, 0);
            w.biases.CopyTo(Populition [i].Biases, 0);

            //Random Weights Value

            /*for (int j = 0; j < WeightNum; j++)
             * {
             *  Populition[i].Weights[j] = Random.Range(-1.0f, 1.0f);
             * }
             *
             * //Random Weights Value
             * for (int j = 0; j < BiasesNum; j++)
             * {
             *  Populition[i].Biases[j] = Random.Range(-1.0f, 1.0f);
             * }*/
        }


        StartTheGenetationTest();
    }
Example #2
0
    //To Check If The Car Reached The Check Points Or The Finish Line
    private void OnTriggerExit(Collider other)
    {
        if (other.tag == "CheckPoint")
        {
            LastIndexCheckPoint++;

            //Update Last Check Point Reach it
            MainCamera.UpdateTarget(LastIndexCheckPoint + 1);
        }

        if (other.tag == "FinishLine")
        {
            string     weight_file = "weights.xml";
            saveDouble w           = new saveDouble(NN.Weights, NN.Biases);
            WriteToXmlFile(weight_file, w);
            Game_Manager.TestFinish();
        }
    }