Difference: Lab9 (24 vs. 25)

Revision 252018-04-03 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 9 - Blackjack

Line: 74 to 74
  JACK, QUEEN, KING };
Changed:
<
<
enum suit {
>
>
enum cSuit {
  CLUBS, DIAMONDS, HEARTS, SPADES };
Line: 82 to 82
 public: // Card Constructors Card();
Changed:
<
<
Card(cRank r, suit s);
>
>
Card(cRank r, cSuit s);
  // Get the short name of a card (1s, Kc) string CardName() const;
Line: 95 to 95
  int GetValue() const; // 1-13

private:

Changed:
<
<
cRank m_Rank; suit m_Suit;
>
>
cRank rank; cSuit suit;
 };

#endif /* CARD_H */

Line: 114 to 114
 //Constructor

Card::Card() {

Changed:
<
<
m_Rank = ACE; m_Suit = CLUBS;
>
>
rank = ACE; suit = CLUBS;
 }
Changed:
<
<
Card::Card(cRank r, suit s) { m_Rank = r; m_Suit = s;
>
>
Card::Card(cRank r, cSuit s) { rank = r; suit = s;
 }

string Card::CardName() const { const string RANKS[] = {"0", "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; const string SUITS[] = {"c", "d", "h", "s"};

Changed:
<
<
return (RANKS[m_Rank] + SUITS[m_Suit]);
>
>
return (RANKS[rank] + SUITS[suit]);
 }

string Card::CardNameLong() const {

Line: 137 to 137
  int Card::GetValue() const { //value is number showing on card
Changed:
<
<
int value = m_Rank;
>
>
int value = rank;
  //value is 10 for face cards if (value > 10) { value = 10;
Line: 150 to 152
  %CODE{"c++"}% // A class for a Hand of playing cards
Deleted:
<
<
#ifndef HAND_H #define HAND_H
 using namespace std;

class Hand {

Line: 170 to 170
  // returns true of card sum is over 21 bool isBusted();

Changed:
<
<
// return true if player has exactly 21
>
>
// return true if plyyer has exactly 21
  bool Wins();

// returns a list of current cards hand. string GetCardList();

private:

Changed:
<
<
vector m_Cards;
>
>
vector cards;
 };
Added:
>
>
 #endif /* HAND_H */ %ENDCODE%
Line: 193 to 194
 #include "Hand.h"

Hand::Hand() {

Changed:
<
<
m_Cards.reserve(7);
>
>
cards.reserve(7);
 }

void Hand::Add(Card& card) { // add a card to hand

Changed:
<
<
m_Cards.push_back(card);
>
>
cards.push_back(card);
 }

bool Hand::Wins() {

Line: 209 to 210
  void Hand::Clear() { //clear vector of cards
Changed:
<
<
m_Cards.clear();
>
>
cards.clear();
 }

string Hand::GetCardList() { string list = "";

Changed:
<
<
for (int i = 0; i < m_Cards.size(); i++) { list += m_Cards[i].CardName() + " ";
>
>
for (int i = 0; i < cards.size(); i++) { list += cards[i].CardName() + " ";
  } return list;
Line: 240 to 241
 %CODE{"c++"}% // A class for a deck of playing card
Deleted:
<
<
#ifndef DECK_H #define DECK_H
 using namespace std;

const int DECKSIZE = 52;

Added:
>
>
#ifndef DECK_H #define DECK_H
  class Deck { public:
Line: 264 to 265
  //deals one card Card Deal();
Deleted:
<
<
// Return Deck size int Size();
  // create a string list of all the cards in this deck. string GetCardList();

private:

Changed:
<
<
vector m_Cards; // Used to store a list of current cards in Deck.
>
>
vector Cards; // Used to store a list of current cards in Deck.
 };

#endif /* DECK_H */

Line: 284 to 284
 #include #include #include
Deleted:
<
<
#include <time.h> #include <stdlib.h>
 #include "Card.h" #include "Deck.h"
Line: 294 to 291
 void seedRandom() { srand(time(NULL)); }
Changed:
<
<
// random number between 0 and 51 int nextRandom() { int random = rand()%52;
>
>
double nextRandom() { double random = ((double) rand()) / RAND_MAX;
  return random; }
Line: 307 to 304
  void Deck::Clear() { //clear vector
Changed:
<
<
m_Cards.clear();
>
>
Cards.clear();
 }

void Deck::Populate() {

Changed:
<
<
Clear();
>
>
Clear(); // clear out the deck before you create a new one
 
Changed:
<
<
//create deck
>
>
//create deck by getting a copy of each card in the pool and placing it in the deck
  for (int s = CLUBS; s <= SPADES; ++s) { for (int r = ACE; r <= KING; ++r) {
Changed:
<
<
m_Cards.push_back(Card(static_cast (r), static_cast (s)));
>
>
Cards.push_back(Card(static_cast (r), static_cast (s)));
  } } }

void Deck::Shuffle() {

Changed:
<
<
// You do }

int Deck::Size() { return m_Cards.size();

>
>
// This needs to randomize the cards in the deck // you will need to use the random function to do this
 }

Card Deck::Deal() {

Changed:
<
<
// // Before dealing, check if the deck is empty, if so repopulate and shuffle, then draw.
>
>
// Pulls the top card out of the deck // and gives it to the caller // Make a special zero valued card in case we have nothing left
  Card aCard(BLANK,CLUBS);
Changed:
<
<
if (m_Cards.empty()) { aCard = m_Cards.back(); m_Cards.pop_back();
>
>
if (Cards.empty()) { aCard = Cards.back(); Cards.pop_back();
  } else { cout << "Out of cards, Unable to deal.\n"; }
Line: 343 to 339
  string Deck::GetCardList() { string list = "";
Changed:
<
<
for (int i = 0; i < m_Cards.size(); i++) { list += m_Cards[i].CardName() + " ";
>
>
for (int i = 0; i < Cards.size(); i++) { list += Cards[i].CardName() + " ";
  } return list;
Line: 349 to 345
  return list;

}

Added:
>
>
 %ENDCODE%
Changed:
<
<

main.cpp Blackjack

>
>

main Blackjack.cpp

  %CODE{"c++"}% #include
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback