//BlackJack
// Plays a simple version of the casino style game of blackjack; 1 - 7 players
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>

using namespace std;
class Card
{
public:
    enum rank {ACE = 1, TWO , THREE , FOUR , FIVE , SIX , SEVEN , EIGHT , NINE , TEN , JACK , QUEEN , KING};
    enum suit {CLUBS , DIAMONDS , HEARTS , SPADES};

    //overloading <<operator so can send the Card object to standart output friend ostream& os, const Card& aCard);

    Card(rank r= ACE, suit s = SPADES , bool ifu = true);

    //returns the value of a card , 1 - 11
    int GetValue() const;

    //flips a card; if face up, becomdes face down and vice versa
    void Flip();

private:
    rank m_Rank;
    suit m_Suit;
    bool m_IsFaceup;
};

Card::Card(rank r, suit s, bool ifu): m_Rank(r) , m_Suit(s) , m_IsFaceup(ifu)
{}

int Card::GetValue() const
{
    //if a cards is face down, its value is 0
    int value = 0;
    if (m_IsFaceup)
    {
        //value is number showing on card
        value = m_Rank;
        //value is 10 for face cards
        if (value > 10)
        {
            value = 10;
        }
    }
    return value;
}
void Card::Flip()
{
    m_IsFaceup = ! (m_IsFaceup);
}
class Hand
{
public:
    Hand();

    virtual ~Hand();

    //adds a card to the hand
    void Add(Card*pCard);

    //clears hand of all cards
    void Clear();

    //gets hand total value, intelligently treats aces as 1 or 11
    int GetTotal() const;

protected:
    vector<Card*> m_Cards;
};

Hand::Hand()
{
    m_Cards.reserve(7);
}

Hand::~Hand()
{
    Clear();
}

void Hand::Add(Card*pCard)
{
    m_Cards.push_back(pCard);
}

void Hand::Clear()
{
    //iterate through vector , freeing all memory on the heap
    vector<Card*>::iterator iter = m_Cards.begin();
    for (iter = m_Cards.begin(); iter !=m_Cards.end(); ++iter)
    {
        delete *iter;
        *iter = 0;
    }
    //clear vector of pointers
    m_Cards.clear();
}

int Hand::GetTotal() const
{
    //if no cards in hand, return 0
    if (m_Cards.empty())
    {
        return 0;
    }


    //if a first card has a value of 0, then card is face down; return 0
    if (m_Cards[0]->GetValue() == 0)
    {
        return 0;
    }

    //add up card values , treast each ace as 1
    int total = 0;
    vector<Card*>::const_iterator iter;
    for (iter = m_Cards.begin(); iter!=m_Cards.end(); ++iter)
    {
        total += (*iter) -> GetValue();
    }

    // determine if hand contains ace
    bool containsAce = false;
    for (iter = m_Cards.begin(); iter !=m_Cards.end(); ++iter)
    {
        if ((*iter)->GetValue() == Card::ACE)
        {
            containsAce = true;
        }
    }

    // if hand contains ace and total is low enough , treat ace as 11
    if (containsAce && total <=11)
    {
        //add only 10 since we've already added 1 for the ace
        total += 10;
    }

    return total;
}
class GenericPLayer: public Hand
{
    friend ostream& operator<<(ostream& os,
                               const GenericPLayer& aGenericPlayer);
public:
    GenericPLayer(const string&name = "");

    virtual ~GenericPLayer();

    //indicates whether or not generic player wants to keep hitting
    virtual bool IsHitting() const = 0;

    //returns whether generic player has busted - has a total greater than 21
    bool IsBusted() const;

    //announces that the generic player busts
    void Bust() const;

protected:
    string m_Name;
};

GenericPLayer::GenericPLayer(const string& name):
m_Name(name)

{}

GenericPLayer::~GenericPLayer()
{}

bool GenericPLayer::IsBusted()const
{
    return (GetTotal()>21);
}

void GenericPLayer::Bust() const
{
    cout << m_Name << "busts.\n";
}
class Player : public GenericPLayer
{
public:
    Player(const string& name= "");

    virtual ~Player();

    //returns whether of not the player wants another it
    virtual bool IsHitting() const;

    //annouces that the player wins
    void Win() const;

    //anouces that the player loses
    void Lose() const;

    //announces that the player pushes
    void push() const;
};
Player::Player(const string& name):
GenericPLayer(name)

{}

Player::~Player()
{}

