public static ChanceTable <TreasureWeaponType> ParseChanceTable_WeaponType(string[] lines, int startLine) { var chanceTable = new ChanceTable <TreasureWeaponType>(); for (var i = startLine + 1; i < lines.Length; i++) { var line = lines[i].Trim(); if (line.Length < 2) { continue; } if (line.Length == 2) { break; } if (line.StartsWith("//")) { continue; } var match = Regex.Match(line, @"TreasureWeaponType.([^,]+),\s+([\d.]+)"); if (!match.Success || !System.Enum.TryParse(match.Groups[1].Value, out TreasureWeaponType weaponType) || !float.TryParse(match.Groups[2].Value, out var chance)) { Console.WriteLine($"Couldn't parse {line}"); continue; } chanceTable.Add((weaponType, chance)); } return(chanceTable); }
public static ChanceTable <bool> ParseChanceTable_Bool(string[] lines, int startLine) { var chanceTable = new ChanceTable <bool>(); for (var i = startLine + 1; i < lines.Length; i++) { var line = lines[i].Trim(); if (line.Length < 2) { continue; } if (line.Length == 2) { break; } if (line.StartsWith("//")) { continue; } var match = Regex.Match(line, @"\(\s+([^,]+),\s+([\d.]+)"); if (!match.Success || !bool.TryParse(match.Groups[1].Value, out var val) || !float.TryParse(match.Groups[2].Value, out var chance)) { Console.WriteLine($"Couldn't parse {line}"); continue; } chanceTable.Add((val, chance)); } return(chanceTable); }
public void GetRandomTest() { var chanceTable = new ChanceTable <int>(new List <ChanceTableEntry <int> > { new ChanceTableEntry <int>(1, 2), new ChanceTableEntry <int>(2, 4), new ChanceTableEntry <int>(3, 3) }); const int values_amount = 1000; var values = new List <int>(values_amount); for (var i = 0; i < values_amount; i++) { values.Add(chanceTable.GetRandom()); } Assert.IsTrue(values.Contains(1)); Assert.IsTrue(values.Contains(2)); Assert.IsTrue(values.Contains(3)); var amountOf1 = values.Count(value => value == 1); var amountOf2 = values.Count(value => value == 2); var amountOf3 = values.Count(value => value == 3); Assert.AreEqual(values_amount, amountOf1 + amountOf2 + amountOf3); Assert.IsTrue(amountOf1 < amountOf3); Assert.IsTrue(amountOf3 < amountOf2); Console.WriteLine("1: " + amountOf1); Console.WriteLine("2: " + amountOf2); Console.WriteLine("3: " + amountOf3); }
static GemCountChance() { using (var ctx = new WorldDbContext()) { var gemCounts = ctx.TreasureGemCount.Where(i => i.Chance > 0); foreach (var gemCount in gemCounts) { if (!gemCodes.TryGetValue(gemCount.GemCode, out var tiers)) { tiers = new Dictionary <int, ChanceTable <int> >(); gemCodes[gemCount.GemCode] = tiers; } if (!tiers.TryGetValue(gemCount.Tier, out var chances)) { chances = new ChanceTable <int>(); tiers[gemCount.Tier] = chances; } chances.Add((gemCount.Count, gemCount.Chance)); } } }
public void CountScore(ChanceTable Symbs) { if (Symbs.Symbol1 == Symbs.Symbol2 && Symbs.Symbol2 == Symbs.Symbol3) { if (Symbs.Symbol1 == "Berry") { Score = Score + Berrys; } if (Symbs.Symbol1 == "Aples") { Score = Score + Apples; } if (Symbs.Symbol1 == "Coins") { Score = Score + Coins; } if (Symbs.Symbol1 == "Orange") { Score = Score + Oranges; } if (Symbs.Symbol1 == "Ace") { Score = Score + Aces; } if (Symbs.Symbol1 == "Diamond") { Score = Score + Diamonds; } if (Symbs.Symbol1 == "7") { Score = Score + Sevens; } } if (Symbs.Symbol4 == Symbs.Symbol5 && Symbs.Symbol5 == Symbs.Symbol6) { if (Symbs.Symbol4 == "Berry") { Score = Score + Berrys; } if (Symbs.Symbol4 == "Aples") { Score = Score + Apples; } if (Symbs.Symbol4 == "Coins") { Score = Score + Coins; } if (Symbs.Symbol4 == "Orange") { Score = Score + Oranges; } if (Symbs.Symbol4 == "Ace") { Score = Score + Aces; } if (Symbs.Symbol4 == "Diamond") { Score = Score + Diamonds; } if (Symbs.Symbol4 == "7") { Score = Score + Sevens; } } if (Symbs.Symbol7 == Symbs.Symbol8 && Symbs.Symbol8 == Symbs.Symbol9) { if (Symbs.Symbol7 == "Berry") { Score = Score + Berrys; } if (Symbs.Symbol7 == "Aples") { Score = Score + Apples; } if (Symbs.Symbol7 == "Coins") { Score = Score + Coins; } if (Symbs.Symbol7 == "Orange") { Score = Score + Oranges; } if (Symbs.Symbol7 == "Ace") { Score = Score + Aces; } if (Symbs.Symbol7 == "Diamond") { Score = Score + Diamonds; } if (Symbs.Symbol7 == "7") { Score = Score + Sevens; } } if (Symbs.Symbol1 == Symbs.Symbol5 && Symbs.Symbol5 == Symbs.Symbol9) { if (Symbs.Symbol1 == "Berry") { Score = Score + Berrys; } if (Symbs.Symbol1 == "Aples") { Score = Score + Apples; } if (Symbs.Symbol1 == "Coins") { Score = Score + Coins; } if (Symbs.Symbol1 == "Orange") { Score = Score + Oranges; } if (Symbs.Symbol1 == "Ace") { Score = Score + Aces; } if (Symbs.Symbol1 == "Diamond") { Score = Score + Diamonds; } if (Symbs.Symbol1 == "7") { Score = Score + Sevens; } } if (Symbs.Symbol7 == Symbs.Symbol5 && Symbs.Symbol5 == Symbs.Symbol3) { if (Symbs.Symbol1 == "Berry") { Score = Score + Berrys; } if (Symbs.Symbol1 == "Aples") { Score = Score + Apples; } if (Symbs.Symbol1 == "Coins") { Score = Score + Coins; } if (Symbs.Symbol1 == "Orange") { Score = Score + Oranges; } if (Symbs.Symbol1 == "Ace") { Score = Score + Aces; } if (Symbs.Symbol1 == "Diamond") { Score = Score + Diamonds; } if (Symbs.Symbol1 == "7") { Score = Score + Sevens; } } }