戳游戏并判断花色

问题描述

我想解决一个关于扑克游戏的问题。玩家需要输入他想玩的回合,每回合随机发五张牌。编程需要判断五种花色,包括同花顺、同花顺、满堂红、同花顺、顺子。最后,打印每次出现的总数。

问题 enter image description here

我尝试打印每一轮的结果进行调试,但我发现每一轮的结果都是一样的。但是,我在 152 和 178 线设置了拆分,结果不一样。我不知道如何解决它。

带有断点 enter image description here

没有断点 enter image description here

 enter code here
#include <iostream>
#include<stdlib.h>
#include<string>
#include<time.h>
#include<cmath>
using namespace std;

string pflo[4] = { "Club","Diamond","Heart","Spade" };
string pnum[13] = { "A","2","3","4","5","6","7","8","9","10","J","Q","K" };
int poker[4][13] = { 0 };//52張牌是否有重複的依據
int allPoker[5];


void deal() {
    int flo,num,all;
    //srand((unsigned)time(NULL));
    srand(time(NULL));
    for (int i = 0; i < 4; i++) {  //poker設初值
        for (int j = 0; j < 13; j++) {
            poker[i][j] = 0;
        }
    }
    for (int j = 0; j < 5; j++) {  //5張牌
        do {
            /*
            flo=(int)rand()%4;
            num=(int)rand()%13;
            */
            all = (int)rand() % 52;
            flo = all / 13;
            num = all % 13;
        } while (poker[flo][num] == 1);
        poker[flo][num] = 1;
        allPoker[j] = all;
        //allPoker[j] = pflo[flo]+punm[num];
    }


}


//int straight_Flush(int array[]) {//同花順),五張順序一樣連續顏色
//    int straight_Flush = 0;
//    int conti_ = 0;
//    conti_ = flush(array) + straight(array);
//    if (conti_ == 2) {
//        straight_Flush = 1;
//    }
//    return straight_Flush;
//
//}
//
//int four_of_a_kind(int array[]) {//鐵支),四張一樣
//    int four_of_a_kind = 0;
//    int same = 0;
//    for (int i = 0; i < 5; i++) {
//
//        if (array[i] == array[i + 1]) {
//            same++;
//        }
//    }
//    if (same == 3 || same == 2) {
//        four_of_a_kind = 1;
//    }
//    return four_of_a_kind;
//}
//int full_House(int array[]) {//葫蘆),三張相同 對子
//
//    int full_house = 0;
//    if (check_pair(array) >= 1 && four_of_a_kind(array) == 1) {
//        full_house = 1;
//    }
//    return full_house;
//
//}
//
//int check_pair(int array[]) { //判斷有幾對牌的點數一樣
//    int P = 0;
//    for (int i = 0; i < 5; i++)
//        for (int j = i + 1; j < 5; j++)
//            if ((array[i] - array[j]) % 13 == 0) P++;
//    return P;
//}
//
//int flush(int array[]) {//同花),同一花色
//    int flush = 1;
//    int same = 0;
//    for (int i = 0; i < 5; i++) {
//
//        flush = abs(array[i] / 13 - array[i + 1] / 13) + flush;
//    }
//    if (flush > 0) flush = 0; //F = 1 表示同花,F = 0 表示非同花
//
//    return flush;
//
//}
//

int straight(int array11[]) {//順子). 五張順序  //boolean

    //int abc[5]= { 0,14,15,29,43 };
    int straight = 0;
    for (int i = 0; i < 5; i++) {

        array11[i]= array11[i]%13;

    }
    for (int i = 0; i < 4; i++) {

        straight += abs(array11[i] - array11[i + 1]);

    }
    if (straight != 4) {
        straight = 0;
    }
    else {
        straight = 1;
    }
    

    return  straight ;


}

int cmp_int(const void* _a,const void* _b)//引數格式固定
{
    int* a = (int*)_a;    //強制型別轉換
    int* b = (int*)_b;
    return *a - *b;
}

int main()
{
    cout << "Please enter the rounds:";
    int rounds;
    cin >> rounds;
    int straight_Flush11 = 0;
    int four_of_a_kind11 = 0;
    int full_house11 = 0;
    int flush11 = 0;
    int straight11 = 0;
    
    for (int i = 0; i < rounds; i++) {
        
        deal();
        cout << endl;
        cout << i + 1<<".";
        for (int j = 0; j < 5; j++) {
            
            cout << allPoker[j] << "\t";
            int flo = allPoker[j] / 13;
            int num = allPoker[j] % 13;
            //cout << pflo[flo] + pnum[num] << "\t";

        }
        cout << endl;
        qsort(allPoker,5,sizeof(allPoker[0]),cmp_int);
        cout << endl;
        cout << i + 1 << ".";
    for (int j = 0; j < 5; j++) {
        
        cout << allPoker[j] << "\t";
        int flo = allPoker[j] / 13;
        int num = allPoker[j] % 13;
        //cout << pflo[flo] + pnum[num] << "\t";

    }
    cout << endl;

       /* straight_Flush11 += straight_Flush(allPoker);
        four_of_a_kind11 += four_of_a_kind(allPoker);
        full_house11 += full_House(allPoker);
        flush11 += flush(allPoker);*/
        straight11 += straight(allPoker);
        
    }

    cout << "after" << rounds << endl;
    cout << "the number of occurrences is " << straight_Flush11 << "for straight flush." << endl;
    cout << "the number of occurrences is " << four_of_a_kind11 << "for four_of_a_kind." << endl;
    cout << "the number of occurrences is " << full_house11 << "for full_house." << endl;
    cout << "the number of occurrences is " << flush11 << "for flush." << endl;
    cout << "the number of occurrences is " << straight11 << "for straight." << endl;



    /*for (int j = 0; j < 5; j++) {
        cout << allPoker[j] << "\t";
        int flo = allPoker[j] / 13;
        int num = allPoker[j] % 13;
        cout <<  pflo[flo]+ pnum[num] << "\t";

    }*/

    //cout << endl;

    /*
    for (int j = 0; j < 5; j++) {
        cout << allPoker[j] << "\t";
        int flo = allPoker[j] / 13;
        int num = allPoker[j] % 13;
        cout << pflo[flo] + pnum[num] << "\t";

    }
    */
    return 0;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...