I want to solve a problem that is about the poker game. The player needs to type the rounds he wants to play and there are five cards dealt randomly each round. The programming needs to judge the five suits, including straight flush, four of a kind, full house, flush, and straight. Finally, print the total number of each occurrence.
the problem enter image description here
I try to print the result of each round for debugging, but I find that the result of each round is the same. However, I set the breaking up at the 152 and 178 lines, the result is not the same. I don't know how to fix it.
with the breaking points enter image description here
without breaking points 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;
}