bool Player::IsHitting() const
{
    cout << m_Name << ", do you want a hit? (Y/N): ";
    char response;
    cin >> response;
    return (response == 'y' || response == 'Y');

}
void Player::Lose() const
{
    cout << m_Name << "loses.\n";
}

void Player::push() const
{
    cout << m_Name << " pushes.\n";
}

class House : public GenericPLayer
{
public:
    House(const string& name = "House");

    virtual ~House();
    //indicates whether house is hitting - will always hit on 16 or less
    virtual bool IsHitting() const;

    //flips over first card
    void FlipFirstCard();
};
House::House(const string& name):
GenericPLayer(name)

{}

House::~House()
{}

bool House::IsHitting() const
{
    return (GetTotal() <=16);
}

void House::FlipFirstCard()
{
    if (!(m_Cards.empty()))
    {
        m_Cards[0] ->Flip();
    }
    else
    {
        cout << "No card to flip!\n";
    }
}
class Deck : public Hand
{
public:
    Deck();

    virtual ~Deck():

    //create a standard deck of 52 cards
    void Populate();

    //shuffle cards
    void Shuffle();

    //deal one card to a hand
    void Deal (Hand& aHand);

    //gives additional cards to a generic player
    void AdditionalCards(GenericPLayer& aGenericPlayer);
    };

    Deck::Deck()
    {
        m_Cards.reserve(52);
        Populate();
    }

    Deck::~Deck()
    {}

    void Deck::Populate()
    {
        Clear();
        //create standard deck
        for (int s = Card::CLUBS; s<=Card::SPADES;++s)
        {
            for(int r = Card::ACE;r<=Card::KING;++r)
            {
                Add(new Card(static_cast<Card::rank>(r),
                static_cast<Card::suit>(s)));
            }
        }
    }

    void Deck::Shuffle()

    {
        random_shuffle(m_Cards.begin(),m_Cards.end());
    }

    void Deck::Deal(Hand&aHand)
    {
        if(!m_Cards.empty())
        {
            aHand.Add(m_Cards.back());
            m_Cards.pop_back();
        }
        else
        {
            cout << "Out of cards. unable to deal.";
        }
    }

    void Deck::AdditionalCards(GenericPLayer&aGenericPlayer)
    {
        cout << endl;
        //continue to deal a card as long as generic player isnt busted and
        //wants another hit
        while (!(aGenericPlayer.IsBusted())&&aGenericPlayer.IsHitting())
        {
            Deal(aGenericPlayer);
            cout << aGenericPlayer << endl;

            if (aGenericPlayer.IsBusted())
            {
                aGenericPlayer.Bust();
            }
        }
    }

    class Game
    {
    public:
        Game(const vector<string>&names);

        ~Game();

        //plays the game of blackjack
        void play();

    private:
        Deck m_Deck;
        House m_House;
        vector<Player>m_Players;
    };

    Game::Game(const vector<string>&names)
    {
        //Create a vector of players from vector of names
        vector<string>::const_iterator pName;
        for (pName = names.begin(); pName !=names.end(); ++pName)
        {
            m_Players.push_back(Player(*pName));
        }

        //seed the random number generator
        srand(static_cast<unsigned int >(time(0)));
        m_Deck.Populate();
        m_Deck.Shuffle();
    }

    Game::~Game()
    {}

    void Game::play()
    {
        //deal intial 2 cards to everyone
        vector<Player>::iterator pPlayer;
        for (int i = 0; i <2;++i)
        {
            for (pPlayer=m_Players.begin();pPlayer!=m_Players.end();
                 ++pPlayer)
            {
                m_Deck.Deal(*pPlayer);
            }
            m_Deck.Deal(m_House);
        )

            //hide houses first card
            m_house.FlipFirstCard();

            //display everyones hand
            for(pPlayer = m_Players.begin();pPlayer!=m_Players.end();++pPlayer)
            {
                cout << *pPlayer << endl;
            }
            cout << m_House << endl;

            //deal additional cards to players
            for(pPlayer=m_Players.begin();pPlayer!=m_Players.end();++pPlayer)
            {
                m_Deck.AdditionalCards(*pPlayer);
            }

            //reveal houses first card
            m_House.FlipFirstCard();
            cout << endl << m_House;

            //deal additional cards to house
            m_Deck.AdditionalCards(m_House);

            if(m_House.IsBusted())
            {
                //everyone still playing wins
                for (pPlayer=m_Players.begin();pPlayer!=m_Players.end();
                     ++pPlayer)
                {
                    if (!(pPlayer->IsBusted()))
                    {
                        pPlayer->Win();
                    }
                }
            }
            else
            {
                //compare each player still playing to house
                for (pPlayer=m_Players.begin();pPlayer!=m_Players.end();
                     ++pPlayer)
                {
                    if ( !(pPlayer->IsBusted()))
                    {
                        if (pPlayer->GetTotal()>m_House.GetTotal())
                        {
                            pPlayer->Win();
                        }
                        else if (pPlayer->GetTotal()<m_House.GetTotal())
                        {
                            pPlayer->Lose();
                        }
                        else
                        {
                            pPlayer->push();
                        }
                    }
                }
            }

            //remove everyones cards
            for (pPlayer = m_Players.begin(); pPlayer !=m_Players.end();++pPlayer)
            {
                pPlayer->Clear();
            }
            m_House.Clear();
        }

        //function prototypes
        ostream& operator<<(ostream& os, const Card& aCard);
        ostream& operator<<(ostream& OS, const GenericPLayer& aGenericPlayer);




