本文整理汇总了C++中Hand::calculate方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::calculate方法的具体用法?C++ Hand::calculate怎么用?C++ Hand::calculate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hand
的用法示例。
在下文中一共展示了Hand::calculate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: comparePlayerHands
/**
Compares 2 hands and returns int of winner or 3 if a push
@return 1: if 1st hand is > 2nd hand.
@return 2: if 1st hand is < 2nd hand.
@return 0: if 1st hand is = 2nd hand.
*/
int Game::comparePlayerHands(Hand playersHand, Hand DealersHand) {
const int HAND1_IS_GREATER = 1;
const int HAND2_IS_GREATER = 2;
const int HAND1_IS_BUSTED = 3;
const int HANDS_ARE_EQUAL = 0;
const int TWENTY_ONE = 21;
int h1 = playersHand.calculate();
int h2 = DealersHand.calculate();
if (h1 > TWENTY_ONE ) {
return HAND1_IS_BUSTED;
}
else if (h1 > h2) {
return HAND1_IS_GREATER;
}
else if (h1 == h2) {
return HANDS_ARE_EQUAL;
}
else if (h1 < h2) {
if (h2 > TWENTY_ONE) {
return HAND1_IS_GREATER;
}
else
return HAND2_IS_GREATER;
}
else {
return TWENTY_ONE;
}
}
示例2: insurancePayout
int Game::insurancePayout(std::vector<GamePlayer*> &gPlayers, Hand dealersHand) {
//Player shouldn't be asked for insurance if he has BJ because it is unnessacary according to most forums/wikipedia
const int BLACKJACK_FLAG = 21;
const int GAME_GOES_ON_FLAG = 0;
if (dealersHand.calculate() == BLACKJACK_FLAG) {
for (auto gP: gPlayers) {
if (gP->getHand(0).calculate() == BLACKJACK_FLAG) { //dealer and player have BJ (push w/ins.)
if (gP->getInsuranceFlag() == true) {
payout(INSURANCE_PUSH, *gP, 0);
//std::cout << gP->getName(false) << " took insurance and wins even money! (2:1)" << std::endl;
}
else {
payout(NO_INSURANCE_PUSH, *gP, 0);
//std::cout << gP->getName(false) << " did not take insurance, therefore it's a push! (1:1)" << std::endl; //dealer and player have BJ (push/no ins.)
}
}
else { //dealer has BJ but player does not
if (gP->getInsuranceFlag() == true) {
payout(INSURANCE_BJ, *gP, 0);
//std::cout << gP->getName(false) << " took insurance, therefore " << gP->getName(false) << " loses bet, but gets back insurance! (2:1)" << std::endl;
}
else {
payout(NO_INSURANCE_BJ, *gP, 0);
//std::cout << gP->getName(false) << " did not take insurance, and loses bet as a result." << std::endl;
}
}
}
return BLACKJACK_FLAG; //game will start next round after payout
}
else { //dealer does not have BJ
std::cout << "Dealer does not have BlackJack..." << std::endl;
for (auto gP: gPlayers) {
if (gP->getHand(0).calculate() == BLACKJACK_FLAG) { //dealer does not have BJ, player does have BJ
std::cout << gP->getName(false) << " has BlackJack and wins bet at 3:2 payout" << std::endl;
payout(BLACK_JACK, *gP, 0);
}
else { //neither dealer or player have BJ
if (gP->isInSession()) {
std::cout << gP->getName(false) << " and Dealer do not have BlackJack" << std::endl;//, checking for special plays..." << std::endl;
}
else
std::cout << gP->getName(false) << " not in play" << std::endl;
}
}
}
//game goes on
return GAME_GOES_ON_FLAG;
}