Пример #1
0
/**
 * Get legal plays per straight game play. Needs played cards for the round.
 */
Cards Player::getLegalPlays(Cards cardsOnTable) const {
    Cards legalPlays;
    Card firstCard = Card(SPADE, SEVEN);

    // Outer loop: current cards in hand
    for (int i = 0; i < getCurrentCards().size(); i++) {
        bool isLegalPlay = false;

        // Only legal card is 7S if there is a 7S on your hand
        if (*getCurrentCards().at(i) == firstCard) {
            legalPlays.clear();
            legalPlays.push_back(getCurrentCards().at(i));
            return legalPlays;

        // Legal if card is a 7
        } else if (getCurrentCards().at(i)->getRank() == SEVEN) {
            isLegalPlay = true;

        // If card in hand has same suit and is +/- 1 rank of a played card, then it is legal
        } else {
            for (int j = 0; j < cardsOnTable.size(); j++) {
                if (cardsOnTable.at(j)->getSuit() == getCurrentCards().at(i)->getSuit()
                    && abs((int) cardsOnTable.at(j)->getRank() - (int) getCurrentCards().at(i)->getRank()) <= 1) {
                    isLegalPlay = true;
                }
            }
        }

        if (isLegalPlay) {
            legalPlays.push_back(getCurrentCards().at(i));
        }
    }

    return legalPlays;
}
Пример #2
0
void CardsDB::addCards(struct card_info *card_infos, ChipSet chipset)
{
    Cards *cards;
    struct Card card;
    struct pci_access *pacc;
    char devbuf[128];

    pacc = pci_alloc();

    for (int i = 0; card_infos[i].card_name != NULL; i++) {

	QString vendor = (card_infos[i].vendor_id == 0xffff ? i18n("Other") : 
			  pci_lookup_name(pacc, devbuf, sizeof(devbuf), PCI_LOOKUP_VENDOR, card_infos[i].vendor_id, 0));

	card.card_id = card_infos[i].card_id;
	card.card_name = card_infos[i].card_name;
	card.chipset = chipset;

	if (!m_vendors.contains(vendor)) {
	    cards = new Cards();
	    m_vendors[vendor] = cards;
	} else {
	    cards = m_vendors[vendor];
	}

	cards->push_back(card);
    }

    pci_cleanup(pacc);
}
Пример #3
0
void Deck::deal(Cards& playerOne, Cards& playerTwo, Cards& playerThree, Cards& playerFour, Cards& kitty) {
    trace;
    srand(unsigned(time(0)));
    Card* joker = (Card*)&__cardspace[42*sizeof(Card)];
    joker->setJokerSuit(Suit::NONE);
    std::random_shuffle(begin(), end());
    std::vector<Card*>::iterator it = begin();
    playerOne.clear();
    playerTwo.clear();
    playerThree.clear();
    playerFour.clear();
    for(unsigned i = 0; i < 10; ++i) {
        playerOne.push_back(*it++);
        playerTwo.push_back(*it++);
        playerThree.push_back(*it++);
        playerFour.push_back(*it++);
    }
    kitty.clear();
    kitty.push_back(*it++);
    kitty.push_back(*it++);
    kitty.push_back(*it);
}