473,395 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Blackjack using structs...

I've found some programs of how to create a standard game of blackjack on C++. But how would you do it using structs? Here is my assignment:

Problem Statement: The purpose of this project is to create a game of Blackjack, which can be played by one player against the dealer (represented by the computer). The deck of cards is to be stored as an array of Card structures.

Blackjack is played with a deck of 52 cards, consisting of four suits (hearts, clubs, diamonds, spades), each with 13 face values (Ace, King, Queen, Jack, 10, 9, ... 2). King, Queen, Jack and 10 all have a point count of 10; the Ace may be counted as either 1 or 11 whichever gives the higher count without going over 21; the remaining cards have their face values as their point count. The objective of the game for the player is to hold a higher point count than the dealer without going over 21. Ties go to the dealer.

Playing the game proceeds as follows
1. Dealer shuffles the cards and lays them face down (that means neither the player nor the dealer can see them until cards are dealt). Cards are dealt off the top of this deck.
2. One card is dealt face down to the dealer and one to the player. The player is allowed to see the card dealt to him/her, but cannot see the card dealt to the dealer.
3. One card is dealt face up to the dealer and to the player. The player can see both these cards.
4. On each successive round, both the player and the dealer may request one more card face up. Once the player or dealer declines a card, that person cannot receive any more cards. When both the player and the dealer decide to stop, or one of them goes over 21, cards are turned up and the winner is determined as follows. The point count used for each is the highest possible without going over 21 – with an Ace counting 11 or with an Ace counting 1. In case the player goes over 21 the dealer wins. In case the dealer goes over 21 and the player does not, the player wins. If neither goes over 21, the winner is determined by the highest point count, with ties going to the dealer.
5. To keep it simple - here is how the dealer figures out when to stop asking for cards. The dealer must continue to request cards until his total is 17 or greater. An Ace in the dealer's hand is always counted as 11 if possible without the dealer going over 21

How to play the game with a computer

Design and implement a program to simulate the game of Blackjack as described above.
Make the human-computer interface as clear and user-friendly as possible.

Cards shown should be the ones the player can see. Show the cards in the form, for example, “Ace of Diamonds”, “Three of Hearts”, etc. The player (user of the program) inputs choices for the player. The dealer choices must be played your program.

Requirements:

Representing the card deck:
The deck of cards should be stored as an array of Card structures, where each struct has three members – one string giving the suit, one string giving the card name, one integer giving the face value.
So, for example, the three of Diamonds will be represented as
suit as string “Diamonds”
name as string “three”
value as int 3
And the Jack of Spades will be represented as
suit as string “Spades”
name as string “Jack”
value as int 11

Initialize the card deck array with the correct values. The first card should be an “Ace” of “Diamonds” with a value of 1, the second card should be a “Two” of “Diamonds” with a value of 2, etc.

Write at least 5 functions
Write a function to shuffle the cards. . Here’s how to shuffle the cards: Pick 2 random numbers between 0 and 51 and exchange these cards in the deck – do this at least 25 times to get the card deck well shuffled.

When the game starts, the dealer/computer shuffles the cards (by calling the shuffle function) and then deals two cards to the player and two to the computer/dealer. Use two more arrays of card structures to hold the player’s cards and the dealer’s cards.

Write a second function to get a total count of the cards in a hand,

Now the game continues until either the computer/dealer or the player decides to stop or either’s total point count goes over 21.

Write a third function to get input from you, the player. Remember to let the player see all of their own cards as well as the top card held by the dealer. The player can decide to ask for another card, or to stop asking for cards, or to stop the game.

Write a fourth function to act as the computer/dealer playing the game. A dealer can only see their own cards. When it is the dealer’s turn, they can get another card or stop asking for cards (see the strategy described in 5 above.)

When the game is over (either has a total of over 21 or the player has requested that the game stops), the winner must be determined. Write a fifth function to determine and announce the winner.

Organize the program so that the main program calls functions to do the work. Be sure to provide comments describing what each function does as well as describing what each segment of your program is doing. Your program should be organized using separate files:
1 The .h file
2 The .cpp file containing the main program
3 One or more .cpp file(s) containing the functions

Submission: Zip all files and upload the zipped file.
Nov 17 '06 #1
1 5627
r035198x
13,262 8TB
I've found some programs of how to create a standard game of blackjack on C++. But how would you do it using structs? Here is my assignment:

Problem Statement: The purpose of this project is to create a game of Blackjack, which can be played by one player against the dealer (represented by the computer). The deck of cards is to be stored as an array of Card structures.

Blackjack is played with a deck of 52 cards, consisting of four suits (hearts, clubs, diamonds, spades), each with 13 face values (Ace, King, Queen, Jack, 10, 9, ... 2). King, Queen, Jack and 10 all have a point count of 10; the Ace may be counted as either 1 or 11 whichever gives the higher count without going over 21; the remaining cards have their face values as their point count. The objective of the game for the player is to hold a higher point count than the dealer without going over 21. Ties go to the dealer.

