title: Help With Small C++ Game
body: <p>I'm writing a game of solitaire that runs in the terminal. As of now, the program compiles and runs and gives the player four cards, placed in four columns and allows them to press 0 for more cards, which are added onto the columns. As the column grows, it's output should be placed in a vector (actually, a vector of vectors).</p>
  
  <p>Ideally, after gathering more cards if necessary, the player inputs a number ranging from 1-4 to select the column they'd like to compare to the others. It should then compare the top card of that column to the other top cards and see if one can be deleted. This is the part that I'm having trouble with. First of all, I'm not sure if I'm inputing the cards correctly into the vector of vectors and I'm not sure how to compare them to each other. I've tried using something like:</p>
  
  <p><code>column[2].back().getSuit()</code> to acces the suit of the top card of column two, then giving it a numerical value and comparing it to the suit of the other.
  I did a similar thing to compare the ranks of the cards but I'm not having any luck.</p>
  
  <p>Can anyone show me an example using my or your own code?
  How should I properly compare the suit and rank of the top cards in each column?</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  enum suits 
  {
      diamond, club, heart, spade
  };
  
  class Card
  {
  private:
      int rank;
      suits suit;
  public:
      Card();
      Card(suits, int);
      int getRank() { return rank; }
      suits getSuit() { return suit; }
      void setRank(int rankvalue) { rank = rankvalue; }
      void setSuit(suits suitvalue) { suit = suitvalue; }
  };
  
  ostream &amp; operator&lt;&lt;(ostream &amp;, Card);
  
  Card::Card()
  {
      rank = 1;
      suit = spade;
  }
  
  Card::Card(suits suitvalue, int rankvalue)
  {
      rank = rankvalue;
      suit = suitvalue;
  }
  
  ostream &amp; operator&lt;&lt;(ostream &amp; out, Card aCard)
  {
      switch (int rank = aCard.getRank())
      {
          case 14: out &lt;&lt; "Ace"; break;
          case 11: out &lt;&lt; "Jack"; break;
          case 12: out &lt;&lt; "Queen"; break;
          case 13: out &lt;&lt; "King"; break;
          default: out &lt;&lt; rank;
      }
  
      switch (suits suit = aCard.getSuit())
      {
          case diamond: out &lt;&lt; " of Diamonds"; break;
          case spade: out &lt;&lt; " of Spades"; break;
          case heart: out &lt;&lt; " of Hearts"; break;
          case club: out &lt;&lt; " of Clubs"; break;
      }
  
      return out;
  }
  
  class RandomInteger 
  {
  public: 
      RandomInteger();
      unsigned int operator() (unsigned int max);
  };
  
  RandomInteger::RandomInteger()
  {
      srand(time(0));
  }
  
  unsigned int RandomInteger::operator()(unsigned int max)
  
  {
      unsigned int rval = rand();
      return rval % max;
  }
  
  RandomInteger randomizer;
  
  class Deck
  {
      Card cards[52];
      int topCard;
  public:
      Deck();
      void shuffle();
      bool isEmpty() { return topCard &lt;= 0; }
      Card draw();
  };
  
  extern RandomInteger randomizer;
  
  Deck::Deck()
  {
      topCard = 0;
      for (int i = 1; i &lt;= 13; i++)
      {
          Card c1(diamond, i), c2(spade, i), c3(heart, i), c4(club, i);
          cards[topCard++] = c1;
          cards[topCard++] = c2;
          cards[topCard++] = c3;
          cards[topCard++] = c4;
      }
  }
  
  Card Deck::draw()
  {
      if (!isEmpty())
          return cards[--topCard];
      else
      {
          Card spadeAce(spade, 1);
          return spadeAce;
      }
  }
  
  void Deck::shuffle()
  {
      random_shuffle(cards, cards+52, randomizer);
  }
  
  class Player
  {
  public:
      Player();
      void print();
      Card draw(Deck &amp;);
      typedef vector&lt;Card&gt; cards;
      vector&lt;cards&gt; column;
  };
  
  //ostream &amp; operator&lt;&lt;(ostream &amp;, Player&amp;);
  
  Player::Player()
  {
      column.push_back(vector&lt;Card&gt;());
      column.push_back(vector&lt;Card&gt;());
      column.push_back(vector&lt;Card&gt;());
      column.push_back(vector&lt;Card&gt;());
  }
  
  Card Player::draw(Deck &amp; aDeck)
  {
      for (int i = 0; i &lt; 4; i++)
          column[i].push_back(aDeck.draw());
  }
  
  void Player::print()
  {
      cout &lt;&lt; "Col 1 \t\t Col 2 \t\t Col 3 \t\t Col 4 \n";
      bool more = true;
      for (int j = 0; more; j++)
      {
          more = false;
          for (int i = 0; i &lt; 4; i++)
              if (j &lt; column[i].size())
          {
          cout &lt;&lt; column[i][j] &lt;&lt; "\t";
          more = true;
          }
              else
              cout &lt;&lt; "\t\t";
      cout &lt;&lt; endl;
      }
  }
  
  int main()
  {
      Deck deck;
      deck.shuffle();
  
      Player player;
      player.draw(deck);
      //while (!deck.isEmpty())
      //{
      cout &lt;&lt; "Enter a column number (0 to draw four new cards): " &lt;&lt; endl;
      //}
      player.print();
  
      int input;
      int i;
      vector&lt;vector&lt;Card&gt; &gt; columns(4);
      while (cin &gt;&gt; input)
      if (input == 0 )
      {
          player.draw(deck);
          player.print();
          columns.push_back(vector&lt;Card&gt;());
          columns.push_back(vector&lt;Card&gt;());
      columns.push_back(vector&lt;Card&gt;());
          columns.push_back(vector&lt;Card&gt;());
      }
          else while (cin &gt;&gt; input)
              if (input == 1)
              {
              for ( i = 0; i &gt; 4; i++)
                  {
                          columns.push_back(vector&lt;Card&gt;());
              }
              for ( i = 0; i &gt; 4; i++)
                      {
                      columns[0].back().getSuit();
                  columns[1].back().getSuit();
                  columns[2].back().getSuit();
                  columns[3].back().getSuit();
              }
  
              }
  
  
  
  }
  </code></pre>
  
  <p>Any suggestions, pointers, tips, are great, thanks.</p>