public int RollDice() { DiceRolls.Clear(); int result = 0; Random randy = new Random(); if (dieMax < 1) { return(1); } else { if (dieAmt > 999) { dieAmt = 999; } for (int i = 0; i < dieAmt; i++) { int temp = randy.Next(dieMax) + 1; DiceRolls.Add(temp); result += temp; } RawDieTotal = result; result += add; return(result); } }
public void Play(Game game) { DiceRolls rolls = new DiceRolls(); game.SumOfDices = rolls.RollDice(); CheckGameStatus(game); }
public static void SelectHomeWorld(Player player) { Random rn = new Random(); var result = Convert.ToInt32(DiceRolls.RollD100(rn)); if (result >= 1 && result <= 15) { player.HomeWorld = "Feral World"; } if (result >= 16 && result <= 33) { player.HomeWorld = "Forge World"; } if (result >= 34 && result <= 44) { player.HomeWorld = "High Born"; } if (result >= 45 && result <= 69) { player.HomeWorld = "Hive World"; } if (result >= 70 && result <= 85) { player.HomeWorld = "Shrine World"; } if (result >= 86 && result <= 100) { player.HomeWorld = "Void Born"; } }
public HomeWorld RandomlySelectHomeWorld()//used for random generation. { HomeWorld homeworldRandom = null; Cryptorandom rn = new Cryptorandom(); var result = Convert.ToInt32(DiceRolls.RollD100(rn)); if (result >= 1 && result <= 15) { homeworldRandom = World.GetHomeworldById(Constants.FeralWorld); } if (result >= 16 && result <= 33) { homeworldRandom = World.GetHomeworldById(Constants.ForgeWorld); } if (result >= 34 && result <= 44) { homeworldRandom = World.GetHomeworldById(Constants.HighBorn); } if (result >= 45 && result <= 69) { homeworldRandom = World.GetHomeworldById(Constants.HiveWorld); } if (result >= 70 && result <= 85) { homeworldRandom = World.GetHomeworldById(Constants.ShrineWorld); } if (result >= 86 && result <= 100) { homeworldRandom = World.GetHomeworldById(Constants.VoidBorn); } return(homeworldRandom); }
/// <summary> /// 1. Get all dice rolls iteratively while also keeping track of sum and prod mod /// 2. filter the elements having equal sum and prod mod values. /// The running time is O(6^n) /// The space requriement is O(6^n) /// /// This is not an optimal solution as space requirement is more here as we are tackling the problem as BFS /// </summary> /// <param name="mod">mod value so that we dont have overflow for sum and product</param> /// <param name="maxDiceRolls">max number of dice rolls that needs to be performed</param> /// <returns></returns> public static int GetCountOfGoodDiceRolls(int mod, int maxDiceRolls) { //1. initialization List <DiceRolls> previous = new List <DiceRolls>(); List <DiceRolls> current = new List <DiceRolls>(); previous.Add(new DiceRolls(mod)); //2. get all the dice rolls for (int i = 1; i <= maxDiceRolls; i++) { foreach (DiceRolls dr in previous) { for (int diceVal = 1; diceVal <= 6; diceVal++) { DiceRolls drClone = dr.Clone(); drClone.Add(diceVal); current.Add(drClone); } } previous = current; current = new List <DiceRolls>(); } //3. Get all the good rolls return(previous.Where(x => x.ProdMod == x.SumMod).Count()); }
private int CalculatePairCategory() { var pairList = DiceRolls.GroupBy(dice => dice) .Where(groupedDice => groupedDice.Count() == NumberOfDiceInAPair) .Select(s => s.Key); return(pairList.Any() ? NumberOfDiceInAPair * (int)pairList.Max() : 0); }
private int CalculateThreeOfAKindCategory() { var tripleList = DiceRolls.GroupBy(dice => dice) .Where(groupedDice => groupedDice.Count() == NumberOfDiceInATriple) .Select(s => s.Key); return(tripleList.Any() ? NumberOfDiceInATriple * (int)tripleList.Single() : 0); }
private int CalculateSmallStraight() { if (DiceRolls.Distinct().Count() == 5 && !DiceRolls.Contains(Dice.One)) { return(20); } return(0); }
public DiceRolls Clone() { DiceRolls clone = new DiceRolls(Mod); clone.AllDiceRolls = new List <int>(AllDiceRolls); clone.SumMod = SumMod; clone.ProdMod = ProdMod; return(clone); }
public int CalculateDamage(int dietoroll = 1) { Cryptorandom rn = new Cryptorandom(); var roll = DiceRolls.RollD10(dietoroll, rn); var x = roll[0]; var damage = x + BaseDamage; return(x); }
public void Move(int numberOfSpaces) { if (MovingForward && Location + DiceRolls.Sum() > _endLocation) { MovingForward = false; UpdateLocation(2 * Location - 2 * _endLocation + DiceRolls.Sum()); return; } UpdateLocation(numberOfSpaces); }
public static void AllocateValues(Player player) { Random rn = new Random(); PropertyInfo[] pi = player.GetType().GetProperties(); var statValue = 0; //TEST player.HomeWorld = "Feral World"; for (int i = 0; i < 12; i++) { statValue = 0; if (pi[i].PropertyType == typeof(int))//checks if the value is an int { statValue = DiceRolls.RollD10(2, rn).Sum(); if (player.HomeWorld == "Feral World") { if (pi[i].Name == "Str") { int[] roll = DiceRolls.RollD10(3, rn); statValue = DiceRolls.TakeDice(2, roll, true).Sum(); } if (pi[i].Name == "T") { int[] roll = DiceRolls.RollD10(3, rn); statValue = DiceRolls.TakeDice(2, roll, true).Sum(); } if (pi[i].Name == "Inte") { int[] roll = DiceRolls.RollD10(3, rn); statValue = DiceRolls.TakeDice(2, roll, false).Sum(); } } statValue += 25; if (statValue >= 100) { statValue = 100; } pi[i].SetValue(player, statValue); } } }
private int CalculateFullHouseCategory() { var pairList = DiceRolls.GroupBy(dice => dice) .Where(groupedDice => groupedDice.Count() == NumberOfDiceInAPair) .Select(s => s.Key); var tripleList = DiceRolls.GroupBy(dice => dice) .Where(groupedDice => groupedDice.Count() == NumberOfDiceInATriple) .Select(s => s.Key); var pairListresult = pairList.Any() ? NumberOfDiceInAPair * (int)pairList.Single() : 0; var tripleListresult = tripleList.Any() ? NumberOfDiceInATriple * (int)tripleList.Single() : 0; if (pairList.Any() && tripleList.Any()) { return(pairListresult + tripleListresult); } return(0); }
private int CalculateYatzy() { return(DiceRolls.All(dice => dice == DiceRolls.First()) ? 50 : 0); }
private int CalculateChance() { return(DiceRolls.Sum(dice => (int)dice)); }