C++ 试图返回“的金额”;“三个一类”;在一个运行16000次的扑克手上 bool Hand::isFlush() { if(cardVector[0]。suit=cardVector[1]。suit=cardVector[2]。suit=cardVector[3]。suit=cardVector[4]。suit)返回true; 返回false; } bool Hand::isThreeOfKind() { 如果(cardVector[4].rank=cardVector[3].rank,//将卡片5与4进行比较,然后将卡片5与3进行比较。 cardVector[4]。秩=cardVector[2]。秩) { 返回true; } 返回false; if(cardVector[3].rank=cardVector[2].rank,//比较卡4和卡3以及卡4和卡2 cardVector[3]。秩=cardVector[1]。秩) { 返回true; } 返回false; 如果(cardVector[2].rank=cardVector[1].rank, cardVector[2]。秩=cardVector[0]。秩)//比较卡片3与2以及卡片3与1 { 返回true; } 返回false;} int main() { cout

C++ 试图返回“的金额”;“三个一类”;在一个运行16000次的扑克手上 bool Hand::isFlush() { if(cardVector[0]。suit=cardVector[1]。suit=cardVector[2]。suit=cardVector[3]。suit=cardVector[4]。suit)返回true; 返回false; } bool Hand::isThreeOfKind() { 如果(cardVector[4].rank=cardVector[3].rank,//将卡片5与4进行比较,然后将卡片5与3进行比较。 cardVector[4]。秩=cardVector[2]。秩) { 返回true; } 返回false; if(cardVector[3].rank=cardVector[2].rank,//比较卡4和卡3以及卡4和卡2 cardVector[3]。秩=cardVector[1]。秩) { 返回true; } 返回false; 如果(cardVector[2].rank=cardVector[1].rank, cardVector[2]。秩=cardVector[0]。秩)//比较卡片3与2以及卡片3与1 { 返回true; } 返回false;} int main() { cout,c++,C++,这是未经测试的,因为我没有手牌、牌组和卡牌的声明,但它应该能让您了解测试不同手牌的方法 如上所述,代码中存在一些问题,例如在if检查中不使用==来测试相等性,以及使用逗号而不是逻辑运算符(&&,|) 一般来说,最好只使用一个评分函数,为每种类型的手牌返回不同的值(高卡、一对、两对、三对、同花顺等)不必对每只手进行多次测试。它可以让您轻松地根据手的得分进行比较,并大大减少重复工作的数量,如计算等级和西装。对手进行排序也是一个好主意,因为它简化了直杆测试,因为您只需测试第一和第二等级之间的排列最后一

这是未经测试的,因为我没有手牌、牌组和卡牌的声明,但它应该能让您了解测试不同手牌的方法

如上所述,代码中存在一些问题,例如在if检查中不使用
==
来测试相等性,以及使用逗号而不是逻辑运算符(
&&
|

一般来说,最好只使用一个评分函数,为每种类型的手牌返回不同的值(高卡、一对、两对、三对、同花顺等)不必对每只手进行多次测试。它可以让您轻松地根据手的得分进行比较,并大大减少重复工作的数量,如计算等级和西装。对手进行排序也是一个好主意,因为它简化了直杆测试,因为您只需测试第一和第二等级之间的排列最后一张牌,一旦你消灭了其余的得分手

bool Hand::isFlush()
{
    if(cardVector[0].suit=cardVector[1].suit=cardVector[2].suit=cardVector[3].suit=cardVector[4].suit)return true;
    return false;
}

bool Hand :: isThreeOfKind() 

{


        if (cardVector[4].rank=cardVector[3].rank, // comparing card 5 to 4, then card 5 to 3.
        cardVector[4].rank=cardVector[2].rank)
        {
            return true;
        }

        return false;
         if (cardVector[3].rank=cardVector[2].rank, //comparing card 4 to 3 and the card 4 to 2
            cardVector[3].rank=cardVector[1].rank)
            {
                return true;
            }
         return false;
         if (cardVector[2].rank=cardVector[1].rank,
                    cardVector[2].rank=cardVector[0].rank) //comparing card 3 to 2 and the card 3 to 1
                 {
                        return true;
                 }      
        return false;}



int main ()
{

    cout<< "welcome" << endl;


    Deck deck;
    float flushCount=0;
    float threeKind=0;
    float count= 16000;
        for(int i=0;i<count;i++)
    {
        deck.shuffle();
        Hand hand=deck.dealHand();
        if(hand.isFlush())flushCount++;


    }
        for (int j=0;j<count;j++)
        {
            Hand hand=deck.dealHand();
            if (hand.isThreeOfKind())threeKind++;

        }
    cout << "The amount of flushes in a game run 160000 times is..."<< endl;
    cout << flushCount << endl;
    cout << (flushCount/count)*100 << endl;
    cout << " Your have this many  "<< threeKind << endl; 





    system("pause");
    return 0;
}
bool Hand::isFlush()
{
对于(int i=1;i<5;++i)
{
if(cardVector[i].suit!=cardVector[0].suit)
{
返回false;
}
}
返回true;
}
bool Hand::isThreeOfKind()
{
//这是16,因为我不知道你的排名是从0开始还是从2开始
整数计数[16]={0};
对于(int i=0;i<5;++i)
{
++计数[cardVector[i].rank];
}
//这只是给你一个关于单分数函数的概念
//可以消除工作。如果你只想测试3种,那么
//你不需要成对和四对的测试和计数
int num_pairs=0;
int num_threes=0;
int num_fours=0;
对于(int i=0;i<16;++i)
{
如果(计数[i]==2)
{
++数对;
}
else if(计数[i]==3)
{
++数三;
}
else if(计数[i]==4)
{
++四个;
}
}
如果(num_threes==1)
{
返回true;
}
返回false;
}

您知道
isFlush
,以及
isThreeOfKind
,正在执行赋值,而不是比较?此外,您似乎不理解逗号运算符的作用。您的代码似乎还假设卡片是有序的,即,相同秩的三张卡片将在cardVector中相邻。赋值将在然而,目前的等价检验更为明显。一种方法是对手牌进行排序,并以这种方式搜索相邻的牌。另一种方法是使用一个包含所有等级的数组,并以这种方式计算所有牌,然后查找任何具有值3的等级。使用一堆if/else进行排序会变得非常复杂和难看ast。在你尝试循环使用16000张卡之前,让它在一组五张卡上正常工作。除了第一次检查之外,你永远不会测试任何东西,因为如果失败,你会无条件地返回false。正如上面其他人所说,我确实误解了=运算符的用法以及&&| |的其他用法。我用正确的用法重新编写了它们,得到了正确的结果去掉if和else,它就开始工作了。我的排名也是从2开始的。谢谢你的输入!!!!
bool Hand::isFlush()
{
    for(int i = 1; i < 5; ++i)
    {
        if(cardVector[i].suit != cardVector[0].suit)
        {
            return false;
        }
    }
    return true;
}

bool Hand::isThreeOfKind() 
{
    //This is 16 because I don't know if your ranks start at 0 or 2
    int counts[16] = {0};
    for(int i = 0; i < 5; ++i)
    {
        ++counts[cardVector[i].rank];
    }
    //This is just to give you an idea of how having single score function
    //can eliminate work.  If you only want to test for 3 of a kind then
    //you don't need the pairs and fours tests and counts
    int num_pairs = 0;
    int num_threes = 0;
    int num_fours = 0;
    for(int i = 0; i < 16; ++i)
    {
        if(counts[i] == 2)
        {
            ++num_pairs;
        }
        else if(counts[i] == 3)
        {
            ++num_threes;
        }
        else if(counts[i] == 4)
        {
            ++num_fours;
        }
    }
    if(num_threes == 1)
    {
        return true;
    }
    return false;
}