Skip to content

Instantly share code, notes, and snippets.

@bumper314
Created September 19, 2015 01:33
Show Gist options
  • Save bumper314/da00311ce53d39097da8 to your computer and use it in GitHub Desktop.
Save bumper314/da00311ce53d39097da8 to your computer and use it in GitHub Desktop.
diff --git a/BlackjackGame.cpp b/BlackjackGame.cpp
index 0138fe7..ce8f36b 100644
--- a/BlackjackGame.cpp
+++ b/BlackjackGame.cpp
@@ -35,20 +35,38 @@ void BlackjackGame::add_player(Player new_player){
return;
}
void BlackjackGame::play_round(){
+ #ifdef VERBOSE
+ printf("Deal\n");
+ #endif
Dealer dealer;
dealer.set_strategy(dealer_hard, dealer_soft, dealer_split);
Hand dealer_hand(doc, 0);
dealer.hands.push_back(dealer_hand);
- #ifdef VERBOSE
- printf("dealer has: %d\n", dealer.hands[0].get_total());
- #endif
- for(int i = 0; i < players.size(); i++){
+ int i = 0;
+ for(i = 0; i < players.size(); i++){
Hand player_hand(doc, players[i].get_wager());
players[i].hands.push_back(player_hand);
+ }
+ for(int c = 0; c < 2; c++){
+ for(i = 0; i < players.size(); i++){
+ #ifdef VERBOSE
+ printf("\tplayer %d ", i+1);
+ #endif
+ players[i].hands[0].take_card(doc);
+ }
+ #ifdef VERBOSE
+ printf("\tdealer ");
+ #endif
+ dealer.hands[0].take_card(doc);
+ }
+ for(i = 0; i < players.size(); i++){
#ifdef VERBOSE
printf("player %d has: %d\n", i+1, players[i].hands[0].get_total());
#endif
}
+ #ifdef VERBOSE
+ printf("dealer has: %d\n", dealer.hands[0].get_total());
+ #endif
if(dealer.hands[0].is_blackjack()){
#ifdef VERBOSE
printf("Dealer BlackJack\n");
diff --git a/Hand.cpp b/Hand.cpp
index 848a017..df90b33 100644
--- a/Hand.cpp
+++ b/Hand.cpp
@@ -18,9 +18,9 @@ class Hand{
void set_wager();
bool split_or_not();
vector<Card> cards;
+ void take_card(DeckOfCard &doc);
bool is_blackjack();
private:
- void take_card(DeckOfCard &doc);
void check_total();
int total;
int wager;
@@ -48,8 +48,6 @@ Hand::Hand(DeckOfCard &doc, int money_to_bet){
num_of_cards = 0;
num_of_aces = 0;
num_of_aces_count_as_one = 0;
- take_card(doc);
- take_card(doc);
}
int Hand::get_total(){
return total;
@@ -92,7 +90,7 @@ void Hand::check_total(){
if(num_of_aces == 0 || num_of_aces == num_of_aces_count_as_one){
if(total > 21){
#ifdef VERBOSE
- printf("burst\n");
+ printf("bust\n");
#endif
total = 0;
}
@@ -121,7 +119,7 @@ void Hand::check_cards(DeckOfCard &doc, Card dealer_card, int num_of_hands, int
}else if(num_of_aces == 0 || num_of_aces == num_of_aces_count_as_one){
if(total > 21){
#ifdef VERBOSE
- printf("burst\n");
+ printf("bust\n");
#endif
total = 0;
}else{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment