how to simulate an american roulette

6 vues (au cours des 30 derniers jours)
David
David le 23 Nov 2014
Commenté : Geoff Hayes le 24 Nov 2014
Table of roulette there are 36 numbers which vary their color there are 18 red and 18 black, and there are two green (0 to 00). If a player bets No amount of color and this falls wins the stake, but if you bet the number and this falls earn double the bet, but if it falls on 0 Green and players lose and win the house, but if it falls 00 is not won or lost only re-spin the wheel.
Pretend there are two players each begins with N amount of money, the house begins with triple the amount of the initial amounts of the players, the simulation will be made to (1-25) shots roulette player may be withdrawn at anytime wait to finish the simulation. Each player can bet: • By Color. • A specific number. • Both. They simulate roulette N times which turned must have: • That each player wagered by certain twist. • That player wins at every turn. • Final amount of each player and the house. • That probability of each player winning according to games played. • Show the graph of the plays (by rotation).
  6 commentaires
David
David le 24 Nov 2014
i have this. ideas are welcome.
clear;
clc;
jugador1=input('Dinero del jugador 1: ');
clc;
jugador2=input('Dinero del jugador 2: ');
casa=(jugador1+jugador2)*3;
cont=1;
juego=1;
ret1=0;
ret2=0;
juegos=1;
ganados1=0;
ganados2=0;
clc; for turn=1:3
switch turn
case 1
if ret1~=1;
disp('Turno del Jugador: 1');
fprintf('El jugador tiene en juego: $%i\n',jugador1)
disp('1. Apostar a un numero');
disp('2. Apostar a un color');
disp('3. Retirarse de la partida');
si1=0;
opc1=input('Que desea hacer?');
while opc1>3||opc1<1
opc1=input('Un numero valido');
end
switch opc1
case 1
numap1=input('A que numero apuesta? ');
apuesta1=input('Cuanto deseas apostar');
jugador1=jugador1-apuesta1;
si1=1;
case 2
disp('1. Rojo');
disp('2. Negro');
color1=input('A que color? (Poner el numero');
apuesta1=input('Cuanto deseas apostar? ');
jugador1=jugador1-apuesta1;
case 3
ret1=1;
disp('El jugador 1 ha salido de la partida');
end
end
clc;
case 2
if ret2~=1;
disp('Turno del Jugador: 2');
fprintf('El jugador tiene en juego: $%i\n',jugador2)
disp('1. Apostar a un numero');
disp('2. Apostar a un color');
disp('3. Retirarse de la partida');
si2=0;
opc2=input('Que desea hacer?');
while opc2>3||opc1<1
opc2=input('Un numero valido');
end
switch opc2
case 1
numap2=input('A que numero apuesta? ');
apuesta2=input('Cuanto deseas apostar');
jugador2=jugador2-apuesta2;
si2=1;
case 2
disp('1. Rojo');
disp('2. Negro');
color2=input('A que color? (Poner el numero');
apuesta2=input('Cuanto deseas apostar? ');
jugador2=jugador2-apuesta2;
case 3
ret2=1;
disp('El jugador 2 ha salido de la partida');
end
end
clc;
case 3
disp('Turno de la casa');
fprintf('La casa tiene en juego: $%i\n', casa);
fprintf('El jugador 1 ha apostado $%i\n', apuesta1);
if si1==1
fprintf('A el numero: %i\n', numap1);
else fprintf('A el color: %i\n', color1);
end
fprintf('El jugador 2 ha apostado $%i\n', apuesta2);
if si2==1
fprintf('A el numero: %i\n', numap2);
else fprintf('A el color: %i\n', color2);
end
%Probabilidades
%Calcular probabilidad de ganar basado en juegos
%anteriores.
end
end
clc;
%La ruleta gira
num=randi(38,1);
caerojo=0;
caenegro=0;
if rem(num,2)==0&&num~=38
fprintf('La ruleta cae en el numero negro: %i\n',num);
caenegro=2;
else if num<37
fprintf('La ruleta cae en el numero rojo: %i\n',num);
caerojo=1;
else if num==37
disp('La ruleta cae en 0');
else if num==38
disp('La ruleta cae en 00');
end
end
end
end
if si1==1
if num==numap1
ganar=(apuesta1+apuesta2)*2;
fprintf('El jugador 1 ha ganado %i\n', ganar);
jugador1=jugador1+ganar;
ganar=0;
end
else if color1==caenegro || color1==caerojo
ganar=apuesta1+apuesta1;
fprintf('El jugador 1 ha ganado %i\n', ganar);
jugador1=jugador1+ganar;
ganar=0;
else
casa=casa+apuesta1;
end
end
if si2==1
if num==numap2
ganar=apuesta2*2;
fprintf('El jugador 2 ha ganado %i\n', ganar);
jugador2=jugador2+ganar;
ganar=0;
end
else if color2==caenegro || color2==caerojo
ganar=apuesta2+apuesta2;
fprintf('El jugador 2 ha ganado %i\n', ganar);
jugador2=jugador2+ganar;
ganar=0;
else
casa=casa+apuesta2;
end
end
juegos=juegos+1; %Poner esto al final de todo el turno
Geoff Hayes
Geoff Hayes le 24 Nov 2014
David - so the above seems to run for one spin of the wheel only. So you probably want to put the above code in a loop that will run N times (where N can be an input parameter to your function, if you change this from a script).
You also need to add some checks in the code to ensure that the players do not bet more money than they have. Suppose the player has only 50 dollars, but attempts to bet 600. You will need to guard against this.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by