public void CombinationTest_CreatesGenericPatternCorrectly() { Assert.Equal(new char[] { 'a' }, GameUtility.CreateGenericPatternFromDice(new int[] { 1 })); Assert.Equal(new char[] { 'a', 'b' }, GameUtility.CreateGenericPatternFromDice(new int[] { 3, 1 })); Assert.Equal(new char[] { 'a', 'a', 'b' }, GameUtility.CreateGenericPatternFromDice(new int[] { 3, 1, 3 })); Assert.Equal(new char[] { 'a', 'b', 'c' }, GameUtility.CreateGenericPatternFromDice(new int[] { 3, 1, 2 })); Assert.Equal(new char[] { 'a', 'a', 'b', 'b' }, GameUtility.CreateGenericPatternFromDice(new int[] { 1, 2, 1, 2 })); Assert.Equal(new char[] { 'a', 'a', 'a', 'b', 'c' }, GameUtility.CreateGenericPatternFromDice(new int[] { 5, 1, 2, 5, 5 })); Assert.Equal(new char[] { 'a', 'a', 'b', 'c', 'd', 'e' }, GameUtility.CreateGenericPatternFromDice(new int[] { 1, 2, 1, 3, 4, 5 })); Assert.Equal(new char[] { 'a', 'a', 'a', 'b', 'b', 'b' }, GameUtility.CreateGenericPatternFromDice(new int[] { 6, 5, 5, 6, 5, 6 })); Assert.Equal(new char[] { 'a', 'b', 'c', 'd', 'e', 'f' }, GameUtility.CreateGenericPatternFromDice(new int[] { 1, 2, 3, 4, 5, 6 })); }
public void SetProbabilitiesAndEVToCompleteCombinationWithinAllAvailableRolls(int maximumNumberOfRolls, int[] rolledDice, Dictionary <string, decimal[]> patternProbabilities) { var patternOfMissingDice = GameUtility.CreateGenericPatternFromDice(MissingDiceToCompleteCombination(rolledDice)); // Number of dice the player have left to roll to complete a combination var rollingDiceCount = 6 - (Dice.Length - DiceToCompleteCombination.Length); // Find the corresponding pattern probability for how many dice a player has left to roll var key = new string(patternOfMissingDice) + rollingDiceCount; var probabilitiesForAvailableRolls = patternProbabilities[key].Take(maximumNumberOfRolls).ToArray(); ProbabilitiesToCompleteCombinationWithinAllAvailableRolls = probabilitiesForAvailableRolls; ExpectedValuesForCombinationWithinAllAvailableRolls = probabilitiesForAvailableRolls.Select(p => p * Score).ToArray(); }
public void GenericPatterns_CheckIfWeHaveAllNeededPatterns() { var dice = new int[6] { 0, 0, 0, 0, 0, 0 }; var patterns = GameUtility.GetPatterns(); // Add empty pattern for simplicity of this test patterns.Add(new char[] { }); var patternFrequencies = patterns.ToDictionary(x => x, x => 0, new ArrayEqualityComparerChar()); var combinationList = new CombinationList(); var isPatternMissing = false; var count = 0; foreach (var rollWithCombinations in combinationList.ReadFullRollListWithAllMatchingCombinations()) { dice = rollWithCombinations.Key; count++; foreach (var com in combinationList.Combinations) { var missingDice = com.MissingDiceToCompleteCombination(dice); var pattern = GameUtility.CreateGenericPatternFromDice(missingDice); if (!patternFrequencies.ContainsKey(pattern)) { isPatternMissing = true; } else { patternFrequencies[pattern]++; } } } Assert.False(isPatternMissing); Assert.Equal(Math.Pow(6, 6) * combinationList.Combinations.Length, patternFrequencies.Sum(x => x.Value)); Assert.Equal(Math.Pow(6, 6), count); foreach (var pat in patternFrequencies) { Assert.True(pat.Value > 0); } }
public void CombinationTest_CreateGenericPatternsForMissingDiceFromCombinationCorrectly() { var combination = new Combination(CombinationType.Threes) { Dice = new int[] { 3, 3, 3, 3 } }; var missingDice = combination.MissingDiceToCompleteCombination(new int[] { 3, 1, 5, 5, 2, 3 }); Assert.Equal(new int[] { 3, 3 }, missingDice); var pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { 'a', 'a' }, pattern); missingDice = combination.MissingDiceToCompleteCombination(new int[] { 6, 1, 5, 5, 2, 3 }); Assert.Equal(new int[] { 3, 3, 3 }, missingDice); pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { 'a', 'a', 'a' }, pattern); missingDice = combination.MissingDiceToCompleteCombination(new int[] { 3, 1, 3, 5, 2, 3 }); Assert.Equal(new int[] { 3 }, missingDice); pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { 'a' }, pattern); missingDice = combination.MissingDiceToCompleteCombination(new int[] { 3, 1, 3, 3, 2, 3 }); Assert.Equal(new int[] { }, missingDice); pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { }, pattern); combination = new Combination(CombinationType.Pairs) { Dice = new int[] { 1, 1, 3, 3, 5, 5 } }; missingDice = combination.MissingDiceToCompleteCombination(new int[] { 6, 6, 4, 4, 2, 2 }); Assert.Equal(new int[] { 1, 1, 3, 3, 5, 5 }, missingDice); pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { 'a', 'a', 'b', 'b', 'c', 'c' }, pattern); missingDice = combination.MissingDiceToCompleteCombination(new int[] { 6, 1, 5, 5, 2, 3 }); Assert.Equal(new int[] { 1, 3 }, missingDice); pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { 'a', 'b' }, pattern); missingDice = combination.MissingDiceToCompleteCombination(new int[] { 3, 1, 3, 5, 2, 3 }); Assert.Equal(new int[] { 1, 5 }, missingDice); pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { 'a', 'b' }, pattern); missingDice = combination.MissingDiceToCompleteCombination(new int[] { 3, 1, 3, 3, 2, 3 }); Assert.Equal(new int[] { 1, 5, 5 }, missingDice); pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { 'a', 'a', 'b' }, pattern); missingDice = combination.MissingDiceToCompleteCombination(new int[] { 5, 1, 3, 3, 5, 1 }); Assert.Equal(new int[] { }, missingDice); pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { }, pattern); missingDice = combination.MissingDiceToCompleteCombination(new int[] { 5, 3, 1, 4, 2, 6 }); Assert.Equal(new int[] { 1, 3, 5 }, missingDice); pattern = GameUtility.CreateGenericPatternFromDice(missingDice); Assert.Equal(new char[] { 'a', 'b', 'c' }, pattern); }