/********************************************************************** * Purpose: This function returns bool for if a move is valid * * Entry: This function takes a top and bottom card. * * Exit: This function returns a bool. * ************************************************************************/ bool Board::isValid(Card move, Card bottom) { bool valid(false); Rank move_rank = move.GetRank(); Suit move_suit = move.GetSuit(); Rank bottom_rank = bottom.GetRank(); Suit bottom_suit = bottom.GetSuit(); // Red onto a black card case if (move_suit == HEART || move_suit == DIAMOND) { if (bottom_suit == CLUB || bottom_suit == SPADE) { if (move_rank == (bottom_rank - 1)) valid = true; } } // Black onto a red card case if (move_suit == CLUB || move_suit == SPADE) { if (bottom_suit == HEART || bottom_suit == DIAMOND) { if (move_rank == (bottom_rank - 1)) valid = true; } } return valid; }
/********************************************************************** * Purpose: add card to home cell * Entry: Card card * Exit: bool ************************************************************************/ bool HomeCell::Add(Card card) { bool valid = true; if (card.GetRank() == Card::ACE || (!m_home[card.GetSuit() - Card::HEART]->IsEmpty() && (card.GetRank() == (m_home[card.GetSuit() - Card::HEART]->Peek().GetRank() + 1)))) { m_home[card.GetSuit() - Card::HEART]->Push(card); } else valid = false; return valid; }
//------------------------------------------------------------------------------ // CheckCarteBlanche - Check if either play has a Carte Blanche. //------------------------------------------------------------------------------ PlayerNum CardManager::CheckCarteBlanche(void) { Card* card; bool carteBlanche = true; PlayerNum p = NOPLAYER; for ( int i = 0; i < playerHand->GetSize(); i++ ) { card = playerHand->GetCard(i); if ( card->GetRank() > 10 && card->GetRank() < 14 ) carteBlanche = false; } if ( carteBlanche ) { p = PLAYER1; } else { carteBlanche = true; for ( int i = 0; i < cpuHand->GetSize(); i++ ) { card = cpuHand->GetCard(i); if ( card->GetRank() > 10 && card->GetRank() < 14 ) carteBlanche = false; } if ( carteBlanche ) { p = PLAYER2; } } return p; }