public void OnAttempt(bool win, float timeOfDeath, float distanceTravelled, float previousCompetenceValue)
    {
        Attempts.AttemptModel attempt = new Attempts.AttemptModel(win, timeOfDeath, distanceTravelled, previousCompetenceValue);

        FileStream   stream = new FileStream(Application.persistentDataPath + "/" + dataFileName, FileMode.OpenOrCreate);
        StreamReader reader = new StreamReader(stream);
        string       json   = reader.ReadToEnd();

        stream.Close();
        stream = new FileStream(Application.persistentDataPath + "/" + dataFileName, FileMode.Truncate);

        Attempts attempts = new Attempts();

        if (!string.IsNullOrEmpty(json))
        {
            attempts = JsonUtility.FromJson <Attempts> (json);
        }

        attempts.Add(attempt);
        json = JsonUtility.ToJson(attempts);
        StreamWriter writer = new StreamWriter(stream);

        writer.Write(json);
        writer.Flush();
        stream.Close();
    }
Beispiel #2
0
    private float respectableDistanceFactor = 0.7f;  // 70% there! Just 30% of the distance away from goal. It increases with each attempt by a factor of 1/20;


    public float OptimizeExperience()
    {
        List <Attempts.AttemptModel> allAttempts = store.GetCurrentAttemptData();
        int   currentAttempt     = 0;
        float timeToReachGoal    = 0;
        float distanceTravelled  = 0;
        float previousCompetence = 0;

        if (allAttempts != null)
        {
            currentAttempt     = allAttempts.Count - 1;
            timeToReachGoal    = allAttempts [currentAttempt].timeOfDeath;
            distanceTravelled  = allAttempts [currentAttempt].distanceTravelled;
            previousCompetence = allAttempts [currentAttempt].previousCompetenceValue;

            Attempts.AttemptModel currentModel = allAttempts[currentAttempt];
            if (currentModel.win)
            {
                if (previousCompetence <= 0.97f)
                {
                    if (previousCompetence <= 0.6f)
                    {
                        return(previousCompetence + 0.18f);
                    }
                    else if (previousCompetence <= 0.86f)
                    {
                        return(previousCompetence + 0.12f);
                    }
                    else if (previousCompetence <= 0.93f)
                    {
                        return(previousCompetence + 0.06f);
                    }
                    else
                    {
                        return(previousCompetence + 0.03f);
                    }
                }
                else
                {
                    return(Mathf.Max(previousCompetence, 1.0f));
                }
            }
            else
            {
                return(previousCompetence);
            }
        }
        //set initial slider value
        return(startCompetence);
    }