/// <summary>
    /// Creates a new generation by using GenerateBoxes and GenerateBoats/Pirates.
    /// Previous generations will be removed and the best parents will be selected and used to create the new generation.
    /// The best parents (top 1) of the generation will be stored as a Prefab in the [savePrefabsAt] folder. Their name
    /// will use the [generationCount] as an identifier.
    /// </summary>
    public void MakeNewGeneration()
    {
        GenerateBoxes();
        GeneratePowerups();

        //Fetch parents
        _activeBoats.RemoveAll(item => item == null);
        _activeBoats.Sort();
        _activeAbledBoats.RemoveAll(item => item == null);
        _activeAbledBoats.Sort();

        if (_activeBoats.Count == 0)
        {
            GenerateBoats(_boatParents);
        }
        if (_activeAbledBoats.Count == 0)
        {
            GenerateAbledBoats(_abledBoatParents);
        }

        _boatParents      = new BoatLogic[boatParentSize];
        _abledBoatParents = new BoatLogic[boatParentSize];

        for (int i = 0; i < boatParentSize; i++)
        {
            _boatParents[i]      = _activeBoats[i];
            _abledBoatParents[i] = _activeAbledBoats[i];
        }

        BoatLogic lastBoatWinner      = _activeBoats[0];
        BoatLogic lastAbledBoatWinner = _activeAbledBoats[0];

        lastBoatWinner.name      += "Gen-" + generationCount;
        lastAbledBoatWinner.name += "Gen-" + generationCount;
        lastBoatWinnerData        = lastBoatWinner.GetData();
        lastAbledBoatWinnerData   = lastAbledBoatWinner.GetData();
        PrefabUtility.SaveAsPrefabAsset(lastBoatWinner.gameObject, savePrefabsAt + lastBoatWinner.name + ".prefab");
        PrefabUtility.SaveAsPrefabAsset(lastAbledBoatWinner.gameObject, savePrefabsAt + lastAbledBoatWinner.name + ".prefab");

        _activePirates.RemoveAll(item => item == null);
        _activePirates.Sort();
        _activeAbledPirates.RemoveAll(item => item == null);
        _activeAbledPirates.Sort();
        _pirateParents      = new PirateLogic[pirateParentSize];
        _abledPirateParents = new PirateLogic[pirateParentSize];
        for (int i = 0; i < pirateParentSize; i++)
        {
            _pirateParents[i]      = _activePirates[i];
            _abledPirateParents[i] = _activeAbledPirates[i];
        }

        PirateLogic lastPirateWinner      = _activePirates[0];
        PirateLogic lastAbledPirateWinner = _activeAbledPirates[0];

        lastPirateWinner.name      += "Gen-" + generationCount;
        lastAbledPirateWinner.name += "Gen-" + generationCount;
        lastPirateWinnerData        = lastPirateWinner.GetData();
        lastAbledPirateWinnerData   = lastAbledPirateWinner.GetData();
        PrefabUtility.SaveAsPrefabAsset(lastPirateWinner.gameObject, savePrefabsAt + lastPirateWinner.name + ".prefab");
        PrefabUtility.SaveAsPrefabAsset(lastAbledPirateWinner.gameObject, savePrefabsAt + lastAbledPirateWinner.name + ".prefab");

        //Winners:
        Debug.Log("Last winner boat had: " + lastBoatWinner.GetPoints() + " points!" + " Last winner pirate had: " + lastPirateWinner.GetPoints() + " points!");
        Debug.Log("Last winner ABLED boat had: " + lastAbledBoatWinner.GetPoints() + " points!" + " Last winner ABLED pirate had: " + lastAbledPirateWinner.GetPoints() + " points!");


        GenerateObjects(_boatParents, _abledBoatParents, _pirateParents, _abledPirateParents);
    }
    /// <summary>
    /// Creates a new generation by using GenerateBoxes and GenerateBoats/Pirates.
    /// Previous generations will be removed and the best parents will be selected and used to create the new generation.
    /// The best parents (top 1) of the generation will be stored as a Prefab in the [savePrefabsAt] folder. Their name
    /// will use the [generationCount] as an identifier.
    /// </summary>
    public void MakeNewGeneration()
    {
        GenerateBoxes();

        //Fetch parents
        _activeBoats.RemoveAll(item => item == null);
        _activeBoats.Sort();
        if (_activeBoats.Count == 0)
        {
            GenerateBoats(_boatParents);
        }
        _boatParents = new BoatLogic[boatParentSize];
        for (int i = 0; i < boatParentSize; i++)
        {
            _boatParents[i] = _activeBoats[i];
        }

        BoatLogic lastBoatWinner = _activeBoats[0];

        lastBoatWinner.name += "Gen-" + generationCount;
        lastBoatWinnerData   = lastBoatWinner.GetData();
        PrefabUtility.SaveAsPrefabAsset(lastBoatWinner.gameObject, savePrefabsAt + lastBoatWinner.name + ".prefab");
        boatRoundScores = 0;
        foreach (BoatLogic boat in _activeBoats)
        {
            boatRoundScores += boat.GetPoints();
        }
        boatTotalScores += boatRoundScores;
        _activePirates.RemoveAll(item => item == null);
        _activePirates.Sort();
        _pirateParents = new PirateLogic[pirateParentSize];
        for (int i = 0; i < pirateParentSize; i++)
        {
            _pirateParents[i] = _activePirates[i];
        }

        PirateLogic lastPirateWinner = _activePirates[0];

        pirateRoundScores = 0;
        foreach (PirateLogic pirate in _activePirates)
        {
            pirateRoundScores += pirate.GetPoints();
        }
        pirateTotalScores     += pirateRoundScores;
        lastPirateWinner.name += "Gen-" + generationCount;
        lastPirateWinnerData   = lastPirateWinner.GetData();
        PrefabUtility.SaveAsPrefabAsset(lastPirateWinner.gameObject, savePrefabsAt + lastPirateWinner.name + ".prefab");
        //Winners:

        //Storing results
        string path = "Assets/Overallresults.txt";
        //Write some text to the test.txt file
        StreamWriter writer = new StreamWriter(path, true);

        writer.WriteLine("Generations count" + generationCount + "||Total boats:" + boatTotalScores + "||TotalPiratesScores:" + pirateTotalScores);
        writer.Close();
        path   = "Assets/BoatsTotalScores.txt";
        writer = new StreamWriter(path, true);
        writer.WriteLine(boatTotalScores);
        writer.Close();
        path   = "Assets/PiratesTotalScores.txt";
        writer = new StreamWriter(path, true);
        writer.WriteLine(pirateTotalScores);
        writer.Close();
        path   = "Assets/BoatsRoundScores.txt";
        writer = new StreamWriter(path, true);
        writer.WriteLine(boatRoundScores);
        writer.Close();
        path   = "Assets/PiratesRoundScores.txt";
        writer = new StreamWriter(path, true);
        writer.WriteLine(pirateRoundScores);
        writer.Close();

        Debug.Log("Last winner boat had: " + lastBoatWinner.GetPoints() + " points!" + " Last winner pirate had: " + lastPirateWinner.GetPoints() + " points!");
        Debug.Log("Total boats:" + boatTotalScores + "||Round boats:" + boatRoundScores + "||TotalPiratesScores:" + pirateTotalScores + "||PiratesRoundScores" + pirateRoundScores);
        GenerateObjects(_boatParents, _pirateParents);
    }