DeckOfCards.h:
struct Card{
string value;
char suit;
}; // end Card structure
class DeckOfCards
{
public:
static const int CARD_COUNT = 52;
static const int VALUE_COUNT = 13;
static const int SUIT_COUNT = 4;
DeckOfCards();
void Shuffle();
Card Deal();
friend ostream & operator<< (ostream &os, const Card &myCard);
private:
vector<Card> newDeck;
stack<Card> shuffledDeck;
void StoreInStack();
}; // end DeckOfCards class
DeckOfCards.cpp
DeckOfCards::DeckOfCards()
: newDeck(CARD_COUNT)
{
static char suit[SUIT_COUNT] = { 3, 4, 5, 6 }; // ASCII codes for card suits
static string value[VALUE_COUNT] = { "A", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "J", "Q", "K" }; // string to get the 10
// create a deck
for (int i = 0; i < CARD_COUNT; i++)
{
newDeck[i].value = value[i % VALUE_COUNT];
newDeck[i].suit = suit[i / VALUE_COUNT];
}
srand((int)time(0));
} // end constructor
void DeckOfCards::Shuffle()
{
// shuffle the vector from <algorithm>
random_shuffle(newDeck.begin(), newDeck.end());
// just as the name implies
StoreInStack();
} // end shuffle
Card DeckOfCards::Deal()
{
// top card
Card card;
card = shuffledDeck.top();
// remove from the stack and return
shuffledDeck.pop();
return card;
} // end deal
void DeckOfCards::StoreInStack()
{
for (int i = 0; i < CARD_COUNT; i++)
{
shuffledDeck.push(newDeck[i]);
}
} // end StoreInStack
ostream& operator<< (ostream& os, const Card &aCard)
{
os << (aCard.value + aCard.suit);
return os;
}
PokerHand.h
class PokerHand
{
public:
PokerHand();
void AddCard(const Card &dealtCard);
void DisplayDealtHand();
private:
list<Card> dealtHand;
}; // end PokerHand class
PokerHand.cpp
PokerHand::PokerHand()
{
}
void PokerHand::AddCard(const Card &dealtCard)
{
list<Card>::iterator pos = dealtHand.begin();
dealtHand.insert(pos, dealtCard);
} // end AddCard
void PokerHand::DisplayDealtHand()
{
if (!dealtHand.empty())
{
int count = 1;
list<Card>::iterator pos = dealtHand.begin();
while (pos != dealtHand.end() && (count < 8))
{
cout << setw(4) << (*pos);
pos++;
count++;
} // end while
} // end if
} // end DisplayDealtHand
main.cpp
int main()
{
const int MAX_HAND = 7;
DeckOfCards theDeck;
PokerHand player1;
PokerHand player2;
theDeck.Shuffle();
for (int i = 0; i < MAX_HAND; i++)
{
player1.AddCard(theDeck.Deal());
player2.AddCard(theDeck.Deal());
}
cout << "Player 1's dealt hand:";
player1.DisplayDealtHand();
cout << "\nPlayer 2's dealt hand:";
player2.DisplayDealtHand();
cout << "\n\nChoosing best hand for each player";
for (int i = 0; i < 5; i++)
{
cout << " .";
Sleep(1000);
}
cout << endl;
cout << "\n\nPlayer 1 discards:" << endl;
cout << "\t\t\tPlayer 1 plays:" << endl;
cout << "\n\nPlayer 2 discards:" << endl;
cout << "\t\t\tPlayer 2 plays:" << endl;
cout << endl << endl;
system("pause");
} // end main
Again, I'm just looking for suggestions/guidance towards evaluating a hand and implementing a fourth data structure with what I have so far.
Thanks in advance.

New Topic/Question
Reply



MultiQuote





|