这个程序运行良好,但像一个真正的赌场老板。我希望在不增加更多可能的情况下尽可能减少支出。我想这样做的方式是为每个数字添加概率。有8种可能性(2,3,4,5,6,7,8,9),我希望7发生最少。所以我想将概率设定为2-6,在75%(每个15%)8-9在20%(每个10%)和7在5%。有人能帮我吗?如何将概率添加到游戏中?
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;
int Random(int low, int high);
int Result(int a, int b, int c, int chips, int bet);
int main()
{
srand(time(0));
int low1(2), low2(2), low3(2);
int high1(9), high2(9), high3(9);
int menu=0;
int bet =0;
bool quit=0;
cout << "Player's chips: $1000" << endl;
int chips=1000;
while (!quit)
{
cout << "1) Play slot. 2) Exit.";
cin >> menu;
switch (menu)
{
case 1:
{
cout << "Enter your bet: ";
cin >> bet;
if (bet<=0 || bet>chips)
{
cout << "You did not enter a valid bet." << endl;
menu=1;
}
else
{
int a = Random(low1,high1);
int b = Random(low2,high2);
int c = Random(low3,high3);
cout << a << " " << b << " " << c << endl;
chips = Result(a,b,c,chips,bet);
cout << "Player's chips: $" << Result(a,b,c,chips,bet) << endl;
}
break;
}
case 2:
{
cout << "Exiting..." << endl;
quit=1;
break;
}
default:
{
cout << "Not a valid menu !"<<endl;
}
}
}
if (chips <=0)
{
cout << "You have $0 ! Game Over !" << endl;
quit=1;
}
}
int Random(int low, int high)
{
int random;
random = low + rand() % ((high+1)-low);
return random;
}
int Result(int a, int b, int c, int chips, int bet)
{
if ((a==7 && b==7 && c==7))
{
cout << "You won 10 times your bet !($" << (bet*10) << ")" << endl;
chips=chips+(bet*10);
}
if ((a==b==c) && !(a==7 && b==7 && c==7))
{
cout << "You won 5 times your bet !($" << (bet*5) << ")" << endl;
chips=chips+(bet*5);
}
if ((a==b || a==c || b==c) && !(a==b==c) && !(a==7 && b==7 && c==7))
{
chips=chips+(bet*3);
cout << "You won 3 times your bet ! ($" << (bet*3) << ")" << endl;
}
else
{
cout << "You lost your bet ! ($-" << bet << ")" << endl;
chips=chips-bet;
}
return chips;
}
'(一== b ==ç )'不会做你认为它做的事。你错误地认为C++是Python。 – rightfold 2014-11-04 21:12:45
如果你知道你想要的可能性和它们的范围,为什么不在1-100之间生成一个数字,把这个随机值赋给一个将它映射到一个结果的函数,并根据需要存储/使用该结果? – StarPilot 2014-11-04 21:14:25
你是对的,右撇子。我会改变 – Annam 2014-11-04 21:17:04