Playing the game proceeds as follows
1. Dealer shuffles the cards and lays them face down (that means neither the player nor the dealer can see them until cards are dealt). Cards are dealt off the top of this deck.
2. One card is dealt face down to the dealer and one to the player. The player is allowed to see the card dealt to him/her, but cannot see the card dealt to the dealer.
3. One card is dealt face up to the dealer and to the player. The player can see both these cards.
4. On each successive round, both the player and the dealer may request one more card face up. Once the player or dealer declines a card, that person cannot receive any more cards. When both the player and the dealer decide to stop, or one of them goes over 21, cards are turned up and the winner is determined as follows. The point count used for each is the highest possible without going over 21 – with an Ace counting 11 or with an Ace counting 1. In case the player goes over 21 the dealer wins. In case the dealer goes over 21 and the player does not, the player wins. If neither goes over 21, the winner is determined by the highest point count, with ties going to the dealer.
5. To keep it simple - here is how the dealer figures out when to stop asking for cards. The dealer must continue to request cards until his total is 17 or greater. An Ace in the dealer's hand is always counted as 11 if possible without the dealer going over 21

How to play the game with a computer

Design and implement a program to simulate the game of Blackjack as described above.
Make the human-computer interface as clear and user-friendly as possible.

Cards shown should be the ones the player can see. Show the cards in the form, for example, “Ace of Diamonds”, “Three of Hearts”, etc. The player (user of the program) inputs choices for the player. The dealer choices must be played your program.

Requirements:

Representing the card deck:
The deck of cards should be stored as an array of Card structures, where each struct has three members – one string giving the suit, one string giving the card name, one integer giving the face value.
So, for example, the three of Diamonds will be represented as
suit as string “Diamonds”
name as string “three”
value as int 3
And the Jack of Spades will be represented as
suit as string “Spades”
name as string “Jack”
value as int 11

Initialize the card deck array with the correct values. The first card should be an “Ace” of “Diamonds” with a value of 1, the second card should be a “Two” of “Diamonds” with a value of 2, etc.

Write at least 5 functions
Write a function to shuffle the cards. . Here’s how to shuffle the cards: Pick 2 random numbers between 0 and 51 and exchange these cards in the deck – do this at least 25 times to get the card deck well shuffled.

When the game starts, the dealer/computer shuffles the cards (by calling the shuffle function) and then deals two cards to the player and two to the computer/dealer. Use two more arrays of card structures to hold the player’s cards and the dealer’s cards.

Write a second function to get a total count of the cards in a hand,

Now the game continues until either the computer/dealer or the player decides to stop or either’s total point count goes over 21.

Write a third function to get input from you, the player. Remember to let the player see all of their own cards as well as the top card held by the dealer. The player can decide to ask for another card, or to stop asking for cards, or to stop the game.

Write a fourth function to act as the computer/dealer playing the game. A dealer can only see their own cards. When it is the dealer’s turn, they can get another card or stop asking for cards (see the strategy described in 5 above.)

When the game is over (either has a total of over 21 or the player has requested that the game stops), the winner must be determined. Write a fifth function to determine and announce the winner.

Organize the program so that the main program calls functions to do the work. Be sure to provide comments describing what each function does as well as describing what each segment of your program is doing. Your program should be organized using separate files:
1 The .h file
2 The .cpp file containing the main program
3 One or more .cpp file(s) containing the functions

Submission: Zip all files and upload the zipped file.
And where exactly do you need help?
Nov 17 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Charlie Cosse | last post by:
Asymptopia BlackJack is written in Python and uses PyGame for multimedia. Version 1.2 contains both Windows and Linux install scripts. Asymptopia BlackJack is a full-featured casino-style...
3
by: slyphiad | last post by:
Here's the problem that i got... I'm trying to create a blackjack game. Here, I'm trying to create 2 blackjack games. A game with bet and without bet. So basically what i did, was create 2...
61
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
6
by: DaTurk | last post by:
Hi, I'm coding a layer into my application using CLI, between a unmanaged and a c# layer. So, I have to marshal some unmanaged c++ structures to structures usable in c#. My solution was to...
6
by: titan nyquist | last post by:
Can I step through a struct using foreach? I want a method that steps through a struct, and prints out the name/value of each member. Can it be done? The error I get when trying this is: ...
1
by: blinkrebel | last post by:
Hello I need some help implementing the game of blackjack using the xturtle package. the instructions can be found at http://katie.luther.edu/moodle/file.php/2387/BlackJack.pdf and .gif's...
7
by: devilinthebox | last post by:
I'm fairly new to java and need help with adding letters (J, Q, K, A) into the program and adding values for each. Thanks. // February 8, 2008 // The "BlackJack" class. import java.awt.*;...
30
by: imran akhtar | last post by:
i have a balckjack code, which does not seem to run, in python, it comes up with syntax error, i have try sortng it out. does not seem to work. below is my code, if anyone can work out wht wrong...
21
by: imran akhtar | last post by:
hi, i am making black jack code, but i am stuck, i have made start, but for reason gettin errors, which i dont seem be able to fix, below is my code wht i started. import random deck = *4...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.