本文整理汇总了C++中Hand::add_card方法的典型用法代码示例。如果您正苦于以下问题:C++ Hand::add_card方法的具体用法?C++ Hand::add_card怎么用?C++ Hand::add_card使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hand
的用法示例。
在下文中一共展示了Hand::add_card方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
Card::Rank r = static_cast<Card::Rank>(0);
Card::Suit s = static_cast<Card::Suit>(0);
Player *player_ptr = player_factory("counting");
Card card = Card(r, s);
Card dealerCard = card;
Hand playerHand;
playerHand.add_card(card);
assert((*player_ptr).draw(dealerCard, playerHand));
r = static_cast<Card::Rank>(7);
card = Card(r, s);
playerHand.add_card(card);
assert((*player_ptr).draw(dealerCard, playerHand));
return 0;
}
示例2:
TEST(HandTest, testTwoPair) {
for (uint16_t v1 : kValues) {
for (uint16_t v2 : kValues) {
if (v1 == v2)
continue;
for (uint16_t v3 : kValues) {
if (v1 == v3 || v2 == v3)
continue;
Hand h;
Card c1{v1, kHearts};
Card c2{v1, kClubs};
Card c3{v2, kDiamonds};
Card c4{v2, kSpades};
Card c5{v3, kClubs};
h.add_card(c1);
h.add_card(c2);
h.add_card(c3);
h.add_card(c4);
h.add_card(c5);
EXPECT_GE(h.rank(), 1l << 58);
EXPECT_LT(h.rank(), 1l << 59);
}
}
}
}
示例3: deal_card_from_bottom
Card Hand::deal_card_from_bottom(Hand &h)
{
// "bottom" is the beginning of the deck
Card c = hand.remove_from_head();
h.add_card(c);
return c;
}
示例4: main
int main()
{
const char* counting = "counting";
Player *cplayer = player_factory(counting);
Hand chand;
Hand chand1;
Hand chand2;
//I added this comment line
Card c = Card(Card::ACE, Card::SPADES);
Card d = Card(Card::FIVE, Card::CLUBS);
Card f = Card(Card::SIX, Card::CLUBS);
Card g = Card(Card::TWO, Card::CLUBS);
Card e = Card(Card::FOUR, Card::SPADES);
chand.add_card(c);
chand.add_card(d);
chand1.add_card(c);
chand1.add_card(f);
chand2.add_card(c);
chand2.add_card(g);
assert(cplayer->draw(e, chand) == true);
assert(cplayer->draw(e, chand1) == true);
assert(cplayer->draw(e, chand2) == true);
return 0;
}
示例5: deal_card_from_top
Card Hand::deal_card_from_top(Hand &h)
{
// "top" is the end of the array
Card c = hand.remove_from_tail();
h.add_card(c);
return c;
}
示例6: best_five
//choose best five cards
Hand TexasHoldEm::best_five(Player & player){
Hand hand = player.getPlayerHand();
vector<Hand>allhands;
for (size_t i = 0; i < VALID_SEVEN_CARDSTUD_HAND_SIZE; i++){
for (size_t j = i + 1; j < VALID_SEVEN_CARDSTUD_HAND_SIZE; j++){
for (size_t k = j + 1; k < VALID_SEVEN_CARDSTUD_HAND_SIZE; k++){
for (size_t m = k + 1; m < VALID_SEVEN_CARDSTUD_HAND_SIZE; m++){
for (size_t n = m + 1; n < VALID_SEVEN_CARDSTUD_HAND_SIZE; n++){
Hand temphand;
temphand.add_card(hand[i]);
temphand.add_card(hand[j]);
temphand.add_card(hand[k]);
temphand.add_card(hand[m]);
temphand.add_card(hand[n]);
vector<Card> temp_cards = temphand.getCards();
sort(temp_cards.begin(), temp_cards.end());
temphand.sethand(temp_cards);
temphand.setHandRank();
allhands.push_back(temphand);
}
}
}
}
}
sort(allhands.begin(), allhands.end(), poker_rank);
return allhands[0];
}
示例7: best_five
//choose five five cards
Hand SevenCardStud::best_five(Player & player){
Hand hand = player.getPlayerHand();
vector<Hand>allhands;
//generate all posible combinations
for (size_t i = 0; i < VALID_SEVEN_CARDSTUD_HAND_SIZE; i++){
for (size_t j = i + 1; j < VALID_SEVEN_CARDSTUD_HAND_SIZE; j++){
for (size_t k = j + 1; k < VALID_SEVEN_CARDSTUD_HAND_SIZE; k++){
for (size_t m = k + 1; m < VALID_SEVEN_CARDSTUD_HAND_SIZE; m++){
for (size_t n = m + 1; n < VALID_SEVEN_CARDSTUD_HAND_SIZE; n++){
Hand temphand;
temphand.add_card(hand[i]);
temphand.add_card(hand[j]);
temphand.add_card(hand[k]);
temphand.add_card(hand[m]);
temphand.add_card(hand[n]);
vector<Card> temp_cards = temphand.getCards();
sort(temp_cards.begin(), temp_cards.end());
temphand.sethand(temp_cards);
temphand.setHandRank();
allhands.push_back(temphand);
}
}
}
}
}
//sort combinations
sort(allhands.begin(), allhands.end(), poker_rank);
//choose the best one
return allhands[0];
}
示例8: main
int main()
{
const char* counting = "counting";
Player *cplayer = player_factory(counting);
Hand chand;
Card c = Card(Card::FIVE, Card::SPADES);
Card d = Card(Card::SEVEN, Card::CLUBS);
Card e = Card(Card::KING, Card::SPADES);
Card f = Card(Card::TWO, Card::SPADES);
Card g = Card(Card::THREE, Card::SPADES);
Card h = Card(Card::SEVEN, Card::SPADES);
Card i = Card(Card::EIGHT, Card::SPADES);
Card j = Card(Card::NINE, Card::SPADES);
Card k = Card(Card::TEN, Card::SPADES);
Card l = Card(Card::JACK, Card::SPADES);
Card m = Card(Card::QUEEN, Card::SPADES);
Card n = Card(Card::ACE, Card::SPADES);
chand.add_card(c);
chand.add_card(d);
assert(cplayer->draw(e, chand) == true);
assert(cplayer->draw(f, chand) == true);
assert(cplayer->draw(g, chand) == true);
assert(cplayer->draw(h, chand) == true);
assert(cplayer->draw(i, chand) == true);
assert(cplayer->draw(j, chand) == true);
assert(cplayer->draw(k, chand) == true);
assert(cplayer->draw(l, chand) == true);
assert(cplayer->draw(m, chand) == true);
assert(cplayer->draw(n, chand) == true);
return 0;
}
示例9: main
int main(int argc, const char * argv[])
{
Deck deck;
Player *player = player_factory(argv[3]);
Hand hand;
cout << "Shuffling the deck\n";
for (int counter = 0; counter < 7; counter++) {
int num = get_cut();
cout << "cut at " << num << endl;
deck.shuffle(num);
player->shuffled();
}
int minBet = 5;
int bankroll = atoi(argv[1]);
int totalHands = atoi(argv[2]);
int handsPlayed = 1;
while ((bankroll >= minBet) & (handsPlayed <= totalHands)) {
cout << "Hand " << handsPlayed << " bankroll " << bankroll << endl;
if (deck.cards_remaining() < 20) {
int cutNum = get_cut();
cout << "cut at " << cutNum << endl;
deck.shuffle(cutNum);
player->shuffled();
}
int wager = player->bet(bankroll, minBet);
cout << "Player bets " << wager << endl;
Hand dealerHand;
Card p1;
Card p2;
Card d1;
Card d2;
p1 = deck.deal();
d1 = deck.deal();
p2 = deck.deal();
d2 = deck.deal();
hand.add_card(p1);
hand.add_card(p2);
dealerHand.add_card(d1);
dealerHand.add_card(d2);
cout << "Player dealt " << p1 << endl;
player->expose(p1);
cout << "Dealer dealt " << d1 << endl;
player->expose(d1);
cout << "Player dealt " << p2 << endl;
player->expose(p2);
if (hand.hand_value() == 21) {
bankroll += (3/2)*wager;
cout << "Player dealt natural 21\n";
handsPlayed++;
hand.discard_all();
} else {
cout << "Player's total is " << hand.hand_value() << endl;
while (player->draw(d1, hand)) {
Card c1 = deck.deal();
hand.add_card(c1);
player->expose(c1);
cout << "Player dealt " << c1 << endl;
cout << "Player's total is " << hand.hand_value() << endl;
}
if ((hand.hand_value() > 21) & (!hand.hand_is_soft())) {
cout << "Player busts!" << endl;
bankroll -= wager;
handsPlayed++;
hand.discard_all();
} else {
cout << "Dealer's hole card is " << d2 << endl;
player->expose(d2);
while (dealerHand.hand_value() < 17) {
Card c1 = deck.deal();
dealerHand.add_card(c1);
player->expose(c1);
cout << "Dealer dealt " << c1 << endl;
}
cout << "Dealer's total is " << dealerHand.hand_value() << endl;
if ((dealerHand.hand_value() > 21) & (!dealerHand.hand_is_soft())) {
cout << "Dealer busts!" << endl;
bankroll += wager;
handsPlayed++;
hand.discard_all();
} else {
if (dealerHand.hand_value() > hand.hand_value()) {
cout << "Dealer wins\n";
bankroll -= wager;
handsPlayed++;
hand.discard_all();
} else if (dealerHand.hand_value() < hand.hand_value()) {
//.........这里部分代码省略.........
示例10: main
int main (int argc, char *argv[])
{
assert(argc == 4);
int bankRoll = atoi(argv[1]);
int maxHands = atoi(argv[2]);
//bankRoll and max # of hands taken in from command line
Player *player = player_factory(argv[3]);
//type of player confirmed
Deck deck;
//Deck initialized
int handsPlayed = maxHands;
deckShuffle(&deck, player);
(*player).shuffled();
for (int i = 0; i < maxHands; i++)
{
if (bankRoll >= 5)
{
cout << "Hand " << (i+1) << " bankroll " << bankRoll << endl;
if (deck.cards_remaining() < 20)
{
deckShuffle(&deck, player);
(*player).shuffled();
}
int wager = (*player).bet(bankRoll, MIN_BET);
cout << "Player bets " << wager << endl;
Hand playerHand = Hand();
Hand dealerHand = Hand();
//hands initialized
Card dealerUp;
for (int i = 0; i < 3; i++)
{
Card nextCard = deck.deal();
if (i == 1)
{
addUpCard("Dealer", &dealerHand, player, nextCard);
dealerUp = nextCard;
}
else
{
addUpCard("Player", &playerHand, player, nextCard);
}
}
//Deals all visible cards
Card dealerDown = deck.deal();
dealerHand.add_card(dealerDown);
//dealer facedown card dealt
if (playerHand.hand_value() == 21)
{
cout << "Player dealt natural 21\n";
bankRoll += (3*wager)/2;
}
else
{
int total = playerHand.hand_value();
while ((*player).draw(dealerUp, playerHand))
{
Card nextCard = deck.deal();
addUpCard("Player", &playerHand, player, nextCard);
total = playerHand.hand_value();
}
// draws cards
cout << "Player's total is " << total << endl;
if (total > 21)
{
cout << "Player busts\n";
bankRoll -= wager;
}
else
{
(*player).expose(dealerDown);
cout << "Dealer's hole card is " << dealerDown << endl;
while (dealerHand.hand_value() < 17)
{
Card nextCard = deck.deal();
addUpCard("Dealer", &dealerHand, player, nextCard);
total = dealerHand.hand_value();
}
cout << "Dealer's total is " << total << endl;
if (total > 21)
{
cout << "Dealer busts\n";
bankRoll += wager;
}
else
{
int dealerTotal = dealerHand.hand_value();
int playerTotal = playerHand.hand_value();
//.........这里部分代码省略.........