代写C++代码 代做C++程序 C++辅导 C++教学

C++网络家教 远程写代码 在线Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

Blackjack (sometimes called Twenty-One) is a popular card game at casinos.  An introduction to

the rules of the game can be found at the United States Play Card Company’s website:

http://www.bicyclecards.com/card-games/rule/blackjack

In Blackjack, suits are not important.  Each card is worth a certain number of points, and the goal

is to accumulate a point total which is higher than the dealer’s point total, without going over 21.

Most cards are worth the number of points printed on the card (for example, the Four of Clubs is

worth 4 points).  However, Jacks, Queens and Kings are worth 10 points, and Aces are worth 1

point or 11 points (player’s choice).

Blackjack (sometimes called Twenty-One) is a popular card game at casinos.  An introduction to

the rules of the game can be found at the United States Play Card Company’s website:

http://www.bicyclecards.com/card-games/rule/blackjack

In Blackjack, suits are not important.  Each card is worth a certain number of points, and the goal

is to accumulate a point total which is higher than the dealer’s point total, without going over 21.

Most cards are worth the number of points printed on the card (for example, the Four of Clubs is

worth 4 points).  However, Jacks, Queens and Kings are worth 10 points, and Aces are worth 1

point or 11 points (player’s choice).

Your program will allow the user to play a simplified version of Blackjack, with the program

serving as the dealer.  The rules of that game are given below.

Game Rules

1.  The game consists of one or more rounds, and is played between two players: the user and

the dealer (with the program serving as the dealer). A single deck of 52 cards is used and is

shuffled prior to the start of the game.

2. For each round in the game, the dealer (the program) initially deals four cards, in the

following order:  one card to the user, one card to the dealer, a second card to the user, and a

second card to the dealer.  The dealer’s second card is not visible to the user.3.  The user then plays his hand, with the goal of accumulating more points in his hand than the

points in the dealer’s hand, without going over 21.  The user must repeatedly decide to “hit”

(request another card from the deck) or “stand” (stop).  If the user’s point total is more than 21,

his hand is “busted” and automatically loses the round.

4.  If the user’s hand is not busted, the program then plays the dealer’s hand.  If the dealer’s

initial two cards total 17 or more points, he must stand; otherwise, he must hit.  The dealer must

continue to hit until his hand totals at least 17 points or he is busted.  Note:  if one of the cards in

the dealer’s hand is an Ace and counting it as 11 would bring the point total to 17 or more (but

not over 21), then that Ace must be counted as 11 points.

5.  The winner of the round is determined as follows:

a)  If the user busted, then the dealer wins the round.

b)  If the dealer busted, then the user wins the round.

c)  If neither busted, then the one with the higher point total wins the round.  If both have the

same point total, then the round is a draw (tie).

d)  If there are not enough cards remaining in the deck to complete the round,  then the round is a

draw (tie).

6.  The cards which are used during the round are discarded.

7.  The game is over when the user asks to stop at the end of a round or when the deck is empty.

Assignment Specifications

1.  You must copy the file named cards.py from the instructor’s Project09 directory into

the same directory where you develop your solution.  That file may not be modified in any way.

Your Python file (named proj09.py) must contain the following statement:

import cards

Furthermore, you may not copy the contents of cards.py into your Python file.

2. Your program may not use any global variables.  That is, any variable names used within a

function must be parameters to that function or must be created within that function (appear on

the left-hand side of an assignment operation).

3. Your program must define at least three functions (not including function “main”).

4.  When the game is over, the program will display the number of rounds won by the user, the

number of rounds won by the dealer, and the number of rounds which were draws (ties).5.  After each round, the program will ask the user if he wishes to continue the game.  A

response of “Y”, “y” or “” will indicate that the user wishes to play another round; any other

response will indicate that the user wishes to halt the game.

6.  For each round of the game, the program will deal the initial four cards (in the prescribed

order), then display the user’s cards and the dealer’s first card (but not his second card).

7.  For each step in the user’s turn within a round, the program will ask the user if he wants

another card (wants to hit).  A response of “Y”, “y”, “H”, “h” or “” will indicate that the user

wants to hit; any other response indicates that the user is going to stand.

The program will then display the cards in the user’s hand and the point total for that hand.  If

the user busted, the program will display an appropriate message.

8.  For each step in the dealer’s turn within a round, the program will display an appropriate

message (such as “dealer hits” or “dealer stands”), and then cards in the dealer’s hand and the

point total for that hand.  If the dealer busted, the program will display an appropriate message.

9.  At the end of each round, the program will display a message stating who won the round.

Assignment Notes:

1. The game rules state that the cards used during a round are not returned to the deck at the end

of that round.  That is, the deck grows smaller for each round and eventually becomes empty (if

there are enough rounds played).  Some suggestions:

a)  Start by developing a program which only plays one round.

b) Next, extend the program to play multiple rounds, but re-initialize and shuffle the deck after

every round.  That way, you don’t need to be concerned about running out of cards in the middle

of a round.

c)  Finally, extend the program to handle the complete game rules.

2.  Handling Aces as 1 or 11 is one of the more challenging part of this project, but all the

complexity can be contained in a function which calculates the value of a hand.  A suggestion:

start by developing a program which always handles Aces as a specific value, and then extend

the program to handle Aces as either 1 or 11 (whichever is better for the hand).

3.  Any hand which contains one or more Aces can have multiple values (since each Ace can be

chosen to be 1 or 11).  The value you are to display is the one that chooses Ace values (11 or 1)

so that the total hand value is as close to 21 as possible, without being greater than 21.  This

value also happens to be the value that the program must use to determine if the dealer needs to

hit or stand on a hand with value 17. A suggestion: develop a function which calculates this

maximum value.


相关推荐