How do I write a Roulette Code?

29 次查看(过去 30 天)
Tommy Agase
Tommy Agase 2019-4-16
回答: Rik 2019-4-16
Hi,
I want to write a code for a project where I am simulating a game of Roulette. I am having trouble writing a clean and easy code. I want to wrtie something where I play ~100 games consistently betting on Red (since you either bet on red or black)
I bet $1 on red every time and then see how much money I make from that (# of times its red out of ~ 100). So if I won I’d get +$1 and if I lose -$1 since it’s a 2:1 betting odds
Then I bet on a certain number (1-37) and I chose to consistently bet on #34. I play ~1000 games of that and see how much money I make (how many times it hits 34 when its 1-37). Every time the simulation hits the #34 I win $37 dollars since it’s a 37:1 odds.
I want to see how much money I make from the two simulations and decide which one is better (more money I win) depending on how many games I play
  3 个评论
Tommy Agase
Tommy Agase 2019-4-16
Yeah, I just did some additional research and my facts were not straight! I figured out the Red or black, Now I just need to figure out the code for consistently betting 34 each time. Im going to do EU Roulette and then just run for 35:1 odds
Walter Roberson
Walter Roberson 2019-4-16
Let 38 be used for 0 and 39 be used for 00. Then
winnings = sum(randi(39, 1, 100) == 34) * 35

请先登录,再进行评论。

回答(1 个)

Rik
Rik 2019-4-16
n_games=100;
your_number_pick=34;
Red=[1:2:9 12:2:18 19:2:27 30:2:36];
Black=[2:2:10 11:2:17 20:2:28 29:2:35];
roulette_result=randi(37,n_games,1);
isRed=ismember(roulette_result,Red);
isBlack=ismember(roulette_result,Black);
%bet on a number:
win=sum(roulette_result==your_number_pick);
expected_result__number=35*win-n_games;
%bet on a color:
win=sum(isRed);
expected_result__color=2*win-n_games;
fprintf(['expected results after %d games:\n',...
'%d for betting on 34\n%d for betting on red\n'],...
n_games,expected_result__number,expected_result__color)

类别

Help CenterFile Exchange 中查找有关 Strategy & Logic 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by