c++ - Creating and comparing two sets of cards -


how go creating hand of cards based on code below , comparing them without changing of have already? thinking how go , thinking of creating array each hand , populating each hand 5 cards. example:

int handcard[5];         //creating "hand of cards" int otherhand[5];  handcard.getacard[5];    //adding 5 cards each hand otherhand.getacard[5];  if (handcard[5] < otherhand)    //comparing hands    cout << "other hand stronger" << endl; if (handcard[5] > otherhand)    cout << "hand card stronger" << endl; else    cout << "both hands same in value" << endl; 

would work? afraid of changing code (i end messing , having recode whole thing) have done assignment asks want try comparing 2 hands. i've seen code on other sites poker , tried mimic think don't have proper functions go how other sites went this. have been trying c++ around 3-4 months not learned. if there other suggestions make code more efficient, please let me know. thank you.

here code:

#include <iostream> #include <vector> #include <algorithm> #include <string> #include <cstdlib> #include <ctime> #include <random>  using namespace std;  const int suit1(4); const int rank1(13); const string suit[suit1] = { "s", "h", "d", "c" }; const string rank[rank1] = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "j", "q", "k", "a" };  class card { friend class deck;  public: explicit card(); explicit card(int suit, int rank);  const string cardstring();  const int generate_suite(); const int generate_rank(); const int get_suite(); const int get_rank();  private: int card_suit; int card_rank; };  class deck { public: explicit deck(); const void print_deck(); void getacard(); void shuffle(); private: vector<card> cards_deck; };  int main() {    srand(time(null));     deck _deck;    cout << "****note*****" << endl;    cout << " 'c' stands club, 's' stands spade, " << endl;    cout << " 'd' stands diamond, , 'h' stands heart." << endl;     cout << endl;     cout << "after shuffling, cards are: " << endl;    _deck.shuffle();    _deck.print_deck();     cout << "your cards are: " << endl;    (int index = 0; index < 5; index++)    {        _deck.getacard();    }     cout << "the computers cards are: " << endl;    (int index1 = 0; index1 < 5; index1++)    {        _deck.getacard();    }  system("pause"); return 0; }  card::card() {    card_suit = generate_suite();    card_rank = generate_rank(); }  card::card(int suit, int rank) : card_suit(suit), card_rank(rank) {  }  const int card::generate_suite() {     return rand() % (suit1 - 1) + 0; }  const int card::generate_rank() {     return rand() % (rank1 - 1) + 0; }  const string card::cardstring() {    return suit[get_suite()] + rank[get_rank()]; }  const int card::get_suite() {    return card_suit; }  const int card::get_rank() {    return card_rank; }  deck::deck() {    (unsigned int i(0); < suit1; i++) {     (unsigned int j(0); j < rank1; j++)     {         card card(i, j);         cards_deck.push_back(card);     } } }  const void deck::print_deck() {    unsigned int count(1);     (unsigned int i(0); < cards_deck.size(); i++)    {     cout << cards_deck[i].cardstring() << " ";     if (count = 13)     {         cout << endl;         count = 0;     }     count++; } }  void deck::getacard() {    card r(cards_deck.back().get_suite(), cards_deck.back().get_rank());    cards_deck.pop_back();    cout << r.cardstring() << endl; }  void deck::shuffle() {    srand(time(null));    random_shuffle(cards_deck.begin(), cards_deck.end()); } 

so syntax little off.

int handcard[5]; 

should be:

card handcard[5]; 

also, you're getacard function need return retrieved card, instead of being void.

handcard.getacard[5] 

doesn't because handcard int. changing card doesn't anything, because card doesn't have function. and, lastly, getacard doesn't take value in. you'll need write function like:

vector<card> deck::getacard(int numcards); 

lastly, '<' , '>' symbols don't know poker hands. you'll want come function like:

int deck::comparepokerhands(vector<card> hand1, vector<card> hand2); 

that function can return -1 if hand1 winner, 1 if hand2 winner, or 0 if hands same.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -