本文整理汇总了C++中Hand::end方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::end方法的具体用法?C++ Hand::end怎么用?C++ Hand::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hand
的用法示例。
在下文中一共展示了Hand::end方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rankSort
void PokerHand::rankSort(Hand& hand) // array of cards making up a hand
{
std::sort(hand.begin(), hand.end(),
[](const PlayingCard& firstCard,
const PlayingCard& secondCard) -> bool
{
return firstCard.getRank() < secondCard.getRank();
});
}
示例2: isStraight
bool PokerHand::isStraight(Hand& hand, // array of cards making up a hand
bool& isStraightAceLow) // output variable,
//true if the straight has a low ace
{
// does this hand contain an ace
PokerHand::rankSort(hand);
Hand::iterator aceLocation;
aceLocation = std::find_if (hand.begin(), hand.end(),
[](PlayingCard& card) -> bool
{
return card.getRank() == PlayingCard::Rank::ACE;
});
bool hasAce = hand.end() != aceLocation;
Hand::iterator it;
bool hasStraight;
// determines if the hand is a straight
if (hasAce)
{
it = hand.begin();
bool straightLowAce = it++->getRank() == PlayingCard::Rank::TWO &&
it++->getRank() == PlayingCard::Rank::THREE &&
it++->getRank() == PlayingCard::Rank::FOUR &&
it->getRank() == PlayingCard::Rank::FIVE;
it = hand.begin();
bool straightHighAce = it++->getRank() == PlayingCard::Rank::TEN &&
it++->getRank() == PlayingCard::Rank::JACK &&
it++->getRank() == PlayingCard::Rank::QUEEN &&
it->getRank() == PlayingCard::Rank::KING;
// is there a straight involving a low valued ace
// note: this value is returned by reference
isStraightAceLow = straightLowAce;
hasStraight = straightLowAce || straightHighAce;
}
else
{
it = hand.begin();
PlayingCard::Rank currentRank = it++->getRank();
PlayingCard::Rank nextRank;
PlayingCard::Rank predictedRank;
hasStraight = true;
do
{
// increment the current rank to the next one
int valuePredictedRank = static_cast<int>(currentRank)+1;
predictedRank = static_cast<PlayingCard::Rank>(valuePredictedRank);
nextRank = it++->getRank();
hasStraight = (nextRank == predictedRank) && hasStraight;
currentRank = nextRank;
} while (hasStraight && it != hand.end() );
}
return hasStraight;
}