Category Archives: c++

On Roulette

So I recently heard about the Martingale betting system, and saw how it could be used for Roulette. I sought to apply it, and was curious about what results I would find.

At first, I was incredibly excited! I found I could achieve a 99% win rate with some realistic cash numbers.

Then I took a closer look. I saw there was something wrong. I looked it up on wikipedia, and sure enough…

http://en.wikipedia.org/wiki/Martingale_(roulette_system)

I came to the same conclusion Einstein did. No matter how I altered the strategy, the one fatal flaw kept hitting me in the face – if you play for long enough, you will lose it all.

Sure, a 99% win ratio sounds good. But, what if you win 99 times, each time winning $5. Then you lose once, and lost all $10,000 you were playing with. The wins don’t outweigh the loss. You can get that 99% VERY close to 100% (like 99.999%) by increasing the amount of cash you start with, but you can only reach 100% by having an infinite amount of initial cash. Hohum.

However… if I was a billionaire, I’d probably be ok playing roulette with a starting bet of around $10. I would accept those odds. But then… the interest I’d receive on my billion from the bank would be more than I could earn in a casino with this betting strategy.

Oh well.

I’m attaching my c++ code I used to check Roulette here. It assumes you choose one of the bets that gives you an 18/38 chance of winning each time(all red/black, even/odd, or 1-18, 19-36), doubling your bet every time you lose, and resetting the bet back to the initial ‘base bet’ each time you win.

Gambling doesn’t pay.

Code:

http://seanybob.net/codedownloads/roulette/roulette.cpp

Budget

I wrote a C++ program to keep track of how much I’m spending… With all the thinking I’ve been doing lately of Cal Poly Pomona vs. Cal State San Bernadino, this has been on my mind a lot.

It’s not optimized. It’s clear, although takes a minute or so to understand. But, for my purposes, it works. I’m adding a download link with the source code, so you can edit it to your specifications if you need something similar.

Extract all the files into the same directory.

Are there other, better ways to manage your budget? Probably.

But I needed the practice in c++ reading and writing to files, and making text file databases.

Download link:

http://seanybob.net/codedownloads/budget/

Risk: World domination?

I played risk yesterday with friends, and we got in a debate (as always) whether it’s better to attack or defend.

I’ve always thought it really didn’t matter, that the odds were so close that chance played a bigger part than any minor advantages one side had.

I decided to write a program to figure out which side (if any) has an advantage in Risk. Here are the results…

First, I ran a test doing about 100 attacks. As you can see, it varied, but it looks like attacker may have a VERY slight edge. Chance screwed everything up though, either side could easily win.

So… now for 10,000,000 attacks…

So my thoughts were basically correct. For low numbers, it really doesn’t matter. However, as you can see from the previous image, attackers do have a slight edge.

Download source code/exe:
http://seanybob.net/codedownloads/risk

Casino games: Craps odds

So I wrote a c++ program to determine the odds of winning the game of craps at a casino.

At first, I ran about 10,000 games per test. I found the overall winner to be somewhat random… sometimes the player would emerge with about 53% wins, sometimes the house would get about 54% wins.

So I stepped it up.

I ran it 10,000,000 games at a time. Finally, my results were final and unchanged. House wins (naturally, casinos couldn’t operate otherwise).

I did the 10,000,000 game test run 6 times, to make sure my results were valid. Here’s a screenie:

House won: 30,440,854 of 60,000,000 games (50.735%)

So a player has a 49.265% chance of winning.

Of course, various betting strategies alter the amount the player wins…

Interesting.

Download for source code/exe:
http://seanybob.net/codedownloads/craps