示例#1
0
    private void SetHighest()
    {
        // We'll need a reference to the highest Forrest in our finished Forrest list
        ForrestCTRL tF         = startFatt[ReturnHighest(startFatt)];
        float       avgFitTemp = GetAverageFitness(startFatt);

        // This saves a record of the fitness performances
        fits.Add(tF.fitness);

        // This saves a record of the fitness average performances
        avgs.Add(avgFitTemp);


        // If this new Forrest beat the Highest Forrest make him the new highest
        if (tF.fitness > highestFit.fitness)
        {
            // Create a new NN to store the highest brain from the training session
            highestFit = new NN(tF.nn.inputs, tF.nn.hL);

            // Set that fitness to the new record Forrest which is tF
            highestFit.SetFitness(tF.fitness);

            // Then set the weights to the new record Forrest tF
            highestFit.IniWeights(tF.nn.GetBrain());

            // Finally change the highest fit brain string to our new record weights
            highestFitBrain = highestFit.ReadBrain();
        }

        // If this new Forrest beat the Highest Forrest make him the new highest
        if (avgFitTemp > highestAvg)
        {
            highestAvg = avgFitTemp;
        }
    }
示例#2
0
    /// <summary>
    /// This will spawn Forrest at the start marker
    /// </summary>
    public void SpawnForrest(int num)
    {
        if (!slowMode)
        {
            // loop through the num count & spawn a every Forrest attempt for that day
            for (int i = 0; i < num; i++)
            {
                ForrestCTRL f = Instantiate(forrest).GetComponent <ForrestCTRL>();

                // Set the position to be that of the starting sphere
                f.transform.position = new Vector3(startSp.transform.position.x, f.transform.position.y, startSp.transform.position.z);

                // Set the angle to be that of the starting sphere
                f.transform.eulerAngles = new Vector3(f.transform.eulerAngles.x, startSp.transform.eulerAngles.y, f.transform.eulerAngles.z);

                // Set the brain to the corresponding attention ini data
                if (mode == GameMode.Train)
                {
                    f.SetBrain(attIniData[i]);
                }
                else if (mode == GameMode.Test)
                {
                    f.SetBrain(attIniData[i], mP.brains[i].Split('\n')[0]);
                }
                else if (mode == GameMode.Campaign)
                {
                    string name = mP.campNN.Split('\n')[0];
                    string pass = mP.campNN.Split('\n')[1];

                    f.SetBrain(ParseBrain1(pass, 29), name);
                }

                // Add the Forrest attemp to the list of All Forrest Attempts
                allFatt.Add(f);
            }

            // Need to clear & make way for a new day
            startFatt.Clear();

            // This will copy that list for later use
            for (int i = 0; i < allFatt.Count; i++)
            {
                startFatt.Add(allFatt[i]);
            }
        }
        else
        {
            if (day == 0)
            {
                day++;
            }

            //
            if ((int)attempt.x == (int)attempt.y - 1)
            {
                LearnFromAttempts();
                SetHighest();
                SetGraphs();
                attempt.x = -1;
                startFatt.Clear();
                day++;
            }
            attempt.x++;

            ForrestCTRL f = Instantiate(forrest).GetComponent <ForrestCTRL>();

            // Set the position to be that of the starting sphere
            f.transform.position = new Vector3(startSp.transform.position.x, f.transform.position.y, startSp.transform.position.z);

            // Set the angle to be that of the starting sphere
            f.transform.eulerAngles = new Vector3(f.transform.eulerAngles.x, startSp.transform.eulerAngles.y, f.transform.eulerAngles.z);

            // Set the brain to the corresponding attention ini data
            if (mode == GameMode.Train)
            {
                f.SetBrain(attIniData[(int)attempt.x]);
            }
            else if (mode == GameMode.Test)
            {
                f.SetBrain(attIniData[(int)attempt.x], mP.brains[(int)attempt.x].Split('\n')[0]);
            }

            allFatt.Add(f);
            startFatt.Add(f);

            //
            f.Reset();
        }
    }
