I'm writing a blackjack program for class and I am having a problem with Aces, jack, queens, kings, my random number generator generates a 1, 11, 12, 13 for those cards, respectively... but Aces should be worth 11, jacks, queens, and kings, as 10, I have attatched my current code, this thing is due in a few hours, if anybody can be of any help I would appreciate it, the code is kinda messy, but not in bad shape.
DarkrShadeOfBlu 0 Newbie Poster
/* ========================================================================== */
/* PROGRAM Blackjack
AUTHOR: Douglas Smith (D.J.)
FSU MAIL NAME: djs02@garnet.acns.fsu.edu
RECITATION SECTION NUMBER: 05
RECITATION INSTRUCTOR NAME: Gabriel Logan
CGS 3408 - Spring 2005
PROJECT NUMBER: 4
DUE DATE: Friday 3/18/2005
PLATFORM: Windows XP using Microsoft Visual C++ compiler
SUMMARY
For this assignment, you will write a program which simulates a simplified version of the game Blackjack, or 21.
The game uses the following rules:
(1) There is one person who is the permanent dealer. For this simulation, assume there is only one other person in the
game, the "player." At the start of every hand the player decides how many "chips" he wants to bet on that hand.
(2) The dealer then deals out 4 cards. The 1st card goes to the player, the 2nd to the dealer, the 3rd to the player,
and the 4th to the dealer.
(3) Each card is worth a certain number of points. Cards with numbers on them (2-10) are worth their face value.
That is, a 3 is worth 3 points, a 9 worth 9 points, and so on. Jacks, Queens, and Kings are worth 10 points each. Aces are always worth 11 points. The value of a hand is simply the sum of the values of each card. Thus if you held a 6 and a Queen, your hand would be worth 16 points, A 4, a 5 and an Ace would be worth 20 points, and so on.
(4) The purpose of the game is to have a hand that is worth more points than your opponent's. However,
you may NOT exceed a total of 21 points. If you do go over 21, you lose immediately (go bust).
(5) After the initial 4 cards have been dealt, it becomes the player's turn to decide if he is satisfied with his hand.
If he believes he has enough points to win, he says "I stand". If he wishes, however, he may ask the dealer to
give him an additional card by saying, "Hit me." His score is then the sum of all 3 cards. Again he has the option
of standing or requesting still another card. The player may continue to request as many more cards as he wishes,
until he is satisfied, or until his total becomes > 21, at which point he loses instantly.
(6) If the player stands before he exceeds 21, it then becomes the dealer's turn. The dealer MUST continue to draw
cards until his total is greater than 16. (If his initial total is > 16, he stands at once). If the dealer draws a
card that brings his total above 21, the player wins. If however the dealer stands with a number in the range 17-21,
the winner is the person with the highest total. In the event of a tie, the bet is a draw and no chips are awarded.
In your program simulate a blackjack game for a total of 20 hands. Keep track of how many hands the dealer wins,
how many hands the player wins, and how many hands are ties, and print out this information at the end of each hand.
Also keep track of the total number of chips that the player has won or lost. The player determines the amount that
is bet on each hand as follows: the player bets 1 chip on the very first hand. After that, the size of his bet is
determined by how he did on the previous hand. If the player won the previous hand, he will bet 3 chips. If he tied
the previous hand, he will bet 2 chips. If he lost the previous hand, he will bet only 1 chip.
INPUT:
OUTPUT:
ASSUMPTIONS:
*/
#include <stdio.h>
void DrawCardValue (int);
void DrawCardSuit (int);
void Deal(int *, int *);
int randmax(int);
int main()
{
int playerFirst; /* =================== */
int playerSecond; /* =================== */
int dealerFirst; /* initial cards dealt */
int dealerSecond; /* =================== */
char* string = "cardSuit";
int playerWins;
int gamecount = 0;
int chipbet = 1;
int score = 0;
int pointsDealt;
/* for ( dealerPoints = 0; dealerPoints <= 16; DrawCard ) */
for(gamecount = 1; gamecount < 20; gamecount++) /* Set up BlackJack 20-round loop */
{
printf("\t--------This is round %d--------\n\n\n", gamecount);
printf("You are dealt:\n");
printf("--------------\n");
Deal(&playerFirst, &suit); /* Deal first card to player */
printf("\n");
Deal(&playerSecond, &suit); /* Deal second card to player */
pointsDealt = playerFirst + playerSecond;
printf("\n\n");
printf("Your total is %d.\n\n", pointsDealt);
printf("The dealer is dealt:\n");
printf("--------------------\n");
Deal(&dealerFirst); /* Deal first card to dealer */
printf("\n");
Deal(&dealerSecond); /* Deal second card to dealer */
printf("\n\n\n");
}
return(0);
}
/* Draw a Card, Print the value, Add necessary points to the total */
void Deal(int value, int suit)
{
int playerPoints;
int points;
int dealerPoints = 0;
char* cardSuit;
int king = 10;
int jack = 10;
int queen = 10;
int ace = 11;
int cardValue;
suit = randmax(4);
switch( suit )
{
case 1:
cardSuit = "Hearts";
break;
case 2:
cardSuit = "Clubs";
break;
case 3:
cardSuit = "Diamonds";
break;
case 4:
cardSuit = "Spades";
break;
}
/* printf("(%d)", *draw); */ /* Used to check random number when recieving bad output */
*draw = randmax(13);
switch( *draw )
{
case 1:
printf("Ace of %s", cardSuit);
cardValue = 11;
break;
case 11:
printf("Jack of %s", cardSuit);
cardValue = 10;
break;
case 12:
printf("Queen of %s", cardSuit);
cardValue = 10;
break;
case 13:
printf("King of %s", cardSuit);
cardValue = 10;
break;
default:
printf("%d of %s", *draw, cardSuit);
cardValue = 10;
break;
}
}
int randmax(int max)
/* largest possible number to return */
/* max should be restricted to the range */
/* 1 through 32767 for this function to */
/* work correctly */
/* This function computes a pseudo-random number in the range
1 through max for max > 0, and returns it to the caller. The linear
congruential algorithm is used. For more information on this
algorithm, please see an appropriate textbook.
Seed is used to control the sequence of numbers generated. A
different initial value for seed would produce a different
sequence of pseudo-random numbers.
*/
{ /* randmax */
static int seed = 2; /* determines sequence of random numbers */
/* initialized to 2 here to meet project */
/* requirements */
seed = (seed * 13077 + 6925) % 32768;
return ((int) (max * seed / 32768.0 + 1.0));
} /* randmax */
1o0oBhP 4 Posting Pro in Training
What exact problem are you having at the moment with it? If you generate random numbers 1 - 13 to generate random cards all you need to do is have a seperate fields to store the value and the ID in. Initially set ID to the random number to identify the card then modify the value to whatever you like. It seems faily black-and-white to me...
with regards to your code the value calculations seem to satisfy the above so where is the problem?
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.