コード例 #1
0
    IEnumerator initialize()
    {
        // Initialize
        Player.restoreValuesToDefault();
        DiceCluster.allowedRolls = new List <int>()
        {
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9
        };
        // Skip anims
        Dice.minPreRollTime = 0f;
        DiceCluster.skipPostAttackAnimation   = true;
        BattleManager.speedUpBattleAnimations = true;

        UnityEngine.SceneManagement.SceneManager.LoadScene("Battle");
        yield return(null);

        // Find DiceCluster and hide other HUDs
        dc = GameObject.Find("DiceCluster").GetComponent <DiceCluster>();
        DiceCluster.isAnEffectTest = true;
        GameObject.Find("HUD").SetActive(false);
        yield return(null);

        GameObject.Find("HandCanvas").SetActive(false);
        yield return(null);
    }
コード例 #2
0
    public void TestDecideDiceScale()
    {
        Player.restoreValuesToDefault();
        Player.diceMultiplier = 1;
        int[] nDices = new int[] { 1, 13, 25, 36, 50, 100, 121, 122, 169, 170, 225, 226,
                                   256, 289, 290, 500, 1000000 };
        float[] expectedScales = new float[] { 1.5f, 1.25f, 1f, 1f, .767f, .55f, .459f, 0.457f, 0.457f, 0.4f, 0.4f, 0.375f,
                                               0.375f, 0.35f, 0.325f, 0.325f, 0.325f };

        for (int i = 0; i < nDices.Length; i++)
        {
            Player.nDice = nDices[i];
            float actualScale   = DiceCluster.decideDiceScale(Player.nDice);
            float expectedScale = expectedScales[i];
            Assert.AreEqual(expectedScale, actualScale, 0.001f); // 3-digit precision
        }
    }
コード例 #3
0
    public void TestDecideDicePositions()
    {
        Player.restoreValuesToDefault();
        Player.diceMultiplier = 1;
        int[]            nDices = new int[] { 1, 2, 3, 4 };
        List <Vector2[]> expectedPositionsArray = new List <Vector2[]>()
        {
            new Vector2[] { Vector2.zero },
            new Vector2[] { new Vector2(-200, 0), new Vector2(200, 0) },
            new Vector2[] { new Vector2(-200, 55), new Vector2(200, 55), new Vector2(0, -55) },
            new Vector2[] { new Vector2(-200, 55), new Vector2(200, 55), new Vector2(-200, -55), new Vector2(200, -55) }
        };

        for (int i = 0; i < nDices.Length; i++)
        {
            Player.nDice = nDices[i];
            float     scale             = DiceCluster.decideDiceScale(Player.nDice);
            int       nDiceObjs         = (Player.nDice > diceLimit) ? diceLimit : (int)Player.nDice;
            Vector2[] actualPositions   = DiceCluster.decideDicePositions(nDiceObjs, scale, diceLimit);
            Vector2[] expectedPositions = expectedPositionsArray[i];
            Assert.AreEqual(actualPositions, expectedPositions);
        }

        // Check that the dice are always within the margins of the screen
        int screenWidth        = 1600;
        int screenHeight       = 900;
        int minimumWidthMargin = 20;

        nDices = new int[] { 10, 25, 50, 75, 100, 200, 250, 300, 500, 1000000 };
        for (int i = 0; i < nDices.Length; i++)
        {
            Player.nDice = nDices[i];
            float     scale           = DiceCluster.decideDiceScale(Player.nDice);
            int       nDiceObjs       = (Player.nDice > diceLimit) ? diceLimit : (int)Player.nDice;
            Vector2[] actualPositions = DiceCluster.decideDicePositions(nDiceObjs, scale, diceLimit);
            foreach (Vector2 dicePosition in actualPositions)
            {
                Assert.GreaterOrEqual(dicePosition.x, -screenWidth / 2 + minimumWidthMargin);
                Assert.LessOrEqual(dicePosition.x, screenWidth / 2 - minimumWidthMargin);
                Assert.GreaterOrEqual(dicePosition.y, -screenHeight / 2);
                Assert.LessOrEqual(dicePosition.y, screenHeight / 2);
            }
        }
    }
