1

Im trying to find all possible combos of 5 cards in a standard 52 card deck. I think I've almost got it but I'm getting stuck on one specific if statement. Im trying to figure out if an array is already in a vector, if it isn't I add it in

if (std::find(combos.begin(), combos.end(), combo) != combos.end()){
    std::cout << combos.size() << endl;
    continue;
}
std::cout << combos.size() << endl;
combos.push_back(combo);

combos is a std::vector<std::array<card, 5>> and combo is a std::array<card, 5>. I get the following error with g++

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:677:71: error: 
  invalid operands to binary expression ('const card' and 'const card')
bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}

card is a struct that looks like this

struct card {
    Suit suit;
    int rank;
};

I just don't have any idea of what to do. Thanks for any ideas

Deejpake
  • 424
  • 4
  • 11

1 Answers1

3

"Just" like the error message tells, you need to implement an equality operator for your card class.

bool operator == (const card &lhs, const card &rhs) // with or without the ref & symbol
{
    return lhs.suit == rhs.suit && lhs.rank == rhs.rank;
}

As a side issue, the number of cards is more than 2.5 millions and the algorithm run in O(n^2), so you might not see it finish in any reasonable timeframe.

Aki Suihkonen
  • 19,144
  • 1
  • 36
  • 57
  • Thanks you so much! I'll admit I dont understand the error messages much. And as to your point about time, I'm hoping to save all the hands in a csv file with their scores, then open it later to compare scores of certain hands to others. I think it will allow me to calculate win chances quicker. – Deejpake Sep 03 '18 at 05:05