Exemplo n.º 1
0
//Given the cards already played by all players and a player's hand, determines the legal cards which can be played by the player
CardList GameLogic::legalMoves(const CardList& table, const CardList& hand) {
	CardList legalMoves;									// used to store legal cards

	// In the case the table is empty, this means this play has 7 of spades, so he has to be forced to play it
	if(table.size() == 0) {
		// finds the 7S card, so we only got one instance of it
		int index = hand.find(Card(SPADE, SEVEN));
		const Card* sevenSpades = hand[index];
		legalMoves.add(sevenSpades);
		return legalMoves;
	}
 
	// loops through hand to determine which ones are legal to play
	for (int index = 0; index < hand.size(); index++) {
		const Card * card = hand[index];

		// Stores the index of lower rank and higher rank card to determine whether it exists or not
		int lowerRankIndex = -1;
		int higherRankIndex = -1;

		// Determines whether a lower rank or higher rank card exists
		if (card->getRank() != ACE) {
			Card lowerRank = Card(card->getSuit(), (Rank) (card->getRank() - 1));
			lowerRankIndex = table.find(lowerRank);
		}
		
		if (card->getRank() != KING) {
			Card higherRank = Card(card->getSuit(), (Rank)(card->getRank() + 1));
			higherRankIndex = table.find(higherRank);
		}

		// Determines whether the current card is legal to play
		if (card->getRank() == SEVEN || lowerRankIndex !=-1 || higherRankIndex != -1) {
			legalMoves.add(card);
		}
	}

	return legalMoves;
}
Exemplo n.º 2
0
// returns a vector of 13 cards for a player to use
CardList Deck::dealPlayerHand() {
    CardList hand;
    
    // grab next 13 cards and copy them to hand vector
    for (int i = 0; i < HAND_SIZE; i++) {
        int index = CARD_COUNT - cards_left_ + i;
        if (index >= 0) {
            hand.add(cards_[index]);
        }
    }
    
    // mark those 13 cards as used
    cards_left_ -= HAND_SIZE;
    
    return hand;
}