cout << "\t\tWelcome to BlackJack!\n\n";

int numPlayers = 0;
while (numPlayers < 1 || numPlayers>7)
    {
        cout << "How many players? 1 - 7): ";
        cin >> numPlayers;
    }

vector<string>names;
string name;
for (int i = 0; i <numPlayers;++i)
    {
        cout << "Enter player name:";
        cin >> name;
        names.push_back(name);
    }
cout << endl;

//the game loop
Game aGame(names);
char again = 'y';
while (again != 'n' && again != 'N')
    {
        aGame.Play();
        cout << "\nDo you want to play again?(Y/N):";
        cin >> again;
    }

    return 0;
}




*Im Almost Done, just a couple of errors,

/Users/Mark/Desktop/C++ Code/BlackJack/BlackJack/Black Jack 2/Black Jack 2/main.cpp:273:5: Expected '(' or '{'
/Users/Mark/Desktop/C++ Code/BlackJack/BlackJack/Black Jack 2/Black Jack 2/main.cpp:288:9: Use of undeclared identifier 'Populate'
/Users/Mark/Desktop/C++ Code/BlackJack/BlackJack/Black Jack 2/Black Jack 2/main.cpp:294:16: Out-of-line definition of 'Populate' does not match any declaration in 'Deck'
/Users/Mark/Desktop/C++ Code/BlackJack/BlackJack/Black Jack 2/Black Jack 2/main.cpp:390:9: Expected expression
/Users/Mark/Desktop/C++ Code/BlackJack/BlackJack/Black Jack 2/Black Jack 2/main.cpp:490:15: No member named 'Play' in 'Game'
/Users/Mark/Desktop/C++ Code/BlackJack/BlackJack/Black Jack 2/Black Jack 2/main.cpp:495:5: Void function 'play' should not return a value


*Im sure most of them are easy, I just cannot figure them out, Thanks for the help! 

Recommended Answers

All 15 Replies

virtual ~Deck():
Should that be a semi-colon?

 m_Deck.Deal(m_House);
)

Should that final ) be a } ?

m_house.FlipFirstCard();
Case matters.

There is more. Fix the above, see if the new errors are helpful to you.

Line 270: virtual ~Deck():

Notice anything wrong with that?

commented: That isnt an error, so there is not anything wrong with it, the : is correct instead of the ; +0

