// ------------------------------------------------------------------------------------------------------ //
    // ------------------------- D I F F I C U L T Y  C O N T R O L L E R ----------------------------------- //
    // ------------------------------------------------------------------------------------------------------ //
    public void manageDifficulty(Boolean responded, float responseTime)
    {
        // Logs in the file that they have responded
        // Saves all their response times in arrays within the Baseline class (keeps track of the data).
        // When <= 60 seconds, adds to baselineArray, when > 60 seconds, adds it to the moving averages array
        baseline.addResponseTime(responseTime, timer);

        // Gets the moving average of the data
        float WMA = baseline.getMovingAverage(responseTime, timer);

        if (timer < 60)
        {
            baseline.getAllResponseTimes("baseline");
        }
        else if (timer < 60)
        {
            baseline.getAllResponseTimes("movingAverage");
        }

        if (WMA > 0)
        {
            // Compares if their moving average is greater than the critical point.
            // Counts if they hit the critical point 3 times.
            if (WMA > baseline.getCritPoint())
            {
                critPointCounter++;
            }
            else
            {
                noCritPointCounter++;
            }

            // If they have made mistakes for multiple times, the difficulty decreases.
            if (WMA > baseline.getCritPoint() && critPointCounter >= 2)
            {
                critPointCounter = 0;
                if (difficultyLvl > 1)
                {
                    difficultyLvl--;
                }

                // Debug.Log("crit: " + critPointCounter + ", noCrit: " + noCritPointCounter + "decrease by -1 to " + difficultyLvl);
                fileManagement.saveCarSpawnedDetails("difficultyAdjust", critPointCounter.ToString(), noCritPointCounter.ToString(), "-1", "0");
            }

            // Otherwise, if they are consistently doing well, the difficulty will increase.
            else if (WMA < baseline.getCritPoint() && noCritPointCounter >= 2)
            {
                noCritPointCounter = 0;
                if (difficultyLvl < 10)
                {
                    difficultyLvl++;
                }

                // Debug.Log("crit: " + critPointCounter + ", noCrit: " + noCritPointCounter + "increase by +1 to " + difficultyLvl);
                fileManagement.saveCarSpawnedDetails("difficultyAdjust", critPointCounter.ToString(), noCritPointCounter.ToString(), "+1", "0");
            }

            fileManagement.saveCarSpawnedDetails("difficultyAdjust", critPointCounter.ToString(), noCritPointCounter.ToString(), "0", "0");
        }
    }
Example #2
0
    // ------------------------------------------------------------------------------------------------------ //
    // ------------------------- D I F F I C U L T Y  C O N T R O L L E R ----------------------------------- //
    // ------------------------------------------------------------------------------------------------------ //
    public void manageDifficulty(Boolean responded, float responseTime)
    {
        // Logs in the file that they have responded
        // Saves all their response times in arrays within the Baseline class (keeps track of the data).
        // When <= 60 seconds, adds to baselineArray, when > 60 seconds, adds it to the moving averages array
        baseline.addResponseTime(responseTime, timer);

        // Gets the moving average of the data
        float WMA = baseline.getMovingAverage(responseTime, timer);

        if (timer < 60)
        {
            baseline.getAllResponseTimes("baseline");
        }
        else if (timer < 60)
        {
            baseline.getAllResponseTimes("movingAverage");
        }

        if (WMA > 0)
        {
            // Counts how many times their moving average is greater than the critical point
            if (WMA > baseline.getCritPoint())
            {
                critPointCounter++;
            }
            else
            {
                noCritPointCounter++;
            }

            // If their moving average was less (two times) (i.e., they are responding slower) the difficulty decreases.
            if (WMA > baseline.getCritPoint() && critPointCounter >= 2)
            {
                critPointCounter = 0;
                if (difficultyLvl > 1)
                {
                    difficultyLvl--;
                }

                // save to the file
                fileManagement.saveCarSpawnedDetails("difficultyAdjust", critPointCounter.ToString(), noCritPointCounter.ToString(), "-1", "0");
            }

            // Otherwise, if their moving average is greater than the critical point (two times)
            // (i.e., they are consistently doing well) the difficulty will increase.
            else if (WMA < baseline.getCritPoint() && noCritPointCounter >= 2)
            {
                noCritPointCounter = 0;
                if (difficultyLvl < 10)
                {
                    difficultyLvl++;
                }

                // save to the file
                fileManagement.saveCarSpawnedDetails("difficultyAdjust", critPointCounter.ToString(), noCritPointCounter.ToString(), "+1", "0");
            }

            fileManagement.saveCarSpawnedDetails("difficultyAdjust", critPointCounter.ToString(), noCritPointCounter.ToString(), "0", "0");
        }
    }