Advertisement
Guest User

Keno Simulator

a guest
Dec 3rd, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include <algorithm>
  2. #include <functional>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <random>
  6. #include <vector>
  7.  
  8.  
  9.  
  10. uint32_t constexpr NUM_BALLS = 80; // total balls in the game
  11. uint32_t constexpr NUM_DRAWN = 20; // how many balls drawn for each game
  12. uint32_t constexpr NUM_CHOSEN = 8; // how many balls player picks
  13. uint32_t constexpr MILLION = 1e6;
  14. uint32_t constexpr ROUNDS = 40 * MILLION;
  15. uint32_t constexpr bet    = 4;
  16.  
  17. int64_t player_bankroll = 0;
  18.  
  19. int main(int argc, char *argv[])
  20. {
  21.     // create the RNG
  22.     std::random_device rd;
  23.     std::mt19937 rng(rd());
  24.  
  25.     // create and initialize the balls
  26.     std::vector<int> balls(NUM_BALLS, 0);
  27.     std::generate(balls.begin(), balls.end(), [n=1] () mutable { return n++; });
  28.  
  29.     // change the last number to 10000*bet for standard paytable, 60000 was to test
  30.     // whether a progressive was positive-EV
  31.     std::vector<int> awards{{ 0, 0, 0, 0, 2*bet, 13* bet, 100*bet, 1652*bet, 60000 }};
  32.  
  33.     for(uint32_t i=0; i < ROUNDS; ++ i)
  34.     {
  35.         std::shuffle(balls.begin(), balls.end(), rng);
  36.  
  37.         // out of the first 20 balls of the randomly shuffled set,
  38.         // count how many are below "NUM_CHOSEN + 1", i.e. assuming the
  39.         // player always picks numbers 1-n, since all combinations are equally likely,
  40.         // it's easier to always choose 1-n for an n-spot game. +1 is so we include n
  41.         player_bankroll += awards[ count_if(balls.begin(), balls.begin() + NUM_DRAWN,
  42.             std::bind(std::less<int>(), std::placeholders::_1, NUM_CHOSEN + 1)) ];
  43.  
  44.         //std::copy(balls.begin(), balls.begin() + NUM_DRAWN, std::ostream_iterator<int>(std::cout, " "));
  45.     }
  46.  
  47.     std::cout << "EV = " << static_cast<float>(ROUNDS * bet - player_bankroll)/static_cast<float>(player_bankroll);
  48.     //player_bankroll -= ROUNDS * bet;
  49.     //std::cout << "Bankroll = " << player_bankroll << std::endl;
  50.     std::cout << "RTP = " << static_cast<float>(player_bankroll)/static_cast<float>(ROUNDS * bet);
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement