Guest User

Untitled

a guest
May 3rd, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Program
  6. {
  7.     static Random rng = new Random();
  8.  
  9.     public static void Main()
  10.     {
  11.         var numberSetsCreated = 0;
  12.         while (true)
  13.         {
  14.             numberSetsCreated++;
  15.             var casts = GenerateTestSpellCasts(100, 50, 44);
  16.             var testResults = InterestingSpellResistStreaks(casts, 7);
  17.             foreach (var interestingThing in testResults)
  18.             {
  19.                 Console.ForegroundColor = ConsoleColor.Green;
  20.                 Console.WriteLine($"Dataset { numberSetsCreated } - { interestingThing }");
  21.             }
  22.         }
  23.     }
  24.  
  25.     public static int GetPvpResistChance(int spellLevel, int targetLevel)
  26.     {
  27.         var result = (85 + ((spellLevel - targetLevel) / 2));
  28.         return result;
  29.     }
  30.     public static IEnumerable<bool> GenerateTestSpellCasts(int size, int spellLevel, int targetLevel) => Enumerable.Range(0, size).Select(r => Chance(GetPvpResistChance(spellLevel, targetLevel)));
  31.  
  32.     public static IEnumerable<string> InterestingSpellResistStreaks(IEnumerable<bool> castResults, int lengthInteresting)
  33.     {
  34.         bool lastResult = false;
  35.         int currentStreakLength = 0;
  36.  
  37.         var results = new Dictionary<int, SpellResistStreak>();
  38.  
  39.         var setSize = castResults.Count();
  40.         for (var i = 0; i < setSize; i++)
  41.         {
  42.             var cast = castResults.ElementAt(i);
  43.             if (cast == lastResult)
  44.             {
  45.                 currentStreakLength++;
  46.                 if (i == setSize - 1 && currentStreakLength >= lengthInteresting && !lastResult)
  47.                 {
  48.                     var streakId = results.Count() + 1;
  49.                     results.Add(streakId, new SpellResistStreak() { StreakLength = currentStreakLength, StreakType = lastResult });
  50.                 }
  51.             }
  52.             else
  53.             {
  54.                 if (currentStreakLength >= lengthInteresting && !lastResult)
  55.                 {
  56.                     var streakId = results.Count() + 1;
  57.                     results.Add(streakId, new SpellResistStreak() { StreakLength = currentStreakLength, StreakType = lastResult });
  58.                 }
  59.                 currentStreakLength = 1;
  60.                 lastResult = cast;
  61.             }
  62.         }
  63.  
  64.         return results
  65.             .Select(a => $"A streak of { a.Value.StreakLength } { (a.Value.StreakType ? "Hits" : "Resists") }");
  66.  
  67.     }
  68.  
  69.     public static bool Chance(int chancePercent)
  70.     {
  71.         return chancePercent >= Random(0, 100);
  72.     }
  73.  
  74.     public static int Random(int min, int max)
  75.     {
  76.         return rng.Next(min, max + 1);
  77.     }
  78. }
  79.  
  80.  
  81. class SpellResistStreak
  82. {
  83.     public bool StreakType { get; set; }
  84.     public int StreakLength { get; set; }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment