stdhand.cpp

// Standard Black jack hand body
// Brandon Goldfedder

#include <assert.h>
#include "stdhand.h"
#include "display.h"

unsigned int StandardBlackJackHand::SingleCardCount(const
       Card& card, bool highCount) const
{
   unsigned int count = 0;
   if (card.IsAce())
      count += (highCount ? 11 : 1);
   else if (card.IsFaceCard() || card.CardType() == 'T')
      count += 10;
   else {
      assert (card.IsValueCard());
      count = count + card.CardType() - '0';
      }
   return count;
}

unsigned int StandardBlackJackHand::TotalCardCount(bool highCount)
     const
{
   unsigned int count = 0;
   unsigned int numAces = 0;
   std::deque<Card>::const_iterator card = hand.begin();
   while (!(card == hand.end())) {
      if ((*card).IsAce()) // Count the aces
         numAces++;
      count += SingleCardCount(*card, false); // compute low
      WAS highCount && count < 11;
      card++;
      }
   // Count one ace at the end if we are highcounting
   if (highCount && count <= 11 && numAces > 0)
      count += 10;
   return count;
}


StandardBlackJackHand::StandardBlackJackHand(Displayer* displayer):
     displayer(displayer)
{
}
StandardBlackJackHand::~StandardBlackJackHand()
{
}

void StandardBlackJackHand::AddCard(const Card& card)
{
   displayer->DrawCard(*this, card);
   hand.push_back(card);
}

void StandardBlackJackHand::Reset()
{
   displayer->Reset(*this);
   hand.erase(hand.begin(), hand.end());
}

bool StandardBlackJackHand::IsAceShowing() const
{
   return hand.back().IsAce();
}

bool StandardBlackJackHand::IsBlackJack() const
{
   return ((hand.size() == 2) && (HighCount() == 21));
}

bool StandardBlackJackHand::IsSplitable() const
{
   return ((hand.size() == 2) && (hand.front().CardType() ==
       hand.back().CardType()));
}

unsigned int StandardBlackJackHand::NumCards() const
{
   return hand.size();
}

const Card& StandardBlackJackHand::GetCard(unsigned int which) const
{
   assert (which <= hand.size());
   return hand.begin()[which];
}

unsigned int StandardBlackJackHand::LowCount() const
{
   return TotalCardCount(false);
}

unsigned int StandardBlackJackHand::HighCount() const
{
   return TotalCardCount(true);
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.101.60