コード例 #4
0
    public void Awake()
    {
        forcedRolls  = new List <int>();
        allowedRolls = new List <int>()
        {
            0, 1, 2, 3, 4, 5, 6, 7, 8, 9
        };
        showingVictoryAnimation = false;

        dicePool = new List <GameObject>();
        for (int i = 0; i < diceLimit + 1; i++) // 1 extra dice above the limit, to allow swapping dice
        {
            GameObject obj = Instantiate(dice);
            obj.SetActive(false);
            obj.transform.SetParent(transform);
            dicePool.Add(obj);
        }

        dcInstance = this;
    }
コード例 #5
0
    public void TestSwapDiceForRandomOne()
    {
        Player.restoreValuesToDefault();
        Player.diceMultiplier = 1;
        // Initialize values
        int maxRoll   = 1000;
        int nDiceObjs = diceLimit;

        DiceCluster.diceObjArray   = new Dice[nDiceObjs];
        DiceCluster.diceGroupArray = new DiceGroup[maxRoll + 1];
        for (int i = 0; i < DiceCluster.diceGroupArray.Length; i++)
        {
            DiceCluster.diceGroupArray[i] = new DiceGroup();
        }

        // Fill with random numbers
        GameObject dummyDiceObject;
        int        rollResult = 100;

        for (int i = 0; i < 500; i++)
        {
            DiceCluster.diceGroupArray[rollResult].nRolls++;

            if (i < diceLimit)
            {
                dummyDiceObject = new GameObject();
                dummyDiceObject.AddComponent <Dice>();
                DiceCluster.addDiceToArrays(rollResult, i, dummyDiceObject);
                DiceCluster.diceObjArray[i].value = rollResult;
            }
        }

        dummyDiceObject = new GameObject();
        dummyDiceObject.AddComponent <Dice>();
        int randomIndex = Random.Range(0, diceLimit);

        DiceCluster.swapDiceForRandomOne(randomIndex, Player.attackRolls[0], dummyDiceObject);

        Assert.AreEqual(1, DiceCluster.diceGroupArray[Player.attackRolls[0]].diceIDs.Count);
        Assert.AreEqual(diceLimit - 1, DiceCluster.diceGroupArray[rollResult].diceIDs.Count);
    }
コード例 #6
0
    public void TestGetNColsRows()
    {
        int[] nDices = new int[] { 1, 2, 3,
                                   4, 5, 7, 10, 20,
                                   30, 50, 75, 100, 195,
                                   196, 197, 250, 361 };
        List <int[]> nColsRows = new List <int[]> {
            new int[] { 1, 1 }, new int[] { 2, 1 }, new int[] { 2, 2 },
            new int[] { 2, 2 }, new int[] { 3, 2 }, new int[] { 3, 3 }, new int[] { 4, 3 }, new int[] { 5, 4 },
            new int[] { 6, 5 }, new int[] { 8, 7 }, new int[] { 9, 9 }, new int[] { 10, 10 }, new int[] { 14, 14 },
            new int[] { 14, 14 }, new int[] { 15, 14 }, new int[] { 16, 16 }, new int[] { 19, 19 }
        };

        for (int i = 0; i < nColsRows.Count; i++)
        {
            int actualNCols   = DiceCluster.getNCols(nDices[i]);
            int actualNRows   = DiceCluster.getNRows(nDices[i], actualNCols);
            int expectedNCols = nColsRows[i][0];
            int expectedNRows = nColsRows[i][1];
            Assert.AreEqual(expectedNCols, actualNCols);
            Assert.AreEqual(expectedNRows, actualNRows);
        }
    }
コード例 #7
0
    public void TestQuickRoll()
    {
        // Only half allowed
        Player.maxRoll           = 1000;
        DiceCluster.allowedRolls = new List <int>()
        {
            5, 6, 7, 8, 9
        };
        List <int> allowedNumbers = DiceCluster.prepareAllowedNumbers();

        for (int i = 0; i < 10000; i++)
        {
            int diceRoll = Dice.quickRoll(DiceCluster.allowedRolls, allowedNumbers);
            if (diceRoll % 10 <= 4)
            {
                Assert.Fail("Roll ended in " + (diceRoll % 10));
            }
        }

        // Only even allowed
        DiceCluster.allowedRolls = new List <int>()
        {
            0, 2, 4, 6, 8
        };
        allowedNumbers = DiceCluster.prepareAllowedNumbers();
        for (int i = 0; i < 10000; i++)
        {
            int diceRoll = Dice.quickRoll(DiceCluster.allowedRolls, allowedNumbers);
            if (diceRoll % 2 == 1)
            {
                Assert.Fail("Roll ended in " + (diceRoll % 10));
            }
        }

        // Only even allowed, low ceil
        Player.maxRoll           = 5;
        DiceCluster.allowedRolls = new List <int>()
        {
            0, 2, 4, 6, 8
        };
        allowedNumbers = DiceCluster.prepareAllowedNumbers();
        for (int i = 0; i < 10000; i++)
        {
            int diceRoll = Dice.quickRoll(DiceCluster.allowedRolls, allowedNumbers);
            if (diceRoll != 2 && diceRoll != 4)
            {
                Assert.Fail("Roll ended in " + (diceRoll % 10));
            }
        }

        // Impossible combination, just to make sure there is no infinite loop
        Player.maxRoll           = 3;
        DiceCluster.allowedRolls = new List <int>()
        {
            0, 4, 5, 6, 7, 8, 9
        };
        allowedNumbers = DiceCluster.prepareAllowedNumbers();
        for (int i = 0; i < 5; i++)
        {
            int diceRoll = Dice.quickRoll(DiceCluster.allowedRolls, allowedNumbers);
        }

        // Ensure that all dice rolls happen with the same likelihood
        Player.maxRoll           = 1000;
        DiceCluster.allowedRolls = new List <int>()
        {
            0, 1, 2, 3, 4
        };
        allowedNumbers = DiceCluster.prepareAllowedNumbers();
        int[] nRolls = new int[1001];
        for (int i = 0; i < 1000000; i++) // Roll dice and save their results
        {
            int diceRoll = Dice.quickRoll(DiceCluster.allowedRolls, allowedNumbers);
            nRolls[diceRoll]++;
        }
        for (int i = 0; i < nRolls.Length; i++) // Check that all non-forbidden dice roll with the same chance
        {
            if (i % 10 <= 4 && i != 0)
            {
                Assert.AreEqual(2000f, nRolls[i], 200, "Dice rolled on " + i + " -> " + nRolls[i] + " times");
            }
        }
    }
コード例 #8
0
    public void TestAddDiceToArrays()
    {
        int maxRoll = 1000;

        // Initialize values
        int[] rolls     = new int[] { 2, 7, 15, 7, 20, 1000, 7, 2, 2 };
        int   nDiceObjs = Mathf.Min(rolls.Length, diceLimit);

        DiceCluster.diceObjArray   = new Dice[nDiceObjs];
        DiceCluster.diceGroupArray = new DiceGroup[maxRoll + 1];
        for (int i = 0; i < DiceCluster.diceGroupArray.Length; i++)
        {
            DiceCluster.diceGroupArray[i] = new DiceGroup();
        }

        DiceGroup[] expectedGroupArray = new DiceGroup[maxRoll + 1];
        for (int i = 0; i < expectedGroupArray.Length; i++)
        {
            expectedGroupArray[i] = new DiceGroup();
        }
        expectedGroupArray[2] = new DiceGroup(3, new List <int>()
        {
            0, 7, 8
        });
        expectedGroupArray[7] = new DiceGroup(3, new List <int>()
        {
            1, 3, 6
        });
        expectedGroupArray[15] = new DiceGroup(1, new List <int>()
        {
            2
        });
        expectedGroupArray[20] = new DiceGroup(1, new List <int>()
        {
            4
        });
        expectedGroupArray[1000] = new DiceGroup(1, new List <int>()
        {
            5
        });

        // Fill arrays
        for (int i = 0; i < rolls.Length; i++)
        {
            GameObject dummyDiceObject = new GameObject();
            dummyDiceObject.AddComponent <Dice>();
            DiceCluster.addDiceToArrays(rolls[i], i, dummyDiceObject);
            DiceCluster.diceGroupArray[rolls[i]].nRolls++;
            DiceCluster.diceObjArray[i].value = rolls[i];
        }

        // Assert same diceObjArrays
        for (int i = 0; i < rolls.Length; i++)
        {
            Assert.AreEqual(rolls[i], DiceCluster.diceObjArray[i].value);
        }

        // Assert same diceGroupArrays
        for (int i = 0; i < expectedGroupArray.Length; i++)
        {
            Assert.AreEqual(expectedGroupArray[i].nRolls, DiceCluster.diceGroupArray[i].nRolls);
            Assert.AreEqual(expectedGroupArray[i].diceIDs, DiceCluster.diceGroupArray[i].diceIDs);
        }
    }