The game uses two standard six-sided dice, which are shaken in a bamboo cup or bowl by a dealer. The cup is then overturned onto the floor. Players then place their wagers on whether the sum total of numbers showing on the two dice will be "Chō" (even) or "Han" (odd). The dealer then removes the cup, displaying the dice. The winners collect their money. The game was a mainstay of the bakuto, itinerant gamblers in old Japan, and is still played by the modern yakuza. In a traditional Chou-Han setting, players sit on a tatami floor. The dealer sits in the formal seiza position and is often shirtless (to prevent accusations of cheating), exposing his elaborate tattoos.
Your code must:
Ask for two to nine additional computer players until a number of players between 2 and 9 are received.
The human player (you) starts with $500.
Each bet is $50.
Each turn the human player must be asked to call Cho (even) or Han (odd) or Pass before the dice are rolled. He leaves the game if he passes. The human player must leave if he has less than $50. You can assume the player will enter only lower case, (cho,han,pass) or will lose that round.
The computer players will randomly pick Cho (even) or Han (odd).
Display the numbers on the two die, whether Cho (even) or Han (odd), whether the human player won and the total number of computer players that won, and the human players current winnings (additional amount over the initial $500)
If the human player losses subtract $50 from his current total.
If the human player wins, the total amount bet is evenly divided amongst the winning calls, and that amount is added to his current total.
this is what i have so far.
Code
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main (void)
{
int n =0, x=1,y=0;
cout << "How many players will be playing?\nPlease choose between 2-9 players:\n";
cin >> n;
while(n)
{
if ((n>=2) && (n<=9))
{
cout << "There will be " << n << " players playing.\n";
break;
}
else
{
cout << "Please insert a number between 2-9.\n";
cin >> n;
}
}
int p = n+1; //set p (players) to n+1 because it goes 0-n
double money[p]; //using double because money has two decimals
for (int i=0;i<p;i++)
{
money[i] = 500.00; //sets all the players money to 500.00
}
char option[p]; //this will be the choice players will make
int win[p]; //the money players will be winning
int pass=0;
string answer; //this will be the answer the user gives
do
{
cout << "Do you want to bet on odd or even?\nIf you want to pass, type pass but this will quit your game.\n";
cin >> answer;
char comp; //this will be set to make it easier for comparison
if (answer.compare("even")==0)
comp = 'e';
else if (answer.compare("odd")==0)
comp = 'o';
else if (answer.compare("pass")==0)
comp = 'p';
option[0]=comp;
srand(time(NULL)); //uses the clock of the computer to generate a random number every time
int dice1 = ((rand()%6) +1); //adding 1 because 0-5 and we need 1-6
int dice2 = ((rand()%6) +1); //these are the 2 random dice rolls
int add_dice = dice1 + dice2;
for (int i=0;i<p;i++)
{
cout << "Player " << i << " has $" << money[i] << ".\n";
}
for (int i=0;i<p;i++)
{
srand(time(NULL));
int num = ((rand()%2)+1);
switch(num)
{
case 1:
{
option[i+1] = 'o'; //add 1 because these are for the computer's choices
cout << "\nodd\n";
} //break;
case 2:
{
option[i+1] = 'e';
cout << "\neven\n";
} //break;
}
}
if (option[0]!='p')
for (int i=0;i<p;i++)
money[i]-=50;
else
{
cout <<"You have chosen to pass your turn, therefore ending the game.\nYour final money is " << money[0] << ".\nGoodbye!";
return 0;
}
if (option[0]!='p')
{
for (int i=1;i<p;i++)
{
switch (option[i])
{
case 'e':
{
if (add_dice%2 ==0)
win[i]=1;
else
win[i]=0;
}; break;
case 'o' :
{
if (add_dice%2 ==1)
win[i]=1;
else
win[i]=0;
}; break;
}
}
float total = 50+ n*50;
int winners=0;
for (int i=0;i<p;i++)
if (win[i]==1)
winners++;
for (int i=0;i<p;i++)
if (win[i]==1)
money[i] += (total/winners);
}
else
{
for (int i=0;i<n;i++)
{
switch (option[i+1])
{
case 'e':
{
if (add_dice%2==0)
win[i+1]=1;
else
win[i+1]=0;
} break;
case 'o':
{
if (add_dice%2==1)
win[i+1]=1;
else
win[i+1]=0;
} break;
}
}
float total = n*50;
int winners = 0;
for (int i=0;i<n;i++)
if (win[i+1]==1)
winners++;
for (int i=0;i<n;i++)
if (win[i+1]==1)
money[i+1]+=(total/winners);
}
cout << "Die rolls were " << dice1 << " and " << dice2 << ".\nThese players won:\n";
if (option[0]!='p')
for(int i=0;i<p;i++)
if (win[i]==1)
cout << i << " \n";
cout << "Your total is $" << money[0] << ".\n";
if (money[0] < 50)
{
cout << "\n\nYou have run out of money, you lose!\nGood-bye!\nThese are the final standings:\n";
for (int i=0;i<p;i++)
{
cout << "Player " << i << " has $" << money[i] << ".\n";
}
return 0;
}
} while (x);
return 0;
}
some issues i have:
if you input anything other then numbers in the first cin, it breaks -.-
at the end, all the computer players have the same amount of money
sometimes when betting, the choice of the computer (i have them couting them what their randomizing into)
any help is appreciated, thanks!