CardSet PokerHand::cardSet () const { CardSet cs; for (uint8_t i=0; i<_ncards; i++) cs.insert (Card(_cards[i])); return cs; }
bool Engine::setDeck(const Deck &deck) { if (mDeck) { // already set return false; } if (deck.empty()) { // nothing to do with empty card set return false; } if (mPlayers.size() < 2) { // add more players return false; } mDeck = new Deck(deck); CardSet cards; cards.insert(deck.begin(), deck.end()); std::for_each(mGameObservers.begin(), mGameObservers.end(), GameStartNotification(mDeck->trumpSuit(), mGeneratedIds, cards)); return true; }
int main(int argc, char *argv[]) { // Setup deck of cards CardSet deck; for (Rank r = RANK_BEGIN; r != RANK_END; ++r) { for (Suit s = SUIT_BEGIN; s != SUIT_END; ++s) { Card card(r, s); deck.insert(card); } } unsigned long long count = 0; // Test each starting hand for (CardSet::const_iterator i = deck.begin(); i != deck.end(); ++i) { CardSet::const_iterator j = i; for (++j; j != deck.end(); ++j) { string hole = Card::pairString(*i, *j); CardSet test(deck); Hand hand; test.erase(*i); hand.append(*i); test.erase(*j); hand.append(*j); count++; board(hole, test, hand); } } cout << "TOTAL: " << count << endl; printStats(); return 0; }
CardSet PokerHand::cardSet (size_t first, size_t len) const { CardSet cs; size_t last = min(first+len, static_cast<size_t>(_ncards)); for (size_t i=first; i<last; i++) cs.insert (_cards[i]); return cs; }
bool LittleThinkPlayer::follow(const GameState & gstat, CardSet & s) { CardSet pile(gstat.pile); Card tmp; std::cout << gstat << std::endl; s.makeEmpty(); //clear(); sortInHand(); std::cout << "( " << inHand() << " )" << std::endl; inHand().pickup(tmp, -1); // とにかく選ぶ. s.insert(tmp); // the card idential to tmp is already removed from the hand. // cardSetOfSameRanks(s, pile.size()); // たとえば、複数枚のカードを探す関数。ただしこの関数は未実装。 // 現状ではこの follow は Player.cc のものと等価 return true; }
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()); }
// This one is not fully optimized PokerEvaluation CardSet::evaluateRanksLow2to7() const { PokerEvaluation high; PokerEvaluation h; // if there are five or fewer cards, we just evaluate the high, // fix the wheel, and take the complement switch (size()) { case 0: case 1: case 2: case 3: case 4: high = evaluateHighRanks(); break; case 5: high = evaluateHighRanks(); high.fixWheel2to7(rankMask()); break; default: // this is a slow way to handle the general case. // TODO: specialize the code for the 6 and 7 card cases. vector<Card> cards = this->cards(); combinations combo(size(), FULL_HAND_SIZE); PokerEvaluation best; do { CardSet candidate; for (size_t i=0; i<static_cast<size_t>(FULL_HAND_SIZE); i++) candidate.insert(cards[combo[i]]); PokerEvaluation e = candidate.evaluateRanksLow2to7(); if (e > best) best = e; } while (combo.next()); return best; } high.flip(); return high; }
int main (int argc, char * const argv[]) { Card c; CardSet cs; cs.print(); std::cout << std::endl; // 行末記号 end of line を標準出力に出力. // カード入力がエラーになるまで指定したカードを入れる do { std::cout << "Type 'suit number', or e'x'it: "; if ( !c.scan() ) break; c.print(); // std::cout << c << std::endl; // C++ 風に出力するには,operator<< を定義する. std::cout << std::endl; } while ( cs.insert(c) >= 0 ); // 常に ture のはず cs.print(); return 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; }
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; }