Example #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;
}
Example #2
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);
}