示例#3
0
    /// <summary>
    /// This will spawn Forrest at the start marker
    /// </summary>
    public void RespawnForrest(int num)
    {
        GameObject[] grabPast = GameObject.FindGameObjectsWithTag("Passive");
        if (!slowMode)
        {
            // loop through the num count & spawn a every Forrest attempt for that day
            for (int i = 0; i < num; i++)
            {
                ForrestCTRL f = grabPast[i].GetComponent <ForrestCTRL>();

                // Set the position to be that of the starting sphere
                f.transform.position = new Vector3(startSp.transform.position.x, f.transform.position.y, startSp.transform.position.z);

                // Set the angle to be that of the starting sphere
                f.transform.eulerAngles = new Vector3(f.transform.eulerAngles.x, startSp.transform.eulerAngles.y, f.transform.eulerAngles.z);

                // Set the brain to the corresponding attention ini data
                f.SetBrain(attIniData[i]);

                //
                f.Reset();

                // Add the Forrest attemp to the list of All Forrest Attempts
                allFatt.Add(f);
            }

            // Need to clear & make way for a new day
            startFatt.Clear();

            // This will copy that list for later use
            for (int i = 0; i < allFatt.Count; i++)
            {
                startFatt.Add(allFatt[i]);
            }
        }
        else
        {
            //
            if ((int)attempt.x == (int)attempt.y - 1)
            {
                LearnFromAttempts();
                SetHighest();
                SetGraphs();
                attempt.x = -1;
                startFatt.Clear();
                day++;
            }
            attempt.x++;

            ForrestCTRL f = grabPast[(int)attempt.x].GetComponent <ForrestCTRL>();

            // Set the position to be that of the starting sphere
            f.transform.position = new Vector3(startSp.transform.position.x, f.transform.position.y, startSp.transform.position.z);

            // Set the angle to be that of the starting sphere
            f.transform.eulerAngles = new Vector3(f.transform.eulerAngles.x, startSp.transform.eulerAngles.y, f.transform.eulerAngles.z);

            // Set the brain to the corresponding attention ini data
            if (mode == GameMode.Train)
            {
                f.SetBrain(attIniData[(int)attempt.x]);
            }
            else if (mode == GameMode.Test)
            {
                f.SetBrain(attIniData[(int)attempt.x], mP.brains[(int)attempt.x].Split('\n')[0]);
            }

            allFatt.Add(f);
            startFatt.Add(f);

            //
            f.Reset();
        }
    }
示例#4
0
    //
    void Update()
    {
        // Will load the menu if power is pressed
        if (Input.GetAxis("Power") > 0)
        {
            GoToMenu();
        }

        // Restart the scene when we press restart
        if (Input.GetAxis("Restart") > 0)
        {
            RestartRoom();
        }

        // Check to see if there are any active Forrests
        bool activeFs = allFatt.Count > 0;

        // If so then perform this
        if (activeFs)
        {
            F = allFatt[ReturnHighest(allFatt)];
            t.transform.position = new Vector3(F.transform.position.x, 3.5f, F.transform.position.z);
            oS.value             = F.movement;
            fT.text  = mP.lvlName + (mP.reverse ? "(R)" : string.Empty) + "\n" + mP.CO + "-" + mP.SEL + "\n" + Mathf.Round(F.fitness * 1000) / 1000;
            lpT.text = ((slowMode) ? attempt.x + 1 + "/" + attempt.y + "\n" : "") + F.lap.x + "/" + F.lap.y;
            wT.text  = "" + F.myName + "\n" + mP.lvlName + (mP.reverse ? "(R)" : string.Empty) + "\n" + Mathf.Round(F.fitness * 1000) / 1000;

            //
            for (int i = 0; i < inp.Length; i++)
            {
                try
                {
                    inp[i].text = "" + Mathf.Round(F.inp[i] * 100) / 100;
                }
                catch
                {
                    inp[i].text = "?";
                }
            }

            //
            if (Camy == CamMode.Lock)
            {
                Camera.main.transform.rotation = Quaternion.Euler(new Vector3(90, 0, 0));
                Camera.main.transform.position = new Vector3(F.transform.position.x, 50, F.transform.position.z);
            }
            else if (Camy == CamMode.Top)
            {
                Camera.main.transform.rotation = Quaternion.Lerp(Camera.main.transform.rotation, Quaternion.Euler(new Vector3(90, F.transform.eulerAngles.y, 0)), Time.deltaTime * 10);
                Camera.main.transform.position = new Vector3(F.transform.position.x, 25, F.transform.position.z);
            }
            else if (Camy == CamMode.Free)
            {
                Camera.main.transform.position = new Vector3(Mathf.Clamp(Camera.main.transform.position.x + Input.GetAxis("Horizontal"), -100, 100), Mathf.Clamp(Camera.main.transform.position.y + (Input.GetAxis("Mouse ScrollWheel") * -10), 5, 100), Mathf.Clamp(Camera.main.transform.position.z + Input.GetAxis("Vertical"), -100, 100));
            }
            else if (Camy == CamMode.Track)
            {
                Camera.main.transform.Translate(new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Mouse ScrollWheel") * 10, Input.GetAxis("Vertical")));
                Camera.main.transform.position = new Vector3(Mathf.Clamp(Camera.main.transform.position.x, -100, 100), Mathf.Clamp(Camera.main.transform.position.y, 2, 100), Mathf.Clamp(Camera.main.transform.position.z, -100, 100));
                Camera.main.transform.LookAt(F.transform);
            }
            else if (Camy == CamMode.POV)
            {
                Camera.main.transform.rotation = Quaternion.Lerp(Camera.main.transform.rotation, F.transform.localRotation, Time.deltaTime * 10);
                Camera.main.transform.position = F.transform.position + (Vector3.up / 2);
            }
            else if (Camy == CamMode.Follow)
            {
                if (Vector3.Distance(Camera.main.transform.position, F.transform.position) > 3)
                {
                    Camera.main.transform.Translate(Vector3.forward * .15f);
                }

                Camera.main.transform.LookAt(F.transform.position + (Vector3.up * .5f));
            }
        }
    }