Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- static Random rng = new Random();
- public static void Main()
- {
- var numberSetsCreated = 0;
- while (true)
- {
- numberSetsCreated++;
- var casts = GenerateTestSpellCasts(100, 50, 44);
- var testResults = InterestingSpellResistStreaks(casts, 7);
- foreach (var interestingThing in testResults)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine($"Dataset { numberSetsCreated } - { interestingThing }");
- }
- }
- }
- public static int GetPvpResistChance(int spellLevel, int targetLevel)
- {
- var result = (85 + ((spellLevel - targetLevel) / 2));
- return result;
- }
- public static IEnumerable<bool> GenerateTestSpellCasts(int size, int spellLevel, int targetLevel) => Enumerable.Range(0, size).Select(r => Chance(GetPvpResistChance(spellLevel, targetLevel)));
- public static IEnumerable<string> InterestingSpellResistStreaks(IEnumerable<bool> castResults, int lengthInteresting)
- {
- bool lastResult = false;
- int currentStreakLength = 0;
- var results = new Dictionary<int, SpellResistStreak>();
- var setSize = castResults.Count();
- for (var i = 0; i < setSize; i++)
- {
- var cast = castResults.ElementAt(i);
- if (cast == lastResult)
- {
- currentStreakLength++;
- if (i == setSize - 1 && currentStreakLength >= lengthInteresting && !lastResult)
- {
- var streakId = results.Count() + 1;
- results.Add(streakId, new SpellResistStreak() { StreakLength = currentStreakLength, StreakType = lastResult });
- }
- }
- else
- {
- if (currentStreakLength >= lengthInteresting && !lastResult)
- {
- var streakId = results.Count() + 1;
- results.Add(streakId, new SpellResistStreak() { StreakLength = currentStreakLength, StreakType = lastResult });
- }
- currentStreakLength = 1;
- lastResult = cast;
- }
- }
- return results
- .Select(a => $"A streak of { a.Value.StreakLength } { (a.Value.StreakType ? "Hits" : "Resists") }");
- }
- public static bool Chance(int chancePercent)
- {
- return chancePercent >= Random(0, 100);
- }
- public static int Random(int min, int max)
- {
- return rng.Next(min, max + 1);
- }
- }
- class SpellResistStreak
- {
- public bool StreakType { get; set; }
- public int StreakLength { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment