gpt4 book ai didi

c++ - 检查扑克牌的大牌和对子

转载 作者:行者123 更新时间:2023-11-30 05:47:16 24 4
gpt4 key购买 nike

<分区>

我只是想检查牌是否高,以便评估手牌。此外,类似于检查对、直线等。但现在,这些是递归的,所以我不确定如何检查等级。感谢帮助!!

函数.cpp

int Hand::find_high_rank() const 
{
int high_rank = 0;

for (unsigned i = 0; i<m_hand.size(); i++)
high_rank = max(high_rank, m_hand[i].get_rank());
return high_rank;
}
bool Hand::is_straight()
{
if (! (is_straight()))
return false;
m_high_rank = find_high_rank();
return true;
}
//these functions are similar for flush, two pair, full house, etc.

头文件

class Card{
public:
Card(int value, char suit) : value(value), suit(suit) {}
Card ();
private:
int value;
char suit;
};
class Deck {
public:
void createDeck();
void shuffleDeck();
Card Draw();
Deck();
void Print() const;
private:
vector<Card> deck;
};
enum hand_kind
{ HIGH_CARD,
ONE_PAIR,
TWO_PAIR,
THREE_OF_A_KIND,
STRAIGHT,
FLUSH,
FULL_HOUSE,
FOUR_OF_A_KIND,
STRAIGHT_FLUSH,
};
class Hand {
vector<Card> m_hand;
hand_kind m_kind;
int m_high_rank;

bool is_straight_flush ();
bool is_four();
bool is_full_house();
bool is_flush ();
bool is_straight ();
bool is_three();
bool is_same_rank (int rank);
bool is_two_pair ();
int find_high_rank () const;
int how_many (int rank) const;
public:
Hand ();
void add_card_to_hand (const Card & card);
hand_kind classify_hand ();

bool operator < (const Hand & rhs) const;

friend ostream & operator << (ostream & os, const Hand & hand);
};

这里也是设置平台的地方:

void Deck::createDeck() {
deck.clear();
static const char suits[] = {'C','D','H','S'};
for (int suit=0; suit < 4; suit++)
for (int val=1; val <=13; val++)
deck.push_back(Card(val,suits[suit]));
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com