Now that I really look at it, there are some interesting concerns.
First let us recognize your array, illustrated with: index:value:face(if any)
1 2 3 4 5 6 7 8 9 10 11 12 13
|
for(int i = 0; i < 13; i++) //allocates card values to array
{
cards[i][0] = i + 1;
cards[i][1] = 4;//You never use index [card][1], although assigned 4.
}
|
0:1:A
1:2:-
2:3:-
3:4:-
4:5:-
5:6:-
6:7:-
7:8:-
8:9:-
9:10:-
10:11:J
11:12:Q
12:13:K |
I've condensed your face check function to 3 comparison:
1 2 3 4 5 6 7 8 9
|
void fc_chk(int f) // checks for face cards
{
if(f==1) //case 1: is 'A';
cout<<face[3];
else if(f>10) //case 2 is {'J','Q','K'};
cout<<face[f-11]; //11-11=0(J),12-11=1(Q),13-11=2{K};
else
cout<<cards[card][0]; //Print out the regular members.
}
|
I had noticed fewer and fewer face cards as the game progress.
The result was because the below would permanently change the values within the array:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
void val_chg(int val) // changes calue of J Q K to 10
{
if(val == cards[0][0])
{
ace_chk(cards[0][0], p_total);
}
if(val == cards[10][0])
{
cards[10][0] = 10;
}
if(val == cards[11][0])
{
cards[11][0] = 10;
}
if(val == cards[12][0])
{
cards[12][0] = 10;
}
else
{
cards[card][0] = cards[card][0];
}
}
|
If first: A=11 (future J - there goes your J!<permanently>)
If second:A=1 (itself again - which is okay)
J=10 (J will never again become present - unless A creates its value!)
Q=10 (Q will never again become present)
K=10 (K will never again become present)
They will eventually all cease to be faced cards and add to the 10 pool.
A will remain itself, if the second card, or change into J.
And J,Q,K will become 10.
So all of the values will eventually become 10. |
A solution would be to not change the values of the card, but change how the cards are interpreted before being accumulated.
Or this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
//Function prototypes:
int val_chg(int); //Modified to return an integer
int ace_chk(int, int); //Modified to return an integer
//Main function: (game-loop)
int main()
{
//...Stuff...
while(playing)
{
deal(); //deals player cards
fc_chk(cards[card][0]); //checks for face cards
p_calc(val_chg(cards[card][0]));//get the values of the cards and call p_calc with its value
cout << " and ";
deal(); //deals player cards
fc_chk(cards[card][0]); //checks for face cards
p_calc(val_chg(cards[card][0]));//get the values of the cards and call p_calc with its value
cout << " which totals: " << p_total << endl;
playerbj_chk(p_total); //Check player hand for instant win!
if(playing) //if(true)
move(); //Prompt user for hit/stand options
if(playing) //if(player did not bust)
{
deal(); // deals dealer cards
fc_chk(cards[card][0]); // checks for face cards
d_calc(val_chg(cards[card][0])); //...for dealer
cout << " and ";
deal(); //deal ... for dealer
fc_chk(cards[card][0]); //check ... for dealer
d_calc(val_chg(cards[card][0])); //...for dealer
cout << " Which totals: " << d_total << endl;
dlr_chk(d_total); //algorithms for dealer hit/stand
}
winner(p_total, d_total);
playing = true;
play_again();
}
}
//Function declarations:
int val_chg(int val) // changes calue of J Q K to 10
{
if(val == cards[0][0])
{
return ace_chk(cards[0][0], p_total);//returns ace_chk's returned value.
}
else if(val>10) //J or greater!
{
return 10;//return 10 for any value greater than 10.
}
else
{
return cards[card][0];//return the cards value
}
return 0;//default
}
int ace_chk(int a, int t) // checks Ace and changes value depending on total
{
if(a == cards[0][0] && t <= 11)
{
cout << "X ";
return 11; //return 11 to the calling procedure
}
else if(a == cards[0][0] && t > 11)
{
cout << "Y ";
return 1; //returns 1 to the calling procedure
}/*
else
{
cards[card][0] = cards[card][0]; //Will never happen; already validated
}*/
return 0;//default
}
|
There can be other approaches, such as resetting the array before every deal, but the above is what I chose.
Also, when things have all setting down, you may want to rethink your 2 dimensional array.
My point is that the second index of the 2d-array is never being used; you literally don't need it unless you are planning to keep of how often cards appear ^^.
Have a good day.