int main() { const char* counting = "counting"; Player *cplayer = player_factory(counting); Hand chand; Hand chand1; Hand chand2; //I added this comment line Card c = Card(Card::ACE, Card::SPADES); Card d = Card(Card::FIVE, Card::CLUBS); Card f = Card(Card::SIX, Card::CLUBS); Card g = Card(Card::TWO, Card::CLUBS); Card e = Card(Card::FOUR, Card::SPADES); chand.add_card(c); chand.add_card(d); chand1.add_card(c); chand1.add_card(f); chand2.add_card(c); chand2.add_card(g); assert(cplayer->draw(e, chand) == true); assert(cplayer->draw(e, chand1) == true); assert(cplayer->draw(e, chand2) == true); return 0; }
void Deck::init() { for (int i = 0; i < MAX_CARD_VALUE; ++i) { cards.push_back(Card(CLUBS, i)); cards.push_back(Card(DIAMONDS, i)); cards.push_back(Card(HEARTS, i)); cards.push_back(Card(SPADES, i)); } }
Hand2 parseHand2(json::Value value) { Hand2 hand; hand[0] = Card(value[size_t(0)]); hand[1] = Card(value[size_t(1)]); std::sort(hand.begin(), hand.end()); return hand; }
int IdenticeO(TMultime *m1, TMultime *m2) { TMultime *x,*y; if(Card(m1)!=Card(m2)) return 0; for(x = m1->v , y = m2->v ; x < m1->s ; x+= m1->d, y+=m2->d){ if(m1->fid(x,y)!=0) return 0; // if( *(char*)x != *(char*)y ) return 0; } return 1; }
TEST(PutDown, LessThanFour) { std::vector<Card> j = std::vector<Card>(); j.push_back(Card(1,5)); j.push_back(Card(2,5)); Player pj = Player(j,"NICK"); std::vector<Card> pdj = pj.putDown(5); ASSERT_EQ(0, pdj.size()); }
TEST(Query, NoCards) { std::vector<Card> h = std::vector<Card>(); h.push_back(Card(1,5)); h.push_back(Card(2,5)); h.push_back(Card(3,5)); h.push_back(Card(4,5)); Player p = Player(h,"NICK"); std::vector<Card> pd = p.query(4); ASSERT_EQ(0, pd.size()); }
TEST(AddCard, NewCardSameOthers) { std::vector<Card> h = std::vector<Card>(); h.push_back(Card(1,5)); h.push_back(Card(2,5)); h.push_back(Card(3,5)); Player p= Player(h,"NICK"); p.addCard(Card(4,5)); EXPECT_EQ(4, p.getHand().size()); EXPECT_EQ(4, p.query(5).size()); }
void Game::createDeck(){ for (int i = 1; i <= 52; i++){ // Adding two of the same card because we use two decks deck.push_back(Card(i)); deck.push_back(Card(i)); } random_shuffle(deck.begin(), deck.end()); random_shuffle(deck.begin(), deck.end()); random_shuffle(deck.begin(), deck.end()); }
TEST(AddCards, NoCards) { std::vector<Card> d = std::vector<Card>(); d.push_back(Card(1,4)); d.push_back(Card(2,2)); d.push_back(Card(3,6)); Player p= Player(d,"NICK"); std::vector<Card> h = std::vector<Card>(); p.addCards(h); ASSERT_EQ(3, p.getHand().size()); }
Deck::Deck() { cards_.reserve(36); for (int i = 6; i <= Card::ACE; i++) { cards_.push_back(Card(i, Card::hearts)); cards_.push_back(Card(i, Card::diamonds)); cards_.push_back(Card(i, Card::spades)); cards_.push_back(Card(i, Card::clubs)); } }
int main() { std::vector<Card> cards; // Correct cards.push_back(Card(SPADES, ACE)); cards.push_back(Card(SPADES, TWO)); // Wrong cards.push_back(Card(Suit::SPADES, Value::ACE)); cards.push_back(Card(Suite::SPADES, Value::TWO)); return 0; }
TEST(TestPutDown, ForFourOfAKind) { std::vector<Card> h = std::vector<Card>(); h.push_back(Card(1,5)); h.push_back(Card(2,5)); h.push_back(Card(3,5)); h.push_back(Card(4,5)); Player p = Player(h,"NICK"); std::vector<Card> pd = p.putDown(5); EXPECT_EQ(4, pd.size()); EXPECT_EQ(5, pd.front().getRank()); }
void botmove(){ addressCard C = whichcardtake(); if(C != NULL){ doTake(Card(C)); doMeld(Card(C)); }else{ doDraw(); } botmeld(); infoCard off = whichcardoff(); doOff(off); }
TEST(AddCards, NewCardsNoOthers) { Player p= Player("NICK"); std::vector<Card> h = std::vector<Card>(); h.push_back(Card(1,5)); h.push_back(Card(2,5)); h.push_back(Card(3,5)); p.addCards(h); ASSERT_EQ(3, p.getHand().size()); }
Deck::Deck() { // fill the deck this->reserve(52); for(int i = 1; i <= 13; i++) { this->push_back(Card(Card::Spades, i)); this->push_back(Card(Card::Clubs, i)); this->push_back(Card(Card::Diamonds, i)); this->push_back(Card(Card::Hearts, i)); } }
void Game::Reset(int nEachType) { m_deck.clear(); m_arena.clear(); int count; int serial = 100; std::vector<Card::Face> faces; faces.push_back(Card::Goomba); faces.push_back(Card::Mushroom); faces.push_back(Card::Flower); faces.push_back(Card::Mario); faces.push_back(Card::Bowser); faces.push_back(Card::Cloud); faces.push_back(Card::Luigi); faces.push_back(Card::Star); std::vector<Card::Face>::const_iterator faceIt; for(count = 0; count < nEachType; count ++, serial ++) { for(faceIt = faces.begin(); faceIt != faces.end(); ++ faceIt) { m_deck.push_back(Card(*faceIt, serial)); } } std::random_shuffle(m_deck.begin(), m_deck.end(), MarioRand); _DealOut(); }
bool SimpleXMLHandler::startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes) { // maybe check for double opening lines? //qDebug("lol"); if (qName == "LINES") { bool ok1 = true, ok2 = true; row = 0; readingCards = true; properties.resize(attributes.value("ColCount").toInt(&ok1)); // cards.resize(attributes.value("RowCount").toInt(&ok2) - 1); if (!ok1 || !ok2 ) { errorStr = "Can't convert string to double."; return false; } } else if (!readingCards) { return true; } else if (qName == "LINE") { column = 0; currentCard = Card(); } else if (qName == "CELL") { currentText.clear(); } return true; }
void Hand::clearHand() { for (int i = 0; i < 5; i++) { _hand[i] = Card(); /*** Make this a 'NULL' card instead? ***/ } }
Card charsToCard(char c0, char c1) { if(c0 >= 'a' && c0 <= 'z') c0 += ('A' - 'a'); if(c1 >= 'A' && c1 <= 'Z') c1 += ('a' - 'A'); std::string c; c += c0; c += c1; return Card(c); }
void afiMx(TMultime*m) /* afiseaza continut multime de Tx */ { Tx *p = (Tx*)(m->v); int i = 0, n = Card(m); printf(" v1 v2 v3\n"); for(; i < n; i++) printf("[%2i]%4i%7.2lf %s\n", i, p[i].v1, p[i].v2, p[i].v3); }
void Deck::fill(const bool shuffle) { // add card based with value for each front texture supplied auto add_card = [ this ](const unsigned int value, const std::vector<std::string> &textures) { for (auto &t : textures) { auto &c = this->add_child(Card(value, true, Texture(Card::TEXTURE_BACK, true))); c.face().texture(Texture("./resources/" + t, true)); // set card face texture } }; // add_card // strings refer to textures in the ./resources/ directory add_card(2, { "2_of_clubs.png", "2_of_diamonds.png", "2_of_hearts.png", "2_of_spades.png" }); add_card(3, { "3_of_clubs.png", "3_of_diamonds.png", "3_of_hearts.png", "3_of_spades.png" }); add_card(4, { "4_of_clubs.png", "4_of_diamonds.png", "4_of_hearts.png", "4_of_spades.png" }); add_card(5, { "5_of_clubs.png", "5_of_diamonds.png", "5_of_hearts.png", "5_of_spades.png" }); add_card(6, { "6_of_clubs.png", "6_of_diamonds.png", "6_of_hearts.png", "6_of_spades.png" }); add_card(7, { "7_of_clubs.png", "7_of_diamonds.png", "7_of_hearts.png", "7_of_spades.png" }); add_card(8, { "8_of_clubs.png", "8_of_diamonds.png", "8_of_hearts.png", "8_of_spades.png" }); add_card(9, { "9_of_clubs.png", "9_of_diamonds.png", "9_of_hearts.png", "9_of_spades.png" }); add_card(10, { "10_of_clubs.png", "10_of_diamonds.png", "10_of_hearts.png", "10_of_spades.png" }); add_card(11, { "jack_of_clubs.png", "jack_of_diamonds.png", "jack_of_hearts.png", "jack_of_spades.png" }); // jack add_card(12, { "queen_of_clubs.png", "queen_of_diamonds.png", "queen_of_hearts.png" , "queen_of_spades.png" }); // queen add_card(13, { "king_of_clubs.png", "king_of_diamonds.png", "king_of_hearts.png", "king_of_spades.png" }); // king add_card(14, { "ace_of_clubs.png", "ace_of_diamonds.png", "ace_of_hearts.png", "ace_of_spades.png" }); // ace if (shuffle) this->shuffle(); } // fill
void Deck::init(int numDecks){ numDecks = numDecks; numCards = numDecks * 52; vector<int> cardList; //Initialize List of Cards int cardAvailable = numCards, val, idx; for(int i=0;i<13;i++){ for(int j=0;j<(numDecks*4);j++){ cardList.insert(cardList.end(),i); } } //Shuffle the deck srand (time(NULL)); for(int i=0;i<numCards;i++){ if(cardAvailable >1 ) idx = rand() % (cardAvailable); else idx = 0; val = cardList[idx]; cardList.erase(cardList.begin()+idx); cardAvailable--; deckList.push_front(Card(val,false)); } //Delete the cardlist vector<int>().swap(cardList); }
void Checker::claimMaster(ClaimMaster& res, Seat* s, Card::Suit suit) { ManagerBase* m = s->manager(); const Option& opt = m->option(); if (opt.claimMasterWithKing && !s->has(Card::KingBlack) && !s->has(Card::KingRed)) { throw Exception(CheckerExcp,ErrorCode::ClaimWithoutKing, "Must use king to claim"); } int level = m->level(); int n = 0; bool kingRed = false; if (suit == Card::King) { n = s->has(Card::KingBlack); if (n < 2) { n = s->has(Card::KingRed); kingRed = true; } if (n != 2) { throw Exception(CheckerExcp,ErrorCode::ClaimRequireKingPair); } } else { n = s->has(Card(suit, level)); } if (n == 0) { throw Exception(CheckerExcp,ErrorCode::ClaimRequireMasterNumber); } const ClaimMaster& cm = m->master(); if (cm.seat >= 0) { if (cm.seat == s->id() && (cm.card.isKing() || cm.card.suit() != suit)) { throw Exception(CheckerExcp,ErrorCode::ClaimAntiSelf); } if (n <= 1) { throw Exception(CheckerExcp,ErrorCode::ClaimWeak); } if (cm.pair) { if (suit != Card::King) { throw Exception(CheckerExcp,ErrorCode::ClaimWeak); } else if (cm.king.suit() == Card::King && !kingRed) { throw Exception(CheckerExcp,ErrorCode::ClaimWeak); } } } res.seat = s->id(); res.card.set(suit, level); res.pair = n == 2; if (suit == Card::King) { if (s->has(Card::KingBlack) == 2) { res.king.set(Card::KingBlack); } else { res.king.set(Card::KingRed); } } else if (opt.claimMasterWithKing) { if (s->has(Card::KingBlack)) { res.king.set(Card::KingBlack); } else { res.king.set(Card::KingRed); } } }
void PokerTest::sortTest() { std::cout << "sort test" << std::endl; Hand hand1(Card(Rank::JACK, Suit::HEART), Card(Rank::ACE, Suit::HEART), Card(Rank::FIVE, Suit::HEART), Card(Rank::SIX, Suit::HEART), Card(Rank::TWO, Suit::HEART)); Hand hand2(Card(Rank::ACE, Suit::SPADE), Card(Rank::FIVE, Suit::SPADE), Card(Rank::FOUR, Suit::SPADE), Card(Rank::THREE, Suit::SPADE), Card(Rank::TWO, Suit::SPADE)); PokerGame game(hand1, hand2); std::cout << game; }
void Deck::reset () { clear (); for(int i=0;i<SUIT_COUNT;i++){ for (int j=0;j<RANK_COUNT;j++){ addCard (Card (Suit(i), Rank(j))); } } }
void CardDeck::buildDeck() { char suits[4] = {'S', 'H', 'D', 'C'}; for (int suit = 0; suit < 4; suit++) { for (int value = 0; value < 13; value++) { cards[suit*13+value] = Card(suits[suit], value+1); } } }
CardDeck::CardDeck() { currentCardIndex = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 13; j++) { cards[i*13 + j] = Card((Card::Suit) i, (Card::Rank) (j + 2)); } } }
Deck::Deck() { srand(time(NULL)); for (int i = 0; i < CARDS_QUANTITY; i++) { deck.append(Card((E_CARD)i)); } }
Deck::Deck() : m_deck(), m_pos(CARDS_IN_DECK) { m_deck.reserve(CARDS_IN_DECK); //Generate all cards and add them to the stack for (int value = LOWEST_CARD_VALUE; value <= HIGHEST_CARD_VALUE; value++) { m_deck.push_back(Card(value, HEARTS)); m_deck.push_back(Card(value, CLUBS)); m_deck.push_back(Card(value, DIAMONDS)); m_deck.push_back(Card(value, SPADES)); } //Shuffle cards random_shuffle(m_deck.begin(), m_deck.end()); }
Card Deck::next() { if(index >= 52) return Card(); Card result = cards[index]; index++; return result; }