Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LeylinePowder.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "stdlib.h"
- #include <vector>
- #include <iostream>
- // 0 is false
- // 1 is leyline
- // 2 is powder
- int DrawCard(int deckSize, int leylineCount, int powderCount)
- {
- // 0 -> x är leylines, x -> y är powders, y -> decksize är blanks
- int card = rand() % deckSize;
- if (card < leylineCount) { return 1; }
- if (card < leylineCount + powderCount) { return 2; }
- return 0;
- }
- int DrawHand(int deckSize, int leylineCount, int powderCount, int handSize)
- {
- int l_deckSize = deckSize;
- int l_leylineCount = leylineCount;
- int l_powderCount = powderCount;
- int ret = 0;
- for (int i = 0; i < handSize; i++)
- {
- l_deckSize--;
- switch (DrawCard(l_deckSize, l_leylineCount, l_powderCount))
- {
- case 0:
- break;
- case 1:
- l_leylineCount--;
- ret = 1;
- break;
- case 2:
- l_powderCount--;
- if (ret == 0) { ret = 2; }
- break;
- }
- }
- return ret;
- }
- int DrawHands(int deckSize, int leylineCount, int powderCount, int drawCount)
- {
- if (drawCount == 0) { return 0; }
- switch (DrawHand(deckSize, leylineCount, powderCount, drawCount))
- {
- default:
- std::cout << "Something went wrong, drawHands entered default case";
- return 99;
- case 0:
- return DrawHands(deckSize, leylineCount, powderCount, drawCount - 1);
- break;
- case 1:
- return drawCount;
- break;
- case 2:
- return DrawHands(deckSize - drawCount, leylineCount, powderCount - 1, drawCount);
- break;
- }
- }
- void ManySimulations(int deckSize, int leylineCount, int powderCount, int simulationCount)
- {
- std::vector<int> results;
- /*
- int sevenCards = 0;
- int sixCards = 0;
- int fiveCards = 0;
- int fourCards = 0;
- int threeCards = 0;
- int twoCards = 0;
- int oneCard = 0;
- int noCard = 0;
- for (int i = 0; i < simulationCount; i++)
- {
- switch (DrawHands(deckSize, leylineCount, powderCount, 7))
- {
- case 0:
- noCard++;
- break;
- case 1:
- oneCard++;
- break;
- case 2:
- twoCards++;
- break;
- case 3:
- threeCards++;
- break;
- case 4:
- fourCards++;
- break;
- case 5:
- fiveCards++;
- break;
- case 6:
- sixCards++;
- break;
- case 7:
- sevenCards++;
- break;
- default:
- break;
- }
- }
- */
- for (int i = 0; i < simulationCount; i++)
- {
- results.push_back(DrawHands(deckSize, leylineCount, powderCount, 7));
- }
- for (int i = 0; i < 8; i++)
- {
- int acc = 0;
- for (int u = 0; u < results.size(); u++)
- {
- if (results[u] == i) { acc++; }
- }
- std::cout << i << " card hands: " << acc << ". Percentage: " << (float)acc * 100.0f / (float)simulationCount << "%" << std::endl;
- }
- }
- void Initializer()
- {
- int deckSize;
- std::cout << "Decksize:";
- std::cin >> deckSize;
- int leylineCount;
- std::cout << "Leylines:";
- std::cin >> leylineCount;
- int powderCount;
- std::cout << "Powders:";
- std::cin >> powderCount;
- int simulationCount;
- std::cout << "Siulations:";
- std::cin >> simulationCount;
- ManySimulations(deckSize, leylineCount, powderCount, simulationCount);
- }
- int main()
- {
- while (true)
- {
- Initializer();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment