wooferzfg1

Mafia Boss Simulation

Dec 9th, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MafiaBoss
  8. {
  9.     class Program
  10.     {
  11.         static List<int> currentBossAttacks;
  12.         static int mode = -1;
  13.         static int cycle = 0;
  14.         static int bossTurn = -1;
  15.         static int currentBossAttack = -1;
  16.         static Random rnd;
  17.  
  18.         static bool IsBossAttackAllowed(int attackID, int indexInArray, int currentTurn)
  19.         {
  20.             if (mode == 0 && attackID != 0 && indexInArray == 0 && currentTurn == 0) return false;
  21.             if (mode == 1 && attackID != 1 && indexInArray == 0 && currentTurn == 0) return false;
  22.             if (currentBossAttack == attackID && indexInArray == 0) return false;
  23.             return true;
  24.         }
  25.  
  26.         static int PullRandomBossAttack(int maxAttackID)
  27.         {
  28.             if (currentBossAttacks.Count <= 0)
  29.             {
  30.                 bossTurn++;
  31.                 List<int> potentialAttackIDs = new List<int>();
  32.                 for (int i = 0; i <= maxAttackID; i++)
  33.                     potentialAttackIDs.Add(i);
  34.                 while (potentialAttackIDs.Count > 0)
  35.                 {
  36.                     int i = rnd.Next(potentialAttackIDs.Count);
  37.                     if (!IsBossAttackAllowed(potentialAttackIDs[i], currentBossAttacks.Count, bossTurn)) continue;
  38.                     currentBossAttacks.Add(potentialAttackIDs[i]);
  39.                     potentialAttackIDs.RemoveAt(i);
  40.                 }
  41.             }
  42.             if (currentBossAttacks.Count <= 0) return -1;
  43.  
  44.             int firstAttack = currentBossAttacks[0];
  45.             currentBossAttacks.RemoveAt(0);
  46.             return firstAttack;
  47.         }
  48.        
  49.         static void clearBossAttacksOnNewMode()
  50.         {
  51.             bossTurn = -1;
  52.             currentBossAttack = -1;
  53.             currentBossAttacks = new List<int>();
  54.         }
  55.  
  56.         static void advanceMode()
  57.         {
  58.             mode++;
  59.             cycle = 0;
  60.             clearBossAttacksOnNewMode();
  61.         }
  62.  
  63.         struct ResultIndex
  64.         {
  65.             public int beanbags;
  66.             public int angeries;
  67.  
  68.             public ResultIndex(int b, int a)
  69.             {
  70.                 beanbags = b;
  71.                 angeries = a;
  72.             }
  73.         }
  74.  
  75.         static void Main(string[] args)
  76.         {
  77.             IDictionary<ResultIndex, int> results = new Dictionary<ResultIndex, int>();
  78.             rnd = new Random();
  79.  
  80.             for (int i = 0; i < 10000000; i++)
  81.             {
  82.                 int beanbags = 0;
  83.                 int angeries = 0;
  84.                 mode = -1;
  85.  
  86.                 //Mode A
  87.                 advanceMode();
  88.                 int bossHealth = 4;
  89.                 while (bossHealth > 0 || bossTurn == 0)
  90.                 {
  91.                     currentBossAttack = PullRandomBossAttack(3);
  92.                     if (currentBossAttack == 0)
  93.                     {
  94.                         //Spin
  95.                         bossHealth--;
  96.                     }
  97.                     else if (currentBossAttack == 1)
  98.                     {
  99.                         //Beanbags
  100.                         beanbags++;
  101.                     }
  102.                     else if (currentBossAttack == 2)
  103.                     {
  104.                         //Electric Strike
  105.                         bossHealth--;
  106.                     }
  107.                     else if (currentBossAttack == 3)
  108.                     {
  109.                         //Get Angry
  110.                         angeries++;
  111.                     }
  112.                 }
  113.  
  114.                 //Mode B
  115.                 advanceMode();
  116.                 bossHealth = 2;
  117.                 while (bossHealth > 0 || bossTurn == 0)
  118.                 {
  119.                     currentBossAttack = PullRandomBossAttack(2);
  120.                     if (currentBossAttack == 0)
  121.                     {
  122.                         //Beanbags
  123.                         beanbags++;
  124.                     }
  125.                     else if (currentBossAttack == 1)
  126.                     {
  127.                         //Throw Cutters
  128.                         bossHealth--;
  129.                     }
  130.                     else if (currentBossAttack == 2)
  131.                     {
  132.                         //Get Angry
  133.                         angeries++;
  134.                     }
  135.                 }
  136.  
  137.                 var resultIndex = new ResultIndex(beanbags, angeries);
  138.                 if (!results.ContainsKey(resultIndex))
  139.                     results[resultIndex] = 1;
  140.                 else
  141.                     results[resultIndex]++;
  142.             }
  143.  
  144.             foreach (KeyValuePair<ResultIndex, int> kvp in results.OrderBy(x => x.Key.beanbags * 12 + x.Key.angeries * 3))
  145.             {
  146.                 Console.WriteLine("Beanbags: {0}, Get Angry: {1} - {2}", kvp.Key.beanbags, kvp.Key.angeries, kvp.Value);
  147.             }
  148.  
  149.             while (true) { }
  150.         }
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment