我在我的计算机科学课上有一项作业(我几周前发布了这个问题,但它的解释方式不适合我应该做的程序)。我已经有一个程序可以在这里洗牌和发牌。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void shuffle( int [][ 13 ] );
void deal ( const int[][ 13 ], const char *[], const char *[] );
int main()
{
const char *suit[4] ={"Hearts","Diamonds","Clubs","Spades"};
const char *face[13] ={"Ace", "Duece", "Three", "Four", "Five", "Six",
"Seven", "Eight","Nine", "Ten", "Jack", "Queen", "King"};
int deck[4][13] = {0};
int row, column, card = 1;
for( row = 0; row <= 3; row++ )
{
for(column = 0; column <= 12; column++)
{
deck[row][column] = card;
card++;
}
}
srand(time(0));
shuffle(deck);
deal(deck, face, suit);
return 0;
}
void shuffle( int wDeck[][13] )
{
int row, column, randomColumn, randomRow, card = 1, counter1, counter2, hold;
for( counter1 = 0; counter1 <= 3; counter1++)
{
for(counter2 = 0; counter2 <= 12; counter2++)
{
randomColumn = rand() % 13;
randomRow = rand() % 4;
hold = wDeck[counter1][counter2];
wDeck[counter1][counter2] = wDeck[randomRow][randomColumn];
wDeck[randomRow][randomColumn] = hold;
}
}
}
void deal( const int wDeck[][13], const char *wFace[], const char *wSuit[] )
{
int card, row, column;
for ( card = 1; card <= 52; card++ )
for (row = 0; row <= 3; row++ )
for ( column = 0; column <= 12; column++ )
if( wDeck[row][column] == card )
{
printf("%5s of %-8s%c",wFace[ column ], wSuit[row], card % 2 == 0 ? '\n' : '\t');
break;
}
}
我应该修改发牌功能以发一张 5 张牌的扑克手,然后检查他们有什么“等级”扑克手(两种,同花)。我的老师提到创建一个单独的双脚本数组来做到这一点,但我可以用不同的方式来做。问题是,我必须使用当前的牌组/洗牌设置来做到这一点。谁能解释如何做到这一点?如果它效率低下也没关系,只要它有效。