MonteCarlo Simulation Roulette script/function
Show older comments
I already have a function that works for the Simulation of a Roulette and now i want to create a script to ask the Player(User) to choose a colour and his bet amount.
I tried to put the function in my script but the payout for the bet is not right, when i put the function in the script. But the function works and i get the payout.
When i choose for example red in input and 100 Euro for bet amount and i win then the payout is not right. If i win then the payout should be 200 Euro but here it is 106 and 96 Euro.
ans =
"rot"
106 96
My Script:
colour = input('Choose red,black or green ','s');
bet = input('choose bet: ','s');
while isnan(str2double(bet)) == true
bet = input('error.again please ','s');
end
disp(montecarlos(colour, bet))
function payout = montecarlos(colour, bet)
red = [3 12 7 18 9 14 1 16 5 23 30 36 27 34 25 21 19 32];
black = [26 35 28 29 22 31 20 33 24 10 8 11 13 6 17 2 4 15];
green = [38];
roulette = randi(38);
validatestring(colour,["red", "black", "green"])
if colour == "red" && any(roulette == red)
payout = 2*bet;
elseif colour == "black" && any(roulette == black)
payout = 2*bet;
elseif colour == "green" && any(roulette == green)
payout = 2*bet;
else % loose
payout = 0;
end
end
3 Comments
You should use strcmp to compare the contents of strings and chars.
Also, where exactly are you converting your bet to a numeric value?
bet='50';
payout=bet*2
Image Analyst
on 16 Feb 2021
Do not use 's' option in input():
bet = input('Specify the amount of your bet: ');
okan kolcak
on 16 Feb 2021
Answers (0)
Categories
Find more on Build and Analyze Curve Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!