我有些如何得到它的工作,但我仍然有排序和製作對的問題,以便我可以確定贏家。如何填充,洗牌,處理紙牌遊戲
將它們配對(對具有相同價值的卡片)。例如心形王牌&黑桃王牌成對。 然後我計算這些對。最高雙手勝。
這就是我正在嘗試配對,但..我仍然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