Guest User

Drawing MtG hands, Serum powder vs Leyline

a guest
Aug 12th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.16 KB | None | 0 0
  1. // LeylinePowder.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "stdlib.h"
  6. #include <vector>
  7. #include <iostream>
  8.  
  9. // 0 is false
  10. // 1 is leyline
  11. // 2 is powder
  12.  
  13.  
  14.  
  15. int DrawCard(int deckSize, int leylineCount, int powderCount)
  16. {
  17.     // 0 -> x är leylines, x -> y är powders, y -> decksize är blanks
  18.  
  19.     int card = rand() % deckSize;
  20.     if (card < leylineCount) { return 1; }
  21.     if (card < leylineCount + powderCount) { return 2; }
  22.     return 0;
  23. }
  24.        
  25. int DrawHand(int deckSize, int leylineCount, int powderCount, int handSize)
  26. {
  27.     int l_deckSize = deckSize;
  28.     int l_leylineCount = leylineCount;
  29.     int l_powderCount = powderCount;
  30.     int ret = 0;
  31.  
  32.     for (int i = 0; i < handSize; i++)
  33.     {
  34.         l_deckSize--;
  35.         switch (DrawCard(l_deckSize, l_leylineCount, l_powderCount))
  36.         {
  37.         case 0:
  38.             break;
  39.         case 1:
  40.             l_leylineCount--;
  41.             ret = 1;
  42.             break;
  43.         case 2:
  44.             l_powderCount--;
  45.             if (ret == 0) { ret = 2; }
  46.             break;
  47.         }
  48.     }      
  49.     return ret;
  50. }          
  51.  
  52. int DrawHands(int deckSize, int leylineCount, int powderCount, int drawCount)
  53. {
  54.     if (drawCount == 0) { return 0; }
  55.     switch (DrawHand(deckSize, leylineCount, powderCount, drawCount))
  56.     {
  57.     default:
  58.         std::cout << "Something went wrong, drawHands entered default case";
  59.         return 99;
  60.     case 0:
  61.         return DrawHands(deckSize, leylineCount, powderCount, drawCount - 1);
  62.         break;
  63.     case 1:
  64.         return drawCount;
  65.         break;
  66.     case 2:
  67.         return DrawHands(deckSize - drawCount, leylineCount, powderCount - 1, drawCount);
  68.         break;
  69.     }
  70. }
  71.  
  72. void ManySimulations(int deckSize, int leylineCount, int powderCount, int simulationCount)
  73. {
  74.     std::vector<int> results;
  75.  
  76.        /*
  77.     int sevenCards = 0;
  78.     int sixCards = 0;
  79.     int fiveCards = 0;
  80.     int fourCards = 0;
  81.     int threeCards = 0;
  82.     int twoCards = 0;
  83.     int oneCard = 0;
  84.     int noCard = 0;
  85.  
  86.     for (int i = 0; i < simulationCount; i++)
  87.     {
  88.         switch (DrawHands(deckSize, leylineCount, powderCount, 7))
  89.         {
  90.         case 0:
  91.             noCard++;
  92.             break;
  93.         case 1:
  94.             oneCard++;
  95.             break;
  96.         case 2:
  97.             twoCards++;
  98.             break;
  99.         case 3:
  100.             threeCards++;
  101.             break;
  102.         case 4:
  103.             fourCards++;
  104.             break;
  105.         case 5:
  106.             fiveCards++;
  107.             break;
  108.         case 6:
  109.             sixCards++;
  110.             break;
  111.         case 7:
  112.             sevenCards++;
  113.             break;
  114.         default:
  115.             break;         
  116.         }
  117.     }
  118. */
  119.  
  120.     for (int i = 0; i < simulationCount; i++)
  121.     {
  122.         results.push_back(DrawHands(deckSize, leylineCount, powderCount, 7));
  123.     }
  124.  
  125.     for (int i = 0; i < 8; i++)
  126.     {
  127.         int acc = 0;
  128.         for (int u = 0; u < results.size(); u++)
  129.         {
  130.             if (results[u] == i) { acc++; }
  131.         }
  132.         std::cout << i << " card hands: " << acc << ". Percentage: " << (float)acc * 100.0f / (float)simulationCount << "%" << std::endl;
  133.        
  134.  
  135.     }        
  136. }
  137.  
  138.  
  139.  
  140. void Initializer()
  141. {
  142.     int deckSize;
  143.     std::cout << "Decksize:";
  144.     std::cin >> deckSize;
  145.  
  146.     int leylineCount;
  147.     std::cout << "Leylines:";
  148.     std::cin >> leylineCount;
  149.  
  150.     int powderCount;
  151.     std::cout << "Powders:";
  152.     std::cin >> powderCount;
  153.  
  154.     int simulationCount;
  155.     std::cout << "Siulations:";
  156.     std::cin >> simulationCount;
  157.  
  158.     ManySimulations(deckSize, leylineCount, powderCount, simulationCount);
  159.  
  160. }
  161.  
  162. int main()
  163. {
  164.     while (true)
  165.     {            
  166.         Initializer();
  167.     }
  168.     return 0;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment