//Public methods
    public void GetNewMap()
    {
        int level = UI_Conversions.UserInputToInt(levelInput);

        if (level < 0)
        {
            Debug.Log("Enter a positive integer value for level");
            return;
        }
        int difficulty = difficultyInput.value;

        m_map = MapGenerator.Instance.GenerateNewMap(level, difficulty);
    }
Example #2
0
    //Chest rarity input callbacks
    public void UpdateTotalRarity()
    {
        //Get all input values
        float commonRarity    = UI_Conversions.UserInputToFloat(commonRarityInput);
        float uncommonRarity  = UI_Conversions.UserInputToFloat(uncommonRarityInput);
        float rareRarity      = UI_Conversions.UserInputToFloat(rareRarityInput);
        float legendaryRarity = UI_Conversions.UserInputToFloat(legendaryRarityInput);

        //Check values
        if (commonRarity == -1.0f ||
            uncommonRarity == -1.0f ||
            rareRarity == -1.0f ||
            legendaryRarity == -1.0f)
        {
            //Disable the GO button
            goButton.interactable = false;
            //Exit early
            return;
        }

        //There are values in all inputs, update the total value
        float totalValue = commonRarity + uncommonRarity + rareRarity + legendaryRarity;

        totalRarityInput.text = totalValue.ToString();

        if (totalValue != 100.0f && totalValue != 1.0f)
        {
            goButton.interactable = false;
        }
        else
        {
            goButton.interactable = true;
            if (totalValue == 100.0f)
            {
                commonRarity    /= 100.0f;
                uncommonRarity  /= 100.0f;
                rareRarity      /= 100.0f;
                legendaryRarity /= 100.0f;
            }

            rarities[0] = commonRarity;
            rarities[1] = uncommonRarity;
            rarities[2] = rareRarity;
            rarities[3] = legendaryRarity;
        }
    }
    public void ChiSquareRandom()
    {
        wg = windowGraph.GetComponent <Window_Graph>();
        if (wg == null)
        {
            Debug.Log("wg is null");
            return;
        }

        Clear(wg);

        int   numToGen = UI_Conversions.UserInputToInt(numberToGenerate);
        float minRange = UI_Conversions.UserInputToFloat(rangeMinimum);
        float maxRange = UI_Conversions.UserInputToFloat(rangeMaximum);

        if (numToGen == -1 || minRange == -1 || maxRange == -1)
        {
            return;
        }

        List <float> chiSquareRandomNumbers = new List <float>();

        Randomness.Instance.UnityRandom(numToGen, 0.0f, 1.0f, ref chiSquareRandomNumbers);

        //Square the values
        for (int i = 0; i < chiSquareRandomNumbers.Count; i++)
        {
            chiSquareRandomNumbers[i] *= chiSquareRandomNumbers[i];
            //Values are still between 0.0f and 1.0f, need to scale them to min and max values
            chiSquareRandomNumbers[i] = minRange + (chiSquareRandomNumbers[i] * ((maxRange - minRange)));
        }

        if (roundingToggle.isOn)
        {
            int decimalPlaceRound = UI_Conversions.UserInputToInt(roundingPlaces.options[roundingPlaces.value].text);
            RoundToDecimalPlaces(ref chiSquareRandomNumbers, decimalPlaceRound);
        }
        chiSquareRandomNumbers.Sort();

        int            minCount = System.Int32.MaxValue;
        int            maxCount = System.Int32.MinValue;
        List <Vector2> counts   = CountOccurences(chiSquareRandomNumbers, ref minCount, ref maxCount);

        wg.Graph(counts, new Vector2(minRange, maxRange), new Vector2(minCount, maxCount));
    }
    public void UnityRandomRange()
    {
        wg = windowGraph.GetComponent <Window_Graph>();
        if (wg == null)
        {
            Debug.Log("wg is null");
            return;
        }

        Clear(wg);

        int   numToGen = UI_Conversions.UserInputToInt(numberToGenerate);
        float minRange = UI_Conversions.UserInputToFloat(rangeMinimum);
        float maxRange = UI_Conversions.UserInputToFloat(rangeMaximum);

        if (numToGen == -1 || minRange == -1 || maxRange == -1)
        {
            return;
        }

        List <float> unityRandomRangeNumbers = new List <float>();

        Randomness.Instance.UnityRandom(numToGen, minRange, maxRange, ref unityRandomRangeNumbers);

        if (roundingToggle.isOn)
        {
            //Mild rounding to make it easier
            int decimalPlaceRound = UI_Conversions.UserInputToInt(roundingPlaces.options[roundingPlaces.value].text);
            RoundToDecimalPlaces(ref unityRandomRangeNumbers, decimalPlaceRound);
        }
        //Sort the list
        unityRandomRangeNumbers.Sort();

        //Count the number of occurences of each value
        int            minCount = System.Int32.MaxValue;
        int            maxCount = System.Int32.MinValue;
        List <Vector2> counts   = CountOccurences(unityRandomRangeNumbers, ref minCount, ref maxCount);

        //plot that count vs the value
        wg.Graph(counts, new Vector2(minRange, maxRange), new Vector2(minCount, maxCount));
    }
    public void GaussianRandom()
    {
        wg = windowGraph.GetComponent <Window_Graph>();
        if (wg == null)
        {
            Debug.Log("wg is null");
            return;
        }

        Clear(wg);

        int   numToGen = UI_Conversions.UserInputToInt(numberToGenerate);
        float mean     = UI_Conversions.UserInputToFloat(rangeMinimum);
        float stdDev   = UI_Conversions.UserInputToFloat(rangeMaximum);

        if (numToGen == -1 || mean == -1 || stdDev == -1)
        {
            return;
        }

        List <float> standardDistributionRandomNumbers = new List <float>();

        Randomness.Instance.GaussianRandom(numToGen, mean, stdDev, ref standardDistributionRandomNumbers);

        if (roundingToggle.isOn)
        {
            int decimalPlaceRound = UI_Conversions.UserInputToInt(roundingPlaces.options[roundingPlaces.value].text);
            RoundToDecimalPlaces(ref standardDistributionRandomNumbers, decimalPlaceRound);
        }

        standardDistributionRandomNumbers.Sort();

        int            minCount = System.Int32.MaxValue;
        int            maxCount = System.Int32.MinValue;
        List <Vector2> counts   = CountOccurences(standardDistributionRandomNumbers, ref minCount, ref maxCount);

        wg.Graph(counts, new Vector2(mean + stdDev * -3.0f, mean + stdDev * 3.0f), new Vector2(minCount, maxCount));
    }
    public void CSharpRandom()
    {
        wg = windowGraph.GetComponent <Window_Graph>();
        if (wg == null)
        {
            Debug.Log("wg is null");
            return;
        }

        Clear(wg);

        int   numToGen = UI_Conversions.UserInputToInt(numberToGenerate);
        float minRange = UI_Conversions.UserInputToFloat(rangeMinimum);
        float maxRange = UI_Conversions.UserInputToFloat(rangeMaximum);

        if (numToGen == -1 || minRange == -1 || maxRange == -1)
        {
            return;
        }

        List <float> cSharpRandomNumbers = new List <float>();

        Randomness.Instance.CSharpRandom(numToGen, minRange, maxRange, ref cSharpRandomNumbers);

        if (roundingToggle.isOn)
        {
            int decimalPlaceRound = UI_Conversions.UserInputToInt(roundingPlaces.options[roundingPlaces.value].text);
            RoundToDecimalPlaces(ref cSharpRandomNumbers, decimalPlaceRound);
        }

        cSharpRandomNumbers.Sort();

        int            minCount = System.Int32.MaxValue;
        int            maxCount = System.Int32.MinValue;
        List <Vector2> counts   = CountOccurences(cSharpRandomNumbers, ref minCount, ref maxCount);

        wg.Graph(counts, new Vector2(minRange, maxRange), new Vector2(minCount, maxCount));
    }
    public void LootTest()
    {
        //Get the value from all of the inputs
        int  chestType    = chestTypeInput.value;
        int  lootPoolSize = UI_Conversions.UserInputToInt(lootPoolInput);
        int  iterations   = UI_Conversions.UserInputToInt(iterationsInput);
        bool inclusive    = inclusiveToggle.isOn;

        //Check the values
        if (lootPoolSize <= 0 ||
            iterations <= 0)
        {
            //exit early
            resultsText.text = "Please fill in the inputs!";
            return;
        }

        int[] loot = new int[lootPoolSize];

        for (int i = 0; i < iterations; i++)
        {
            int thisLoot = -1;
            if (inclusive)
            {
                thisLoot = (int)Randomness.Instance.RandomUniformFloat(0, lootPoolSize);
            }
            else
            {
                do
                {
                    thisLoot = (int)Randomness.Instance.RandomUniformFloat(0, lootPoolSize);
                } while (thisLoot == 0 || thisLoot == lootPoolSize);
            }
            loot[thisLoot]++;
        }

        int sum       = 0;
        int average   = 0;
        int mode      = 0;
        int modeCount = 0;
        int min       = iterations + 1;
        int minCount  = iterations + 1;

        for (int i = (inclusive == true ? 0 : 1); i < (inclusive == true ? lootPoolSize : lootPoolSize - 1); i++)
        {
            sum += loot[i];
            if (loot[i] > modeCount)
            {
                modeCount = loot[i];
                mode      = i;
            }

            if (loot[i] < minCount)
            {
                minCount = loot[i];
                min      = i;
            }
        }

        average = sum / (inclusive == true ? lootPoolSize : lootPoolSize - 2);

        //Calculate the ideal value for each item
        int idealValue = 0;

        if (inclusive)
        {
            idealValue = iterations / lootPoolSize;
        }
        else
        {
            idealValue = iterations / (lootPoolSize - 2);
        }

        //Output the results
        resultsText.text  = "";
        resultsText.text += "Generated " + iterations + " items\n";
        resultsText.text += "mean: " + average + "\n";
        resultsText.text += "mode: item_" + mode + " with " + modeCount + " occurences\n";
        resultsText.text += "min: item_" + min + " with " + minCount + " occurences\n";
        resultsText.text += "ideally each value would be " + idealValue + "\n";
        resultsText.text += "\n***All values***\n";

        for (int i = (inclusive == true ? 0 : 1); i < (inclusive == true ? lootPoolSize : lootPoolSize - 1); i++)
        {
            resultsText.text += "item_" + i + " " + loot[i] + " occurences\n";
        }
    }
Example #8
0
    //GO! Generate all the chests!
    public void ChestTest()
    {
        //Clear the results text
        resultsText.text = "";
        //See if we want to make a text file with results
        bool   log         = logFileToggle.isOn;
        string logFileName = "";

        if (log == true)
        {
            logFileName = @"Logs/ChestRarityTest_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_log.txt";
        }

        int iterations = UI_Conversions.UserInputToInt(iterationsInput);

        if (iterations == -1)
        {
            resultsText.text = "Please specify a number of iterations";
            return;
        }

        //Get modifier inputs
        //TODO: Probably better practice to have an "on end edit" for each one that updates these values rather than check here?
        int floor          = UI_Conversions.UserInputToInt(floorInput);
        int chestsPerFloor = UI_Conversions.UserInputToInt(chestsPerFloorInput);
        int luck           = UI_Conversions.UserInputToInt(luckInput);

        if (floor == -1 ||
            chestsPerFloor == -1 ||
            luck == -1)
        {
            resultsText.text += "Please fill in the \"Modifiers\" inputs";
            return;
        }

        List <int> chests = new List <int>();

        //run for the requested number of iterations
        for (int i = 0; i < iterations; i++)
        {
            //Generate chest/floor chests
            for (int j = 0; j < chestsPerFloor; j++)
            {
                chests.Add(Randomness.Instance.GenerateChest(rarities, floor, luck));
            }
        }

        //Count the number of chests of each rarity
        int[] chestCounts = new int[4];
        for (int i = 0; i < chests.Count; i++)
        {
            chestCounts[chests[i]]++;
        }

        //Create an expected output
        //Print results
        int[]  expectedChests = new int[4];
        string output         = "";

        for (int i = 0; i < 4; i++)
        {
            int totalChests = iterations * chestsPerFloor;
            expectedChests[i] = (int)Mathf.Ceil(totalChests * rarities[i]);

            string chestRarityName = "";
            if (i == 0)
            {
                chestRarityName = "common";
            }
            else if (i == 1)
            {
                chestRarityName = "uncommon";
            }
            else if (i == 2)
            {
                chestRarityName = "rare";
            }
            else
            {
                chestRarityName = "legendary";
            }

            output += "Number of " + chestRarityName + " chests generated: " + chestCounts[i];
            output += "\r\nNumber of " + chestRarityName + " chests expected: " + expectedChests[i];
            output += "\r\nDifference of " + ((float)Mathf.Abs(chestCounts[i] - expectedChests[i]) / (float)chestCounts[i]) * 100 + "%";
            output += "\r\n\r\n";
        }

        resultsText.text = output;

        if (log)
        {
            File.WriteAllText(logFileName, output);
        }
    }