AchillesGames

php – Cube odds: Simulating a recreation of Craps

Three of a kind poker hand in java

I would watch out with any piece of code written to “show” you are extra prone to double your cash at craps (or another recreation of likelihood) earlier than you go broke. Las Vegas is a sprawling metropolis within the desert of Nevada as a testomony to 2 issues:

  1. Ultimately, the home all the time wins
  2. Individuals are dangerous at math

There isn’t any recreation any on line casino would placed on their ground that did not leverage each guidelines. In case your code disagrees with Vegas, I am placing my cash on Vegas.

Replace:

Right here is a few C++ I wrote based mostly in your authentic code. The unique downside you posted was if you happen to may double your cash earlier than you went broke most of the time. I adopted up the code I wrote with some outcomes.

#embrace 

int die_roll()
{
    return std::rand() % 6 + 1;
}

int win_count_g(0);
int loss_count_g(0);

// return true when double our cash.
// return false once we cannot wager anymore.
bool test_loop(int money)
{
    static const int bet_k(5);

    int purpose(money * 2);
    int button(0);

    whereas (true)
    {
        if (money >= purpose)
            return true;
        else if (money < bet_k)
            return false;

        int roll(die_roll() + die_roll());
        int odds(0); // further odds wager

        if (button == 0)
        {
            if (roll == 7 || roll == 11)
            {
                ++win_count_g;
                money += bet_k;
            }
            else if (roll == 2 || roll == 3 || roll == 12)
            {
                ++loss_count_g;
                money -= bet_k;
            }
            else
            {
                button = roll;

                if (roll == 4 || roll == 10)
                {
                    odds = std::min(money - bet_k, bet_k * 3);
                }
                else if (roll == 5 || roll == 9)
                {
                    odds = std::min(money - bet_k, bet_k * 4);
                }
                else // if (roll == 6 || roll == 8)
                {
                    odds = std::min(money - bet_k, bet_k * 5);
                }
            }
        }
        else
        {
            if (roll == 7)
            {
                ++loss_count_g;
                button = 0;
                money -= bet_k + odds;
            }
            else if (roll == button)
            {
                ++win_count_g;
                button = 0;
                money += bet_k;

                if (roll == 4 || roll == 10)
                {
                    money += odds * 2;
                }
                else if (roll == 5 || roll == 9)
                {
                    money += odds * 3 / 2;
                }
                else // if (roll == 6 || roll == 8)
                {
                    money += odds * 6 / 5;
                }
            }
        }
    }
}

void take a look at(int money)
{
    win_count_g = 0;
    loss_count_g = 0;

    int doubled(0);
    int broke(0);

    for (int i(0); i < 10000; ++i)
        if (test_loop(money))
            ++doubled;
        else
            ++broke;

    float win_percentage(static_cast(doubled) / (doubled + broke) * 100.0);

    std::cout << "beginning money: $" << money
              << "; doubled: " << doubled
              << "; broke: " << broke
              << " (" << win_percentage << "% win)"
              << "; loop wins: " << win_count_g
              << "; loop losses: " << loss_count_g
              << std::endl;
}

int predominant ()
{
    static const int cash_set_k[] =
    {
        5,
        10,
        20,
        50,
        100,
        200,
        400,
        800,
        1000
    };
    static const int cash_set_size_k(sizeof(cash_set_k) / sizeof(cash_set_k[0]));

    std::for_each(&cash_set_k[0], &cash_set_k[cash_set_size_k], &take a look at);

    return 0;
}

Outcomes:

beginning money: $5; doubled: 4944; broke: 5056 (49.44% win); loop wins: 4944; loop losses: 5056
beginning money: $10; doubled: 4862; broke: 5138 (48.62% win); loop wins: 19706; loop losses: 20258
beginning money: $20; doubled: 4755; broke: 5245 (47.55% win); loop wins: 78360; loop losses: 80320
beginning money: $50; doubled: 4345; broke: 5655 (43.45% win); loop wins: 489406; loop losses: 502506
beginning money: $100; doubled: 3553; broke: 6447 (35.53% win); loop wins: 1914393; loop losses: 1972273
beginning money: $200; doubled: 2468; broke: 7532 (24.68% win); loop wins: 7172464; loop losses: 7375024
beginning money: $400; doubled: 861; broke: 9139 (8.61% win); loop wins: 22615369; loop losses: 23277609
beginning money: $800; doubled: 112; broke: 9888 (1.12% win); loop wins: 54556881; loop losses: 56121041
beginning money: $1000; doubled: 31; broke: 9969 (0.31% win); loop wins: 69308617; loop losses: 71296217

Related posts

Leave a Comment