Ejemplo n.º 1
0
CardSet pokerstove::canonizeToBoard(const CardSet& board, const CardSet& hand)
{
    CardSet cboard = board.canonize();
    vector<int> perms = findSuitPermutation(board, cboard);
    CardSet chand = hand.rotateSuits(perms[0],perms[1],perms[2],perms[3]);
    return chand;
}
Ejemplo n.º 2
0
CardSet CardSet::canonize(const CardSet& other) const
{
    CardSet cother = other.canonize();
    vector<int> perms = findSuitPermutation(other, cother);
    CardSet hand = *this;
    CardSet chand = hand.rotateSuits(perms[0],perms[1],perms[2],perms[3]);
    return chand;
}
Ejemplo n.º 3
0
std::set<CardSet>
expandRankSet(size_t numCards)
{
    combinations cards(52,numCards);
    do
    {
        CardSet hand;
        for (size_t i=0; i<num_cards; i++)
        {
            hand.insert (Card(cards[i]));
        }
        collection.insert(hand.canonize());
        rankHands[hand.rankstr()] = hand.rankColex();
    }
    while (cards.next());
}
Ejemplo n.º 4
0
std::set<CardSet> createCardSet(size_t numCards, Card::Grouping grouping) {
  std::set<CardSet> ret;
  combinations cards(52, numCards);
  do {
    CardSet hand;
    for (size_t i = 0; i < numCards; i++) {
      hand.insert(Card(cards[i]));
    }
    switch (grouping) {
      case Card::RANK_SUIT:
        ret.insert(hand);
        break;
      case Card::SUIT_CANONICAL:
        ret.insert(hand.canonize());
        break;
      case Card::RANK:
        ret.insert(hand.canonizeRanks());
        break;
    };

  } while (cards.next());
  return ret;
}
Ejemplo n.º 5
0
int main (int argc, char ** argv)
{
    try 
    {
        // set up the program options, handle the help case, and extract the values
        po::options_description desc("pscolex, a utility which prints all combinations\n"
                                     "of poker hands, using canonical suits, or only ranks\n");
        desc.add_options()
            ("help,?",    "produce help message")
            ("num-cards,n", po::value<size_t>()->default_value(2), "number of cards in hands")
            ("ranks",       "print the set of rank values")
            ;
      
        po::variables_map vm;
        po::store (po::command_line_parser(argc, argv)
                   .style(po::command_line_style::unix_style)
                   .options(desc)
                   .run(), vm);
        po::notify (vm);

        // check for help
        if (vm.count("help") || argc == 1)
        {
            cout << desc << endl;
            return 1;
        }

        // extract the options
        size_t num_cards = vm["num-cards"].as<size_t>();

        set<CardSet> canonicalHands;
        map<string,size_t> rankHands;
        combinations cards(52,num_cards);
        do
        {
            CardSet hand;
            for (size_t i=0; i<num_cards; i++)
            {
                hand.insert (Card(cards[i]));
            }
            canonicalHands.insert(hand.canonize());
            rankHands[hand.rankstr()] = hand.rankColex();
        }
        while (cards.next());

        if (vm.count("ranks") > 0)
        {
            for (auto it=rankHands.begin(); it != rankHands.end(); it++)
                cout << boost::format("%s: %d\n") % it->first % it->second;
        }
        else
        {
            for (auto it=canonicalHands.begin(); it != canonicalHands.end(); it++)
                cout << boost::format("%s: %d\n") % it->str() % it->colex();
        }
    }
    catch(std::exception& e) 
    {
        cerr << "-- caught exception--\n" << e.what() << "\n";
        return 1;
    }
    catch(...) 
    {
        cerr << "Exception of unknown type!\n";
        return 1;
    }
    return 0;
}