我有些如何得到它的工作,但我仍然有排序和制作对的问题,以便我可以确定赢家。如何填充,洗牌,处理纸牌游戏
将它们配对(对具有相同价值的卡片)。例如心形王牌&黑桃王牌成对。 然后我计算这些对。最高双手胜。
这就是我正在尝试配对,但..我仍然rellyy坚持我如何开始比较,使配对。
这是我所期望的结果是,每手的方式:
手1: 黑桃六,是黑钻的 七,红 黑桃八,是黑 十红心,红 女王黑桃,是黑 数对:0
手2: 三锹,是钻石的黑色 五,红 俱乐部的五,是黑色 九钻石,是红皇后 钻石,红 数对:1 最高的对是:五
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct card {
const char *face;
const char *suit;
const char *color;
};
typedef struct card Card;
typedef unsigned char pairs;
void fillDeck(Card * const, const char *[], const char *[] ,const char *[]);
void shuffle(Card * const);
void print(const Card * const);
pairs findpairs(card *hand); /* finds any pairs in a hand */
int main()
{
int hand,cd,winner;
card hands[5][5],handssorted[5][5];
pairs numpairs[5],highest;
Card deck[52];
const char *face[] = { "Ace", "Two", "Three", "Four", "Five","Six", "Seven",
"Eight", "Nine", "Ten","Jack", "Queen", "King"};
const char *suit[] = { "Hearts", "Diamonds", "Clubs", "Spades"};
const char *color[]= {"Black","Red"};
srand(time(NULL));
fillDeck(deck, face, suit, color);
print(deck);
printf("\n ---------------------------------------------------------- \n");
shuffle(deck);
print(deck);
for(cd=0;cd<5;cd++)
{
}
for(hand=0;hand<5;hand++)
{
/* sort the hands here */
numpairs[hand]=findpairs(handssorted[hand]);
printf("Hand %i:\n",hand+1);
/* print the hands here */
/* print the number and value of any pairs here */
}
/* determine the winner and print it */
system("pause");
return 0;
}
//----------------------------------------------------------------------------- void fillDeck(Card * const wDeck, const char * wFace[], const char * wSuit[],
const char * wColor[])
{
int i;
for (i = 0; i <= 51; i++) {
wDeck[i].face = wFace[ i % 13 ];
wDeck[i].suit = wSuit[ i/13 ];
wDeck[i].color = wColor[i%2];
// if()
// wDeck[i].suit = wSuit[ i/13 ];
}
}
//------------------------------------------------------------------
void shuffle(Card * const wDeck)
{
int i, j;
Card temp;
for (i = 0; i <= 51; i++) {
j = rand() % 52;
temp = wDeck[ i ];
wDeck[ i ] = wDeck[ j ];
wDeck[ j ] = temp;
}
}
//---------------------------------
void print(const Card * const wDeck)
{
int i;
for (i = 0; i <= 51; i++){
printf("\t%s\t of \t%-8s is \t%s \n \t", wDeck[i].face,
wDeck[i].suit,wDeck[i].color,
(i + 1) % 2 ? '\t' : '\n');}
}
//--------------------------------------------------------------------------
pairs findpairs(card *hand)
{
pairs numpairs=0;
for (int i = 0; i <= 5; i++){
if (hand[i].face ==)
}
return numpairs;
}
西装和颜色不是独立的。 – 2010-08-08 01:32:46
请了解如何正确设置您的文章的格式。 http://stackoverflow.com/editing-help – spender 2010-08-08 01:33:31
你告诉我们预期的结果,但不是什么实际结果。 – zneak 2010-08-08 01:41:47