Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        GetSettings();

        lastGenBest = -1;
        startArea   = GameObject.FindWithTag("StartArea");
        //panel that shows statistics about winning
        wonPanel = GameObject.Find("WonPanel");
        wonPanel.SetActive(false);

        spawnPos     = startArea.transform.position;
        spawnPos.z   = spawnPos.z - 0.1f; //just to put it above level so the picture shows up
        currMaxSteps = beginSteps;


        //used for saving in file
        //delete old file
        SaveScores.deleteCSV();
        lastBestFitness    = new float[10];
        lastAverageFitness = new float[10];
        lastGens           = new int[10];

        InitializeGoalMarkers();
        //spawn first squares
        SpawnFirstGeneration();
    }
Esempio n. 2
0
    void Awake()
    {

        if (instance == null)
            instance = this;
        else if (instance != this)
            Destroy(gameObject);
        DontDestroyOnLoad(gameObject);
        if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android)
            dataPath = System.IO.Path.Combine(Application.persistentDataPath, "Score.xml");
        else
            dataPath = System.IO.Path.Combine(Application.dataPath, "Resources/Score.xml");
    }
Esempio n. 3
0
    /// <summary>
    /// Reset evolution parameters. Called by ResetEvolution
    /// </summary>
    void ResetParameters()
    {
        lastGenBest   = -1;
        levelComplete = false;
        currMaxSteps  = beginSteps;
        currGen       = 1;


        //used for saving in file
        //delete old file
        SaveScores.deleteCSV();
        lastBestFitness    = new float[10];
        lastAverageFitness = new float[10];
        lastGens           = new int[10];

        //spawn first squares
        SpawnFirstGeneration();
    }
Esempio n. 4
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
     DontDestroyOnLoad(gameObject);
     if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android)
     {
         dataPath = System.IO.Path.Combine(Application.persistentDataPath, "Score.xml");
     }
     else
     {
         dataPath = System.IO.Path.Combine(Application.dataPath, "Resources/Score.xml");
     }
 }
Esempio n. 5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (evolutionPaused)
        {
            //best square died
            if (!bestSquare.activeSelf)
            {
                bestSquare.GetComponent <PlayerController>().ResetPlayer();
                ResetEnemies();
            }
        }
        else
        {
            //did everybody die or win?
            if (AllPlayersDead())
            {
                //set best square of last generation back to original color
                SetSquareToNormalColor();

                //find best square and keep it (also change its color)
                FindBestSquare();

                //breed squares
                if (naturalSelectionOn)
                {
                    NaturalSelection();
                }
                if (breedWithBestOn)
                {
                    BreedWithBest();
                }

                //save index of generation
                lastGens[(currGen - 1) % 10] = currGen;
                //every ten generations, save information to file
                if (currGen % 10 == 0)
                {
                    SaveScores.SaveDataToCSV(lastGens, lastBestFitness, lastAverageFitness);
                }

                //increase generation number
                currGen++;

                //add more moves every x gens
                //dont add more moves if a square has already completed the level
                if (currGen % inscreaseStepGens == 0 && !levelComplete)
                {
                    IncreasePlayerSteps();
                }


                //spawn players
                //reset them to initial position, steps etc
                ResetPlayers();

                //put best square in front
                squares[lastGenBest].transform.position = new Vector3(squares[lastGenBest].transform.position.x, squares[lastGenBest].transform.position.y, -0.2f);


                //reset level between gens
                ResetEnemies();
            }
        }
    }