Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this C program. I sort of have an idea but I am struggling. 1.The basic rules of game A deck of

I need help with this C program. I sort of have an idea but I am struggling.

1.The basic rules of game

A deck of poker cards are used. For simplicity, we have unlimited number of cards together, so we can generate a random card at a time without considering what cards have already dealt. The game here is to play as a player against the computer (the dealer). The aim of the game is to accumulate a higher score total than the dealer, but without going over 21. The cards 2 through 10 have their face value. J, Q, and K are worth 10 points each, and the Ace is worth either 1 or 11 points (player's choice).

a) Betting and winning The player first place a bet. Lets assume our minimum bet is $10 and maximum is $1000.

b) Each hand will result in one of the following events for the player Lose - the player's bet is taken by the dealer. Win - the player wins as much as s/he bet. If s/he bet $10, s/he wins $10 from the dealer Blackjack (natural) - the player wins 1.5 times the bet. With a bet of $10, s/he wins $15 from the dealer. Push - the hand is a draw. The player keeps his/her bet, neither winning nor losing money.

c) The start of the game At the start, the player and the dealer receive two cards each. The player' cards are normally dealt face up, while the dealer has one face down (called the hole card) and one face up. The best possible blackjack hand is an opening deal of an ace with any ten-point card. This is called a "blackjack", or a natural 21, and the player holding this automatically wins unless the dealer also has a blackjack. If a player and the dealer each have a blackjack, the result is a push.

d) The players' turn The player can keep his hand as it is (stand) or take more cards from the deck (hit), one at a time, until either the player judges that the hand is strong enough to go up against the dealer's hand and stands, or until it goes over 21, in which case the player immediately loses (busts).

e) The dealer's turn The dealer turns over his hidden hole card. If the dealer has a natural 21 (blackjack) with his two cards, he won't take any more cards. If the dealer doesn't have a natural, he hits (takes more cards) or stands depending on the value of the hand. The dealer must hit if the value of the hand is lower than 17, otherwise the dealer will stand. Whether or not the dealer must hit on a soft 17 (a hand of 17 containing an Ace being counted as 11) depends on whether the dealer wins at this score. If it doesn't win, it will continue taking more cards. If the dealer goes bust, the player wins. Otherwise the player wins if s/he has a higher score, lose if s/he has a lower score, or push if s/he has the same score as the dealer. A blackjack hand beats any other hand, also those with a total value of 21 but with more cards.

f) the program towards the end If the player won or lost, s/he must decide whether to quit or to play another game unless the player runs out of money. Your program should give the player an initial betting amount of $1000.00.

g) The program If the player won or lost, s/he must decide whether to quit or to play another game unless the player runs out of money. Your program should give the player an initial betting amount of $1000.00.

2.The specific design of this project

a) The main() program and its variables You will need to decide on appropriate variables in which to store the player's bank roll (in order to keep track of how much money the player has) and other information. Lets use an integer array to store how many times the player won, lost, hit a blackjack, and got busted. This bank roll should be kept up to date on the player's current status, which means that wins should be added and losses should be subtracted from the bankroll as the user plays the game. (The program calls playing() to play a game, as discussed below. ) After each game, the program must report the result of the game, the amount of money won or lost, the current value of the bank roll, how many times the player won and lost, and how many times the player hit a blackjack or got busted. You may want to record and report how many times the dealer got busted as well. After each game, the program should allow the player to continue playing until s/he chooses to quit, or until the player runs out of money. This central program control may be done within main().

b) "Dealing" the card: dealing() function A separate dealing() function will be used to generate a card number. You will use a random number generator. The random number generator needs to be seeded with the current time at the program execution. The possible values are 1 to 13. This function will return the number generated. The return value 1 can be counted as 1 or 11 for the card's face value, and the return value 11, 12, and 13 are counted as 10 for the card's face value. Any other number is the card's face value.

c) "Playing" the game: playing() function A second function playing() will be used to play a single game until the player either wins or loses a bet, based upon the rules given above. This function should modify the current amount of the player's bank roll according to the game result, modify the array values of the player won or lost, and how many time the player hit the blackjack or bust. These values are returned through function parameters (address passing). Within the function, the player is asked whether s/he would like to place a bet. The system (dealer) then "deals the cards" (simulated by calling the function dealing(), one card at a time). After each dealing, this function should report the card values, except the dealers hole card. The function should have two variables to store the player and the dealers scores. The player can keep his hand as it is (stand) or take more cards from the deck (hit), one at a time, until either the player judges that the hand is strong enough to go up against the dealer's hand and stands, or until it goes over 21, in which case the player immediately loses the bet. The dealer turns over his hidden hole card, and starts the game process automatically until the dealer wins or loses.

d) "Ending" and "Beginning" of the game You need a separate function ending() to do the following: you should report the current value of the bank roll, how many times the player won and lost, how many times the player hit a blackjack, and how many time the player busted. You need to save the above information into a text file as well. You need a separate function beginning() to do the following at the beginning of your program in main(): the function will open the text file you used to save game information for reading if it exists, so that your game can continue from previous played results. If the file does not exist or the bank roll has a balance below the minimum bet, you start the game from scratch as usual, and report new game or continual game.

3. Additional functions may be necessary and/or appropriate, depending upon the final overall design of your program. Its your choice.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago