Share/Save/Bookmark
Subscribe

Hot offers:

Your Ad Here
Jobs By Category:
.NET
Academic Writing
Access DB
Accounting
Accounting/Bookkeeping
Active Directory
Advertising
After Effects
Ajax
Algorithmic
Android
Animation
Apache
Architecture
Art & Craft
Article Rewriting
Articles
ASP
Asterisk PBX
Astroturfing
Audio Services
Audio Transcription
AutoCAD
Automotive
Banner Design
Biology
Biotechnology
Blackberry
Blog
Boonex Dolphin
BPO
Branding
Building & Architecture
Building Architecture
Bulk Marketing
Business Analysis
Business Cards
Business Plans
Buyer Sourcing
C Programming
C#
C/C++
CAD/CAM
CakePHP
Caricature / Cartoons
Cartography/Maps
Chemical Engineering
Christmas
Chrome OS
Cisco
Civil Engineering
Cloud Computing/EC2
CMS
Cocoa
Codeigniter
Cold Fusion
Computer Security
Conceptual Design
Construction Monitoring
Contracts
Copywriting
Corporate Identity
Craigslist
CRM
Cryptography
CSS
Customer Support
Data Entry
Data Processing
Dating
Delphi
Desktop Support
Django
DNS
DotNetNuke
Dreamweaver
Drupal
E-Commerce
eBay
eBooks
eCommerce
Editing
Electrical Engineering
Electronic Forms
Electronics
eMarketing
Embedded Software
Engineering
Erlang
ERP
Excel
Expression Engine
Facebook
Fashion Design
Fiction
Finance
Finance Research
Financial Markets
Finite Element Analysis
Flash
Flex
Forum Posting
Forum Software
Game Design
Genealogy
Geology
Ghostwriting
Google Analytics
Google App Engine
Google Go
Google Wave
GPGPU
Grant Writing
Graphic Design
Handheld
Handheld / PDA
Home Design Drafting
Human Resources
IIS
Illustration
Illustrator
InDesign
Industrial Design
Insurance
Interior Design
Internet Marketing
iPhone
iSeries / AS400
J2EE
Java
JavaFX
Javascript
Joomla
JSP
LaTeX
Layout / Formatting
LDAP
Leads
Legal
Legal Advice
Legal Research
Link Building
LinkBuilding
Links
Linux
Logo Design
Mac OS
MacOS
Magento
Magneto
Management
Manufacturing
Market Research
Marketing
Materials Engineering
Matlab/Mathematica
Maya
Mechanical Engineering
Mechatronics
Medical
Medical Writing
Metatrader
Microcontroller
Microsoft
MLM
MMORPG
MODx
MS Access
MS Exchange
MS Expression
MS SQL
MS Windows
mSQL
MSWindows
Multimedia
Music
MySpace
MySQL
Objective C
Oracle
Order Processing
OsCommerce
Packaging / Covers
Palm
Patents
Paypal API
PCB Layout
PDF
PeopleSoft
Perl
Perl/CGI
Phone Support
Photo
Photo Editing
Photography
Photoshop
PHP
PLA / SCADA
PostgreSQL
Powerpoint
Print
Printing
Product Descriptions
Product Sourcing
Programming
Project Management
Project Scheduling
Proofreading
Protoshare
PSD Coding
PSD to HTML
PSD2CMS
Publishing
Python
Quantum
Quantum Computing/Physics
QuarkXPress
Quickbooks/Quicken/MYOB
REALbasic
Recruiting
Rendering/3D
Report Writing
Research
Reviews
Ruby/Ruby on Rails
Sales
SAP
Scientific Research
Script Install
Script Installation
Search Engine Optimization
Second Life / Virtual Worlds
Security
SEM / Adwords
SEO
Sharepoint
Shell Script
Shopping Carts
Silverlight
Social Networking
SocialEngine
Software Architecture
Software Testing
Solidworks
Sports
SQL
Stationery Design
Statistical Analysis
Structural Engineering
Supplier Sourcing
Support
Symbian
System Admin.
System Administration
Tax
Technical Support
Technical Writing
Telemarketing
Templates
Test Automation
Testing / QA
Training
Transcription
Translation
Travel Writing
Troubleshooting
Tutoring
Tutoring / Education
Twitter
Typography
UML Design
User Interface / IA
vBulletin
Verilog / VHDL
Video Services
Video Uploading
Virtual Assistant
Virtual Reality
Visual Basic
Voice Talent
VoIP
Volusion
Web Promotion
Web Scraping
Web Search
Website Design
Website QA
Website Security
Weddings
Windows
Windows Mobile
Wireless
Word
Wordpress
Writing
XHTML
XML
XXX
YouTube
Zen Cart
Zend


Your Ad Here

Black Jack C++ Help


Your Ad Here

Required knowledge: C/C++






Background

For this assignment, you complete a program to play the game of "Twenty-one" (also called "Blackjack").

The general idea of Twenty-one is as follows. There are two players, the customer and the dealer. The dealer deals a card face down to the customer, then a card face up to herself (the up-card), then another card to the customer and another card to herself, both face down. In most cases, the customer may then ask for more cards, one at a time. The dealer does the same, and the hand is resolved. The object of the game is to be dealt a set of cards whose total value is as close to 21 as possible without going over.

Cards are dealt from a deck of 52. There are four cards in the deck with value 2, four with value 3, and so on up to value 9; there are sixteen cards with value 10 (four 10's and twelve face cards: four jacks, four queens, and four kings); and there are four cards ("aces") whose value may be either 1 or 11 depending on the value of a player's remaining cards. For both players, an ace counts 11 unless the hand total is more than 21, in which case it counts 1.

For our purposes, the actual play of the game proceeds as follows. Each player receives two cards as described above. If the dealer's cards total 21—that is, one has value 10 and the other is an ace—the dealer has a "blackjack" and wins the hand. Otherwise, if the customer's cards total 21, she has a blackjack and wins the hand. Otherwise, the customer may ask for more cards one by one, until either she goes over 21—in which case she loses, or "busts"—or has a total that she thinks is high enough to beat the dealer. After the customer has stopped with a total at most 21, the dealer draws, taking another card if her total is 16 or less, and stopping if her total is over 16. If the dealer busts, she loses. If neither player has bust, the totals of the two sets of cards are compared. If the customer's is higher, she wins; otherwise, the dealer wins.

Productive strategies in Twenty-one involve taking account of the dealer's up-card. For instance, it will be easier for the dealer to win if her up-card is an ace or a face card.
Examples

Some annotated sample hands are shown below. Only the values of the cards are listed, except for aces.
Customer hand = 10 ace
Dealer hand = ace 10
Dealer has blackjack and wins immediately, even though the customer also has blackjack.
Customer hand = 10 ace
Dealer hand = 4 9
Customer has blackjack and wins immediately.
Customer hand = 4 ace
Dealer hand = 4 9
Customer continues, and is dealt a 7; her hand now totals 12.
Customer continues, and is dealt a 10; dealer wins.
Customer hand = 4 ace
Dealer hand = 4 9
Customer continues, and is dealt a 7; her hand now totals 12.
Customer continues, and is dealt an ace; her hand now totals 13.
Customer continues, and is dealt a 5; her hand now totals 18.
Dealer draws a 10 and loses.
Customer hand = 4 ace
Dealer hand = 4 9
Customer continues, and is dealt a 7; her hand now totals 12.
Customer continues, and is dealt an ace; her hand now totals 13.
Customer continues, and is dealt a 5; her hand now totals 18.
Dealer's total is less than 17, so she continues, drawing a 3; her hand now totals 16.
Dealer's total is less than 17, so she continues, drawing an ace; her hand now totals 17.
Dealer must stand. Customer has more than dealer, so customer wins.
Customer hand = 4 ace
Dealer hand = 4 9
Customer continues, and is dealt a 3; her hand now totals 18.
Dealer's total is less than 17, so she continues, drawing a 3; her hand now totals 16.
Dealer's total is less than 17, so she continues, drawing a 5; her hand now totals 21.
Dealer must stand. Dealer has more than customer, so dealer wins.
Problem

Complete the program in the file ~cs9f/lib/blackjack.cpp to play games of Twenty-one. The program begins each game by calling the DealFirstFourCards function, which initializes the customer and dealer hands as described above. After checking for blackjacks, it calls the ResultOfPlay function to play the game. You supply the code for these two functions. Don't change any of the code that's provided in the file.

The program uses two classes, declared in ~cs9f/lib/hands.h, to represent the dealer and customer hands; you are also to provide two versions of a file hands.cpp that correctly implements the operations of these classes. These versions will differ only in the CanDraw member function of the CustomerHand class. The idea is to to test two strategies for the customer, namely the dealer's strategy—draw to a total of 16 or under—and the following alternative:

Take a card if and only if your hand total is less than 17 and the dealer's up card is a 7, 8, 9, 10, or ace, or if your hand total is less than 12 and the dealer's up card is a 2, 3, 4, 5, or 6. (The idea is that in the second case, the dealer is much more likely to bust since there are more 10's than any other card.)

Your program will play fifty games of Twenty-one with each strategy and report how many games were won by dealer and customer in each run. A blackjack should count as two wins.
System information

Your program will include calls to member functions of Deck and Card classes that we supply in the file ~cs9f/lib/cards.h. The Deck constructor may be given a boolean argument that says whether or not to produce debugging output when the deck is shuffled or a card is drawn; the code in blackjack.cpp enables this deck option. One of the functions, Shuffle, should be called at the start of each game; another, Deal, should be called to deal a card from the deck. The Value and IsAce functions will help in evaluating a hand. The Name function should be used when Printing/">printing a hand, for instance as follows:

cout << card.Name ();

The file cards.cpp is available in ~cs9f/lib for inclusion in the executable version of your program. (The techniques it uses won't be covered in CS 9F until the "Vectors" segment.) A command to create an executable version of the program might then be

g++ -Wall -g blackjack.cpp hands.cpp ~cs9f/lib/cards.cpp

You can abbreviate this command using the make program described later in this document; a "make file" for this assignment is available in ~cs9f/lib/p2b.makefile. You may also download this file in case you're using a C++ environment on some other computer.
Miscellaneous requirements

You do not need to store the individual cards in the hands (that requires an array). You only need to maintain each hand's point total.

You should test the member functions of the ...Hand classes in isolation, using appropriate test data, to see if they work independently before calling them from the program in blackjack.cpp. Tutors may ask to see the results of these tests. Tests should also include whatever other values are necessary to ensure that all statements in your program have been executed at least once. Be sure to check that your output makes sense, since the output is what most tutors will check first. Students are sometimes embarrassed to have a tutor point out that their programs have the customer never drawing a card, or always valuing an ace as 1.

Some other useful tests involve the possibilities for valuing an ace. Test your program on the following situations:
a hand containing a single ace whose final value is 11;
a hand containing a single ace that initially is valued at 11, but whose value must change to 1 because of subsequently drawn cards;
a hand containing a single ace that initially is valued at 1;
a hand containing more than one ace, one of which has a final value of 11;
a hand containing more than one ace, the first of which initially is valued at 11 but whose value much change to 1 because of subsequently drawn cards;
a hand containing more than one ace, all of which have initial values of 1.

Your program runs must also provide enough evidence that your simulation is accurate: that hands are dealt and evaluated correctly, and that the rules and strategies described above are correctly implemented. Include in your program sufficient output for the tutor to be able to verify its correctness quickly. (One way to improve the readability of your output is to indent the intermediate output and not to indent the result of each game. For instance:

Dealing 9 of spades
Dealing 9 of clubs
Dealing 4 of hearts
Dealing 5 of clubs
Customer hand: 2 cards, 0 aces counting 11, 18 total.
Dealer hand: 2 cards, 0 aces counting 11, up card = 9 of clubs, total = 9

Customer stands.
Dealing 3 of spades
Dealing 3 of hearts
Dealing 9 of hearts
WIN: Dealer bust with 24

Your output should include examples of each case of the dealer's strategy, as well as the customer's strategy as displayed in the following table:
your total dealer's up card your total dealer's up card
< 17 7, 8, 9, 10, A < 12 2 through 6
= 17 7, 8, 9, 10, A = 12 2 through 6
> 17 7, 8, 9, 10, A > 12 2 through 6
< 17 2 through 6 < 12 7, 8, 9, 10, A
= 17 2 through 6 = 12 7, 8, 9, 10, A
> 17 2 through 6 > 12 7, 8, 9, 10, A

It is probably easier to provide this output by constructing cards by hand using the ChangeCard function rather than relying on a shuffled deck to produce the right numbers.

Your code should call ...Hand member functions where appropriate; code in blackjack.cpp should not duplicate their functionality. You should not change the public interface of the ...Hand classes; you may, however, provide additional private member functions. (Don't forget to provide the function prototypes for any functions you provide.) Your program should also adhere to standards described in the section "Style guidelines" of this document. You don't need arrays to solve this problem
Checklist

Correctly working code:

completion of blackjack.cpp without duplicating functionality in ...Hand member functions;
completion of two versions of hands.cpp (one for each player strategy mentioned in the assignment), without adding any public member functions to the ...Hand classes.

Sufficient testing, with output sufficient to verify test correctness:

tests on specified strategy situations;
tests of hands that include aces as specified;
evidence of independent tests of all functions in hands.cpp;
tests sufficient to exercise all statements in the program.

Printed listings of program text, tests, and test results.
Adherence to CS 9F style standards:

appropriate use of indenting and white space;
avoidance of "forbidden C++"
variable and function names that reflect their use;
informative comments at the head of each function;
no routine more than twenty-four lines of code.

Clean case analysis and simple loop structuring.
Suitable input prompts and informative output, including at least the final result of each game and the total number of wins for a given strategy.

blackjack.cpp framework

#include <iostream>
using namespace std;

#include "cards.h"
#include "hands.h"

// You complete this function, which takes two hands and a deck as arguments.

// It returns the result of dealing two cards each to the dealer hand and
// the customer hand arguments. The first card in the deck argument goes
// to the customer, the second to the dealer, the third to the customer, and the fourth to

// the dealer. DealFirstFourCards should also print appropriate debugging output.
void DealFirstFourCards ( ... [you fill this in] ) {
... [you fill this in]
}

// You complete this function, which takes two hands and a deck as arguments.

// On entry, each hand has already been dealt two cards, and neither hand has
// a blackjack (a total of 21). ResultOfPlay returns the result of playing the hand.
// First, the customer draws cards until he/she either goes past 21 (a "bust")

// or reaches a suitable total less than or equal to 21. If the customer has not bust,
// then the dealer draws cards until reaching a total of 17 or more.
// ResultOfPlay returns 0 if the customer busts or if the customer's total is

// less than or equal to the dealer's and the dealer hasn't bust.
// ResultOfPlay returns 1 if the dealer busts or if the customer's total
// exceeds the dealer's and the customer has not bust.

// ResultOfPlay should also print appropriate debugging output.
int ResultOfPlay ( ... [you fill this in] ) {
... [you fill this in]
}
int main () {
Deck d(true);
int numGames, numWins;
DealerHand dealerHand;

CustomerHand ourHand;
cout << "How many games? ";
cin >> numGames;
numWins = 0;
for (int k=1; k<=numGames; k++) {
DealFirstFourCards (dealerHand, ourHand, d);
if (dealerHand.Total()==21) {

cout << "LOSS: Dealer has blackjack" << endl;
} else if (ourHand.Total()==21) {
numWins += 2;
cout << "WIN: We have blackjack" << endl;
} else {
numWins += ResultOfPlay (dealerHand, ourHand, d);

}
}
cout << "We won " << numWins << " out of " << numGames << endl;
return 0;
}

cards.h

#ifndef _CARDS
#define _CARDS
#include <iostream>
#include <vector>
#include <string>

class Card {
public:
// Construct a card initialized to the ace of clubs.

Card ();

// Change the card to the nth card in the sequence
// ace of clubs, 2 of diamonds, 3 of hearts, 4 of spades,
// 5 of clubs, ..., queen of spades,
// king of clubs, ace of diamonds, 2 of hearts, 3 of spades,

// 4 of clubs, ..., jack of spades,
// queen of clubs, king of diamonds, ace of hearts, 2 of
// spades, etc.
void ChangeCard (int n);

// Return the card's value in blackjack: 11 if it's an ace,

// 10 if it's a face card (king, queen, or jack), and the
// card's face value (2, 3, ..., or 10) otherwise.
int Value ();

// Return the name of the card.
string Name ();

// Return true if the card is an ace, and return false

// otherwise.
bool IsAce ();

// Return true if the card is a face card (king, queen, or
// jack), and return false otherwise.
bool IsFaceCard ();

// Return true if the card outranks the argument card.

// One card outranks another if it has a higher value.
// Any face card outranks a 10; a king outranks a queen or
// jack; and a queen outranks a jack.
bool Outranks (Card c);

// Return true if the card and the argument card are equal

// in value.
bool EqualsInRank (Card c);

// Return true if the card and the argument card are the
// same suit.
bool IsSameSuit (Card c);

private:
int myRank;
int mySuit;
};


class Deck {
public:
// Construct a deck of 52 cards.
// If a true argument is given, it causes debugging output
// to be printed to cerr every time a card is dealt or the deck
// shuffled.
Deck (bool debug=false);


// Shuffle the deck, i.e. randomly permute its cards.
void Shuffle ();

// Print the contents of the deck.
void Print (ostream &output);

// Return the top card of the deck, and remove that card from

// the deck. If the deck is empty, first shuffle the already-
// dealt cards and deal from them.
Card Deal ();

// Return true if the deck is empty and false otherwise.
bool IsEmpty ();

private:

vector <Card> myCards;
int myTop;
bool debugging;
};
#endif

hands.h

#ifndef _HANDS
#define _HANDS
#include "cards.h"

class DealerHand {
public:
// Construct an empty hand for the dealer.
DealerHand ();
// Reinitialize the hand to contain no cards.

void Reset ();
// Add the given card to the hand.
void AddCard (Card c);
// Return true if, according to the dealer's strategy, another
// card should be drawn. (The dealer's strategy is to draw a

// card when his/her total is less than or equal to 16.)
bool CanDraw ();
// Return the dealer's "up card" (the first card dealt to the
// dealer at the start of each game).
Card UpCard ();

// Return the dealer's total hand value.
int Total ();
// Print available information about the hand.
void Print ();
private:
Card myUpCard;
int myCardCount;
int myAceAs11Count;
int myTotal;

};

class CustomerHand {
public:
// Construct an empty hand for the customer.
CustomerHand ();

// Reinitialize the hand to contain no cards.
void Reset ();

// Add the given card to the hand.

void AddCard (Card c);

// Return true if, according to the player's strategy, another
// card should be drawn.
bool CanDraw (Card dealerUpCard);

// Return the total hand value.
int Total ();


// Print available information about the hand.
void Print ();

private:
int myCardCount;
int myAceAs11Count;
int myTotal;
};
#endif





Latest Related projects:

Title Bids Avg
Black jack game graphics   0 n/a
C++ help to build audio utility (BPM detection and MP3 tagging) by pland 0 n/a
Casino Site w/ Games   0 n/a
Java assignment help 1 $ 100
100 articles for casino site, delivered into wordpress   4 $ 519
FULL CASINO WEBSITE W/ GAMES   0 n/a
Need Full Casino Website 0 n/a
Full Casino Site Needed 0 n/a
Distributed Enterprise System -.NET, Server/Client, MYSQL   30 $ 2952
new flash game required   0 n/a
social and couple of game!   0 n/a
C Help 0 n/a
Poker for Money by jhriss 0 n/a
TEACHME2GAMBLE.COM by duraidhallak 0 n/a
CakePHP and Web Design   1 $ 2000
Gambling translation - German into French   2 $ 60
Casino Gambling Program Texas Hold-em in FLASH or JAVA   2 $ 25500
Flash Game Maker 0 n/a
New Isacco website with multipoint A/V conferencing virtual   0 n/a
Casino Server Software Package   0 n/a
Need Online Gaming website   0 n/a
NEW BETTING WEBSITE   0 n/a
Article writers wanted   2 $ 30
Raffling Website/stylish 0 n/a
Online casino software working with vouchers   1 n/a
Ad Words Professional Needed For Adult Product Site 2   2 $ 225
Ad Words Professional Needed For Adult Product Site   7 n/a
multiplayer game developer team required for 6 game   0 n/a
multiplayer game developer team required   0 n/a
Custom Home Multiplayer Blackjack Software Wanted   0 n/a

Post your own project on getafreelancer Search for scimilar work on getafreelancer
Post your own project on scriptlance Search for scimilar work on scriptlance
Post your own project on eufreelance Search for scimilar work on eufreelance

Post and Bid on projects! Join EUFreelance.com for free!

Get custom programming done at GetAFreelancer.com!




Currently viewed: "Black Jack C++ Help"