I would really appreciate the help with producing a specific type code for a bla
ID: 3628201 • Letter: I
Question
I would really appreciate the help with producing a specific type code for a blackjack game(requires):I)There is always a dealer in the game
a. At the start of the game, the dealer’s first card will not be shown or displayed. The second card will be displayed.
b. The dealer may draw additional cards.
c. The dealer must use a random-number generator to determine the maximum number of cards the dealer will draw--a value between 0 and 3. In other words, the dealer is a computer player.
d. The dealer does not show all the cards or the total until all the players have either gone bust (over 21) or hold (no more cards drawn).
There must be at least one other player (you) and up to a maximum of four other players (all played by you).
e. On a player’s turn, that player may either draw a card or hold. Once a player holds, he or she should not be asked to draw another card during this game.
f. All the cards for each player, including the first card dealt, are displayed, along with the suit symbol: spades ?, clubs ?, hearts ?, or diamonds ?.
g. Each game will start with a new, 52-card deck, which is modeled on a real deck of cards. The card deck has 52 cards with no jokers.
h. The card deck is represented by a two-dimensional array of data-type character, where the first dimension represents the suit and the second dimension represents the card in the suit, such as the following: i. char CardDeck[4][13];
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
#include <ctime>
#include <string>
using namespace std;
void deal(int ,char [4][13]);
void printcards(int,char[4][13]);
int getPlayers();
void deal1(char[][13],int);
void scoreCards(char[4][13],int[],int,int&);
void initCards(char[][13],int&,int&,bool[],int&);
bool draw(int,int);
int getwinner(int[],int);
int playagain(int);
void final(int,int,int,char[][13]);
int main ()
{char CardDeck[4][13];
int num,dealer,round;
bool playing[5];
int score[5];
int i,k, m,done,over21;
bool play=true;
srand(time(0));
//srand(5);
num=getPlayers();
while(num>=1)
{
initCards(CardDeck,round,dealer,playing,done);
deal(num,CardDeck);
printcards(num,CardDeck);
scoreCards(CardDeck,score,num,over21);
while(done<num&&over21<num+1&&round<5)
{round++;
if(round<=dealer)
deal1(CardDeck,0);
for(i=1;i<=num;i++)
if(playing[i])
if(draw(i,score[i]))
deal1(CardDeck,i);
else
{playing[i]=false;
done++;
}
printcards(num,CardDeck);
scoreCards(CardDeck,score,num,over21);
}
i=getwinner(score,num);
cout<<" GAME OVER ";
for(k=0;k<=num;k++)
final(score[k],k,i,CardDeck);
num=playagain(num);
}
system("pause");
return 0;
}
int playagain(int num)
{int a=0,i;
char again;
for(int i=1;i<=num;i++)
{cout<<"player "<<i<<" play again(y/n)? ";
cin>>again;
if(toupper(again)=='Y')
a++;
}
return a;
}
void final(int s,int n,int w ,char CardDeck[][13])
{int i,j,k;
string card[]={"2","3","4","5","6","7","8","9","10","jack","queen","king","ace"};
int code[]={4,3,5,6};
if(n==0)
cout<<"Dealers hand ";
else
cout<<"Player "<<n<<"s hand ";
for(j=0;j<4;j++)
for(k=0;k<13;k++)
if(CardDeck[j][k]==n)
cout<<(char)code[j]<<" "<<card[k]<<", ";
cout<<s<<" ";
if(n==w)
cout<<"Win! ";
else
cout<<"Lose ";
}
int getwinner(int s[],int num)
{int i,w;
for(i=0;i<=num;i++)
if(s[i]<=21)
{w=i;
i=num+3;
}
for(i=0;i<=num;i++)
if(s[i]>s[w]&&s[i]<=21)
w=i;
return w;
}
bool draw(int i,int s)
{char h;
if(s>21)
return false;
cout<<"player "<<i<<" hold or draw? ";
cin>>h;
if(toupper(h)=='H')
return false;
return true;
}
void deal1(char CardDeck[][13],int n)
{int k,l;
do
{k=rand()%13;
l=rand()%4;
}while(CardDeck[l][k]!=' ');
CardDeck[l][k]=n;
}
void scoreCards(char c[4][13],int s[],int n,int& over)
{int i,j,k,aces=0;
over=0;
for(i=0;i<=n;i++)
{aces=0;
s[i]=0;
for(j=0;j<4;j++)
for(k=0;k<13;k++)
{if(c[j][k]==i)
{if(k<9)
s[i]+=(k+2);
else if(k<12)
s[i]+=10;
else
aces++;
}
if(aces>0)
if(aces>1)
s[i]+=aces;
else
if(s[i]+11>21)
s[i]++;
else
s[i]+=11;
}
if(s[i]>21)
over++;
// cout<<i<<" "<<s[i]<<" "<<j<<" "<<k<<endl;
}
}
void initCards(char CardDeck[][13],int& round,int& dealer,bool p[],int& done)
{int i,k,m;
round=0;
done=0;
dealer=rand()%4;
for(k=0;k<4;k++)
for(m=0;m<13;m++)
CardDeck[k][m]=' ';
for(i=0;i<5;i++)
p[i]=true;
}
int getPlayers()
{int num;
cout<<"Welcome to Honest Sam's Blackjack Table ";
cout<<"Glad to have you back! ";
cout<<"Enter the number of players in the game. ";
cout<<"There must be at least one player but no more than four. ";
cout<<"Number of players: ";
cin>>num;
while(num<1||num>4)
{cout<<"invalid entry ";
cout<<"There must be at least one player but no more than four. ";
cout<<"How many players in the game (1-4)? ";
cin>>num;
}
return num;
}
void deal(int players,char CardDeck[4][13])
{int i,j,k,l;
for(i=0;i<=players;i++)
for(j=0;j<2;j++)
{do
{k=rand()%13;
l=rand()%4;
}while(CardDeck[l][k]!=' ');
CardDeck[l][k]=i;
}
}
void printcards(int players,char CardDeck[4][13])
{int i,j,k;
string card[]={"2","3","4","5","6","7","8","9","10","jack","queen","king","ace"};
int code[]={4,3,5,6};
bool d=false;
for(i=0;i<=players;i++)
{if(i==0)
cout<<"Dealers hand ";
else
cout<<"Player "<<i<<"s hand ";
for(j=0;j<4;j++)
for(k=0;k<13;k++)
if(CardDeck[j][k]==i)
if(i!=0||d)
cout<<(char)code[j]<<" "<<card[k]<<endl;
else
d=true;
}
}