Two people independently told you about the colon at the end of that line, and your reply (in a comment on Nathan's response, no less) is that because the compiler didn't put a big neon sign on it, it must be correct?

I am genuinely astounded that you didn't even try what two people independently told you. Do any of your other function declarations finish with a colon instead of a semi-colon? Do you do that a lot?

My recomendations are:
You must write the << operators
I don't think is a good idea to Derive Deck from Hand
I recomend you to use the following hierarqui:

  Card n.........1 GroupOfCards
                    |        |
                    |        |
                  Hand      Deck
                    |
                    |
              GenericPlayer (v)
               |         |
               |         |
         (v) Player    House (v)


  Deck 1.....1 Game 1....1 House
                 1
                 .
                 .
                 n
              Players

Make the program more compact, this will help you to understand.
Don't write anything that is not strictly necessary.
Don't use pointers (new, delete).
Use the C++11 new facilities like for(auto& card : m_Card) //...

I did, try what the two others said, and it did end up working, sorry about saying that "it didnt work"

Lilgenski16: As you solved the problem and I think this could be a good example to show another style of programming, I am appending my own version (based on yours).

I think that writting a program is like writting a book, that is, there aren't a fixed number of rules that you must follow. The idea when writting a program is to express what you want in the best way for other humans comprehension.

Based on that, I like to write using the minnimum number of line codes and don´t writting things that are completly unnecesary. In this program, for example, the destructors don't need to be virtual; as a matter of fact, you don't need any destructor at all. So I deleted all the destructors. The default destructors are enough.

I would like to read others comments about the programmings style.

So, my complete alternative, written in C++11 full commented with 295 lines of code is the following:

//==================================================================== Black Jack:
//Plays a simple version of the casino blackjack game with 1 to 7 players.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>  // srand, random_shuffle
#include <ctime>      // time()

using namespace std;

//-------------------------------------------------------------------- Class Card:
class Card
{
public:
  enum rank {ACE = 1, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN,
         JACK, QUEEN, KING};
  enum suit {CLUBS, DIAMONDS, HEARTS, SPADES};

  Card(rank r, suit s): m_Rank(r), m_Suit(s) {}

  int getValue() const // returns the value of a card: 1 - 10
  {
    int value = m_Rank;        // value is number showing on card
    if(value > 10) value = 10; // value is 10 for face cards
    return value;
  }                                                         

  friend ostream& operator<<(ostream& os, const Card& card);

private:
  rank m_Rank;
  suit m_Suit;
};

ostream& operator<<(ostream& os, const Card& card)
{
  switch(card.m_Rank)           
  {
    case Card::ACE:   os << "Ace";   break;  //     Program Hierarqui     |
    case Card::TWO:   os << "Two";   break;  //                           |
    case Card::THREE: os << "Three"; break;  //        GroupOfCards       |
    case Card::FOUR:  os << "Four";  break;  //          /       \        | 
    case Card::FIVE:  os << "Five";  break;  //         /         \       | 
    case Card::SIX:   os << "Six";   break;  //        /           \      | 
    case Card::SEVEN: os << "Seven"; break;  //  (v)GenericPlayer  Deck   | 
    case Card::EIGHT: os << "Eight"; break;  //          /    \           | 
    case Card::NINE:  os << "Nine";  break;  //         /      \          | 
    case Card::TEN:   os << "Ten";   break;  //        /        \         | 
    case Card::JACK:  os << "Jack";  break;  //   (v)Player    House(v)   | 
    case Card::QUEEN: os << "Queen"; break;  //                           | 
    case Card::KING:  os << "King";  break;  //   (v):virtual             | 
  }                     

  switch(card.m_Suit)               
  {
    case Card::CLUBS:    os << " Clubs";    break;
    case Card::DIAMONDS: os << " Diamonds"; break;
    case Card::HEARTS:   os << " Hearts";   break;
    case Card::SPADES:   os << " Spades";   break;
  }

  return os;
}

//---------------------------------------------------------------- Group of Cards:
class GroupOfCards
{
public:
  GroupOfCards(int n) : m_AreFaceup(true) {m_Cards.reserve(n);}

  void addCard(Card card) {m_Cards.push_back(card);} // Adds a card to the group

  void flipCards() {m_AreFaceup = !m_AreFaceup;}

  ostream& printTo(ostream& os) const // Show only faceup cards
  {
    if(m_AreFaceup) for(auto& card : m_Cards) os << card << ", ";
    return os << m_Cards.size() << " cards";
  }

protected:
  vector<Card> m_Cards;
  bool m_AreFaceup;
};

ostream& operator<<(ostream& os, GroupOfCards& gc)
{
  return gc.printTo(os);
}

//---------------------------------------------------------- Class Generic Player:
class GenericPlayer: public GroupOfCards
{
public:
  GenericPlayer(const string& name = "") : GroupOfCards(7), m_Name(name) {}

  // Note that this is the only virtual function in this program
  virtual bool isHitting() const = 0; // Indicates if player will keep hitting

  int getTotal() const // Gets hand total value, treats aces as 1 or 11
  {
    int total = 0;
    bool containsAce = false;

    for(auto& card : m_Cards) // Add up card values, treast each ace as 1
    {                         // and determine if hand contains ace
      total += card.getValue();
      if(card.getValue() == Card::ACE) containsAce = true;
    }

    // If hand contains ace and total is low enough, treat ace as 11
    if(containsAce && total <= 11) total += 10; // Add only 10 since we've added 1

    return total;
  }

  bool isBusted() const {return (getTotal()>21);}
  void bust() const {cout << m_Name << ": busts.\n";}
  void total() const {cout<<m_Name<<":\t("<<getTotal()<<")";} // Hand total value

  ostream& printTo(ostream& os) const
  {
    os << m_Name << ": ";
    return GroupOfCards::printTo(os);
  }

protected:
    string m_Name;
};

ostream& operator<<(ostream& os, GenericPlayer& gp)
{
  return gp.printTo(os);
}

//------------------------------------------------------------------ Class Player:
class Player : public GenericPlayer
{
public:
  Player(const string& name = "") : GenericPlayer(name) {}

  virtual bool isHitting() const override // Returns if player wants another card
  {
    cout << m_Name << ", do you want a hit? (Y/N): ";
    char response;
    cin >> response;
    return (response == 'y' || response == 'Y');
  }

  void win()  const {total(); cout << " wins.\n";}
  void lose() const {total(); cout << " loses.\n";}
  void push() const {total(); cout << " pushes.\n";}
};

//------------------------------------------------------------------- Class House:
class House : public GenericPlayer
{
public:
  House(const string& name = "House") : GenericPlayer(name) {}

  virtual bool isHitting() const override {return getTotal() <= 16;}
};

//-------------------------------------------------------------------- Class Deck:
class Deck : public GroupOfCards
{
public:
  Deck() : GroupOfCards(52) // Create a shuffled standard deck of 52 cards
  {
    for(int s = Card::CLUBS; s<=Card::SPADES; ++s)
      for(int r = Card::ACE; r<=Card::KING; ++r)
    m_Cards.push_back(Card(static_cast<Card::rank>(r),
                   static_cast<Card::suit>(s)));

    srand(static_cast<unsigned int>(time(0)));     // Seed the random generator
    random_shuffle(m_Cards.begin(),m_Cards.end()); // Shuffle cards
  }

  void deal(GenericPlayer& player) // Deal one card to a player
  {
    player.addCard(m_Cards.back()); // There are enough cards for seven playes
    m_Cards.pop_back();
  }

  void additionalCards(GenericPlayer& gp) // Gives additional cards to a player
  {
    cout << endl;
    while(!gp.isBusted() && gp.isHitting())
    {
      deal(gp);
      cout << gp << endl;
      if(gp.isBusted()) gp.bust();
    }
  }
};

//-------------------------------------------------------------------- Class Game:
class Game
{
public:
  Game(const vector<string>& names)
  { // Create a vector of players froma a vector of names
    for(auto& name : names) m_Players.push_back(Player(name));
  }

  void play(); // Plays the game of blackjack

private:
  Deck m_Deck;
  House m_House;
  vector<Player> m_Players;
};

void Game::play()
{
  for(int i = 0; i<2; ++i) // Deal initial 2 cards to everyone
  {
    for(auto& player : m_Players) m_Deck.deal(player);
    m_Deck.deal(m_House);
  }

  m_House.flipCards(); // Hide house's cards

  for(auto& player : m_Players) cout << player << endl; // Display everyones hand
  cout << m_House << endl;

  for(auto& player : m_Players) m_Deck.additionalCards(player);

  m_House.flipCards(); // Reveal house's cards
  cout << endl << m_House;

  m_Deck.additionalCards(m_House); // Deal additional cards to house

  cout << endl;
  m_House.total();
  cout << endl;
  if(m_House.isBusted())
  {
    for(auto& player : m_Players)
      if(!player.isBusted()) player.win(); // Everyone still playing wins
  }
  else
  {
    for(auto& player : m_Players) // Compare each player still playing to house
    {
      if(!player.isBusted())
      {
    int playerTotal = player.getTotal();
    int houseTotal  = m_House.getTotal();

    if(playerTotal>houseTotal)        player.win();
    else if(playerTotal < houseTotal) player.lose();
    else                              player.push();
      }
    }
  }
}

//-------------------------------------------------------------------------- main:
int main ()
{
  cout << "================== Welcome to BlackJack! ==================\n\n";

  int numPlayers = 0;
  while(numPlayers < 1 || numPlayers>7)
  {
    cout << "How many players? (1 to 7): ";
    cin >> numPlayers;
  }

  vector<string> names;

  cout << endl;
  for(int i = 1; i<=numPlayers; ++i)
  {
    cout << "Enter player name " << i << ": ";
    string name;
    cin >> name;
    names.push_back(name);
  }

  char again = 'y';
  while(again != 'n' && again != 'N') // The multiple game loop
  {
    cout << "\n-------------------------------------------------- Lets go:\n";
    Game game(names);
    game.play();
    cout << "\nDo you want to play again? (Y/N): ";
    cin >> again;
  }

  return 0;
}
//=========================================================================== END.

Any comments?

i was thinking of Unicode characters for representing card suits and other text line graphics. If you want a better representation of Blackjack, i recommend SFML.

Maazu: Sure, thanks. I must admit that I don't know how to use other characters than ASCI in a system independent mode. If you can write a post with this in mind I'll appreciate.

You know Windows -> Accessories -> Char map utility? have Arial font mappings for the following extended ASCII: U+2660 ♠ , U+2665 ♥, U+2663 ♣, U+2666 ♦

test if your DOS prompt can render it with a simple 1 liner:
std::cout << std::string("\u2663") << std::endl;

Otherwise you might need PDCurses (mingw) or ncurses (Unix) library linked and execute it with MSYS 1.0, TERM = VT100 emulation. It will be alot easier if you are running Linux+GNOME Terminal or KTerm.

commented: Unfortunatley, im not on a windows machine, OSX -__ +0

Following your recomendations, the operator<< of class Card must be changed to:

ostream& operator<<(ostream& os, const Card& card)
{
  switch(card.m_Rank)           
  {
    case Card::ACE:   os << "A"; break;  //        Program Hierarchy       |
    case Card::TWO:   os << "2"; break;  //                                |
    case Card::THREE: os << "3"; break;  //             GroupOfCards       |
    case Card::FOUR:  os << "4"; break;  //               /     \          | 
    case Card::FIVE:  os << "5"; break;  //              /       \         | 
    case Card::SIX:   os << "6"; break;  //             /         \        | 
    case Card::SEVEN: os << "7"; break;  //    (v)GenericPlayer   Deck     | 
    case Card::EIGHT: os << "8"; break;  //         /       \              | 
    case Card::NINE:  os << "9"; break;  //        /         \             | 
    case Card::TEN:   os << "10";break;  //       /           \            | 
    case Card::JACK:  os << "J"; break;  // (v)Player        House(v)      | 
    case Card::QUEEN: os << "Q"; break;  //                                | 
    case Card::KING:  os << "K"; break;  // (v):virtual                    | 
  }                     

  switch(card.m_Suit)               
  {
    case Card::CLUBS:    os << "\u2663"; break;
    case Card::DIAMONDS: os << "\u2666"; break;
    case Card::HEARTS:   os << "\u2665"; break;
    case Card::SPADES:   os << "\u2660"; break;
  }

  return os;
}

With this, some play can look like:

-------------------------------------------------- Lets go:
Player a: 10♣ 4♥  (2 cards)
Player b: 5♣ 5♥  (2 cards)
Player c: J♥ Q♠  (2 cards)
House:  (2 cards)

Player a, do you want a hit? (Y/N): y
Player a: 10♣ 4♥ 3♥  (3 cards)
Player a, do you want a hit? (Y/N): n

Player b, do you want a hit? (Y/N): y
Player b: 5♣ 5♥ K♣  (3 cards)
Player b, do you want a hit? (Y/N): n

Player c, do you want a hit? (Y/N): n

House: K♦ 9♥  (2 cards)

House:  (19)
Player a:  (17) loses.
Player b:  (20) wins.
Player c:  (20) wins.

Do you want to play again? (Y/N): n

Nice, isn't it?

Yes, output looks encouraging! Now, i recommend refactoring your classes, namely "Player" class into client/server model.
How far do you plan to go with this project?

Well, this project really is from Lilgenski16. I did it completelly because I wanted to use it as an example as a programming style in the forum to be commented by everybody. My idea was to show that the original program did by Lilgenski16 is to long and dificult to undertand (in my opinion) and my solution, based on exacly the same idea, is very more compact and, I think, more easy to be undertand. Obviously all of this this is subject to debate.

Maazu: Following with this programming style open example, should be very interesting and instructive if you can show the modifications to implement your idea of client/server model. Hope you have the time to do that.

I'm sorry i cannot do that. Operating system, be it linux or windows, uses different socket types... I am sorry, i cannot do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.