# 请在此提交课程设计报告，注意只允许提交一次。

``````#include<stdio.h>
#include<stdlib.h>
#include<time.h>
struct
{
int color;
int point;
}pai[53];
struct personal
{
int color;
int point;
}s;
struct
{
struct personal card[18];
}people[3];
void paixu(int num,int sum)
{
int i,j;
for(i=1;i<sum;i++)
for(j=1;j<sum-i+1;j++)
{
if(people[num].card[j].color>people[num].card[j+1].color)
{
s=people[num].card[j];
people[num].card[j]=people[num].card[j+1];
people[num].card[j+1]=s;
}
}
for(i=1;i<sum;i++)
for(j=1;j<sum-i+1;j++)
{
if((people[num].card[j].color==people[num].card[j+1].color)&&(people[num].card[j].point<people[num].card[j+1].point))
{
int t3;
t3=people[num].card[j].point;
people[num].card[j].point=people[num].card[j+1].point;
people[num].card[j+1].point=t3;
}
}
}
int end=0;/*结束标志*/
int logo[4]={0};/*判断上次是否出牌*/
int s2[4];/*所选卡牌序号*/
int question1=NULL,question2=NULL;/*当前所出卡牌*/
int mark[4]={0};
int begin[4]={0};
void game2(int num,int num1,int num2,int sum)
{
int i,j;
while(begin[num])
{
begin[num1]=1;
begin[num2]=1;
for(i=1;i<=sum;)
{
for(j=0;j<s1[num];j++)
{
goto M2;
}
if((people[num].card[i].color==question1&&people[num].card[i].point>question2)||(logo[num1]==0&&logo[num2]==0))
{
logo[num]=1;
break;
}
else logo[num]=0;
M2:  i++;
}
if(logo[num])
{
if(logo[num1]==0&&logo[num2]==0)  /*如果对手都要不起，则从右到左出牌*/
{
for(i=sum;i>=1;i)
{
for(j=0;j<s1[num];j++)
{
goto Q2;
}
if(j>=s1[num])
{
question1=people[num].card[i].color;
question2=people[num].card[i].point;
s1[num]++;
if(s1[num]==sum)
{
printf("\n\n\t\t\t%d号人机获胜！\n",num);
end=1;
}
break;
}
Q2:i--;
}
if(end==1)
break;
}
if(!(logo[num1]==0&&logo[num2]==0)&&(people[num].card[i].color==question1&&people[num].card[i].point>question2))               /*否则，寻找能管上的最小卡牌*/
{
for(i=sum;i>=1;)
{
for(j=0;j<s1[num];j++)
{
{
goto L2;
}
}
if(people[num].card[i].color==question1&&people[num].card[i].point>question2)
{
s1[num]++;
if(s1[num]==sum)
{
printf("\n\n\t\t\t%d号人机获胜！\n",num);
end=1;
break;
}
question1=people[num].card[i].color;
question2=people[num].card[i].point;
break;
}
L2:i--;
}
}
printf("%d号人机出牌：\n",num);
if(question1=='A')      /*打印玩家所出卡牌*/
printf("\tCLUB\n");
else if(question1=='B')
printf("\tDIAMOND\n");
else if(question1=='C')
printf("\tHEART\n");
else if(question1=='D')
printf("\t");
if(question2==11)
printf("J         ");
else if(question2==12)
printf("Q         ");
else if(question2==13)
printf("K         ");
else if(question2==14)
printf("A         ");
else
printf("%-10d",question2);
printf("\n\n");
system("pause");
}
else
{
printf("%d号人机出牌：\n",num);
printf("\t不要！\n");
printf("\n\n");
system("pause");
}
printf("\n\n\n");
break;
}
return;
}
void game1(int num,int num1,int num2,int sum)
{
while(begin[num])
{
begin[num1]=1;
begin[num2]=1;
int i,j;                                                               /*玩家出牌*/
printf("%d号玩家:\n",num);
printf("卡牌序号\n");
printf("\t");
for(i=1;i<=sum;)
{
for(j=0;j<=s1[num];j++)
{
goto s;
}
printf("%-10d",i);
s:i++;
}
printf("\n\n");
for(i=1;i<=sum;)
{
for(j=0;j<=s1[num];j++)
{
goto n;
}
if(people[num].card[i].color=='A')
printf("    CLUB  ");
else if(people[num].card[i].color=='B')
printf("   DIAMOND");
else if(people[num].card[i].color=='C')
printf("    HEART ");
else if(people[num].card[i].color=='D')
n:  i++;
}
printf("\n");
printf("\t");
for(i=1;i<=sum;)
{
for(j=0;j<s1[num];j++)
{
goto k;
}
if(people[num].card[i].point==11)
printf("J         ");
else if(people[num].card[i].point==12)
printf("Q         ");
else if(people[num].card[i].point==13)
printf("K         ");
else if(people[num].card[i].point==14)
printf("A         ");
else
printf("%-10d",people[num].card[i].point);
k:  i++;
}
printf("\n");
printf("\n");
printf("\n");
for(i=1;i<=sum;)
{
for(j=0;j<s1[num];j++)
{
goto m;
}
if((people[num].card[i].color==question1&&people[num].card[i].point>question2)||(logo[num1]==0&&logo[num2]==0))
{
logo[num]=1;
break;
}
else logo[num]=0;
m:  i++;
}
if(logo[num])
{
printf("请选择一张卡牌的序号：\n");
l:  fflush(stdin);
scanf("%d",&s2[num]);
char ch;
scanf("%c",&ch);
if(ch!='\n')
{
printf("请检查输入是否合理！\n");
goto l;
}
if(!(s2[num]>=1&&s2[num]<=18))
{
printf("请检查输入是否合理！\n");
fflush(stdin);
goto l;
}
for(i=0;i<s1[num];i++)
{
{
printf("请检查输入是否合理！\n");
fflush(stdin);
goto l;
}
}
if((people[num].card[s2[num]].color==question1&&people[num].card[s2[num]].point>question2)||(logo[num1]==0&&logo[num2]==0))/*判断出牌是否合理*/
{
s1[num]++;
if(s1[num]==sum)
{
printf("\n\n\t\t\t%d号玩家获胜！\n",num);
end=1;
break;
}
question1=people[num].card[s2[num]].color;
question2=people[num].card[s2[num]].point;
}
else
{
printf("\t请检查输入是否合理！\n");
s1[num]--;
goto l;
}

printf("%d号玩家出牌：\n",num);
if(question1=='A')      /*打印玩家所出卡牌*/
printf("\tCLUB\n");
else if(question1=='B')
printf("\tDIAMOND\n");
else if(question1=='C')
printf("\tHEART\n");
else if(question1=='D')
if(question2==11)
printf("\tJ\n");
else if(question2==12)
printf("\tQ\n");
else if(question2==13)
printf("\tK\n");
else if(question2==14)
printf("\tA\n");
else
printf("\t%d\n",question2);
}
else
{
printf("%d号玩家出牌：\n",num);
printf("\t不要！\n");
system("pause");
}
printf("\n\n\n");
break;
}
return ;
}
int main()
{
int Color[4]={'A','B','C','D'};
int point[13]={2,3,4,5,6,7,8,9,10,11,12,13,14};
int i,j,k=1;                                        /*制造52张不同的牌*/
for(i=0;i<4;i++)
for(j=0;j<13;j++)
{
pai[k].color=Color[i];
pai[k].point=point[j];
k++;
}
int a[100];                                                     /*发牌阶段*/
int k1=1,k2=1,k3=1;
srand(time(NULL));
for(i=1;i<=52;)
{
int j;
int n;
n=rand()%(52-1+1)+1;
for(j=1;j<i;j++)
{
if(a[j]==n)
{
break;
}
}
if(j>=i)
{
a[i]=n;
if(i%3==0)
{
people[3].card[k3].color=pai[n].color;
people[3].card[k3].point=pai[n].point;
k3++;
}
if(i%3==1)
{
people[1].card[k1].color=pai[n].color;
people[1].card[k1].point=pai[n].point;
k1++;
}
if(i%3==2)
{
people[2].card[k2].color=pai[n].color;
people[2].card[k2].point=pai[n].point;
k2++;
}
i++;
}
}
printf("\n");
/*卡牌排序*/
paixu(1,18);
paixu(2,17);
paixu(3,17);

printf("*********************************************************\n");                  /*选择游戏模式*/
printf("*                                                       *\n");
printf("*                    Club Game                          *\n");
printf("*                                                       *\n");
printf("*                 选择1：三人模式                       *\n");
printf("*                 选择2：人机模式                       *\n");
printf("*                 选择0：退出游戏                       *\n");
printf("*********************************************************\n");
int Mode;
while(1)
{
char a;
scanf("%d",&Mode);
scanf("%c",&a);
if(Mode==0)
return 0;
if(a!='\n')
{
printf("\n请选择正确模式!或者输入数字 0 退出游戏!\n");
fflush(stdin);
continue;
}
if(Mode!=1&&Mode!=2)
{
printf("\n请选择正确模式!或者输入数字 0 退出游戏!\n");
fflush(stdin);
}
else
break;
}

/*三人模式*/

if(Mode==1)
{
system("cls");                                                                            /*出牌阶段*/
for(i=1;i<=18;i++)                                            /*判断哪位玩家先出牌*/
{
if(people[1].card[i].color=='A'&&people[1].card[i].point==2)
{
mark[1]=1;
begin[1]=1;
}
}
for(i=1;i<=17;i++)
{
if(people[2].card[i].color=='A'&&people[2].card[i].point==2)
{
mark[2]=1;
begin[2]=1;
}
}
for(i=1;i<=17;i++)
{
if(people[3].card[i].color=='A'&&people[3].card[i].point==2)
{
mark[3]=1;
begin[2]=1;
}
}
while(end==0)
{
game1(1,2,3,18);
if(end==1)
continue;
game1(2,3,1,17);
if(end==1)
continue;
game1(3,1,2,17);
}
}

/*人机模式*/

if(Mode==2)
{
system("cls");
for(i=1;i<=18;i++)                                            /*判断哪位玩家先出牌*/
{
if(people[1].card[i].color=='A'&&people[1].card[i].point==2)
{
mark[1]=1;
begin[1]=1;
}
}
for(i=1;i<=17;i++)
{
if(people[2].card[i].color=='A'&&people[2].card[i].point==2)
{
mark[2]=1;
begin[2]=1;
}
}
for(i=1;i<=17;i++)
{
if(people[3].card[i].color=='A'&&people[3].card[i].point==2)
{
mark[3]=1;
begin[3]=1;
}
}
while(end==0)
{
game1(1,2,3,18);
if(end==1)
continue;
game2(2,1,3,17);
if(end==1)
continue;
game2(3,1,2,17);
}

}
}
``````

``````#include<stdio.h>
#include<stdlib.h>
#include<time.h>
struct
{
int color;
int point;
}pai[53];
struct personal
{
int color;
int point;
}s;
struct
{
struct personal card[18];
}people[3];
void paixu(int num,int sum)
{
int i,j;
for(i=1;i<sum;i++)
for(j=1;j<sum-i+1;j++)
{
if(people[num].card[j].color>people[num].card[j+1].color)
{
s=people[num].card[j];
people[num].card[j]=people[num].card[j+1];
people[num].card[j+1]=s;
}
}
for(i=1;i<sum;i++)
for(j=1;j<sum-i+1;j++)
{
if((people[num].card[j].color==people[num].card[j+1].color)&&(people[num].card[j].point<people[num].card[j+1].point))
{
int t3;
t3=people[num].card[j].point;
people[num].card[j].point=people[num].card[j+1].point;
people[num].card[j+1].point=t3;
}
}
}
int end=0;/*结束标志*/
int logo[4]={0};/*判断上次是否出牌*/
int s2[4];/*所选卡牌序号*/
int question1=NULL,question2=NULL;/*当前所出卡牌*/
int mark[4]={0};
int begin[4]={0};
void game2(int num,int num1,int num2,int sum)
{
int i,j;
while(begin[num])
{
begin[num1]=1;
begin[num2]=1;
for(i=1;i<=sum;)
{
for(j=0;j<s1[num];j++)
{
goto M2;
}
if((people[num].card[i].color==question1&&people[num].card[i].point>question2)||(logo[num1]==0&&logo[num2]==0))
{
logo[num]=1;
break;
}
else logo[num]=0;
M2:  i++;
}
if(logo[num])
{
if(logo[num1]==0&&logo[num2]==0)  /*如果对手都要不起，则从右到左出牌*/
{
for(i=sum;i>=1;i)
{
for(j=0;j<s1[num];j++)
{
goto Q2;
}
if(j>=s1[num])
{
question1=people[num].card[i].color;
question2=people[num].card[i].point;
s1[num]++;
if(s1[num]==sum)
{
printf("\n\n\t\t\t%d号人机获胜！\n",num);
end=1;
}
break;
}
Q2:i--;
}
if(end==1)
break;
}
if(!(logo[num1]==0&&logo[num2]==0)&&(people[num].card[i].color==question1&&people[num].card[i].point>question2))               /*否则，寻找能管上的最小卡牌*/
{
for(i=sum;i>=1;)
{
for(j=0;j<s1[num];j++)
{
{
goto L2;
}
}
if(people[num].card[i].color==question1&&people[num].card[i].point>question2)
{
s1[num]++;
if(s1[num]==sum)
{
printf("\n\n\t\t\t%d号人机获胜！\n",num);
end=1;
break;
}
question1=people[num].card[i].color;
question2=people[num].card[i].point;
break;
}
L2:i--;
}
}
printf("%d号人机出牌：\n",num);
if(question1=='A')      /*打印玩家所出卡牌*/
printf("\tCLUB\n");
else if(question1=='B')
printf("\tDIAMOND\n");
else if(question1=='C')
printf("\tHEART\n");
else if(question1=='D')
printf("\t");
if(question2==11)
printf("J         ");
else if(question2==12)
printf("Q         ");
else if(question2==13)
printf("K         ");
else if(question2==14)
printf("A         ");
else
printf("%-10d",question2);
printf("\n\n");
system("pause");
}
else
{
printf("%d号人机出牌：\n",num);
printf("\t不要！\n");
printf("\n\n");
system("pause");
}
printf("\n\n\n");
break;
}
return;
}
void game1(int num,int num1,int num2,int sum)
{
while(begin[num])
{
begin[num1]=1;
begin[num2]=1;
int i,j;                                                               /*玩家出牌*/
printf("%d号玩家:\n",num);
printf("卡牌序号\n");
printf("\t");
for(i=1;i<=sum;)
{
for(j=0;j<=s1[num];j++)
{
goto s;
}
printf("%-10d",i);
s:i++;
}
printf("\n\n");
for(i=1;i<=sum;)
{
for(j=0;j<=s1[num];j++)
{
goto n;
}
if(people[num].card[i].color=='A')
printf("    CLUB  ");
else if(people[num].card[i].color=='B')
printf("   DIAMOND");
else if(people[num].card[i].color=='C')
printf("    HEART ");
else if(people[num].card[i].color=='D')
n:  i++;
}
printf("\n");
printf("\t");
for(i=1;i<=sum;)
{
for(j=0;j<s1[num];j++)
{
goto k;
}
if(people[num].card[i].point==11)
printf("J         ");
else if(people[num].card[i].point==12)
printf("Q         ");
else if(people[num].card[i].point==13)
printf("K         ");
else if(people[num].card[i].point==14)
printf("A         ");
else
printf("%-10d",people[num].card[i].point);
k:  i++;
}
printf("\n");
printf("\n");
printf("\n");
for(i=1;i<=sum;)
{
for(j=0;j<s1[num];j++)
{
goto m;
}
if((people[num].card[i].color==question1&&people[num].card[i].point>question2)||(logo[num1]==0&&logo[num2]==0))
{
logo[num]=1;
break;
}
else logo[num]=0;
m:  i++;
}
if(logo[num])
{
printf("请选择一张卡牌的序号：\n");
l:  fflush(stdin);
scanf("%d",&s2[num]);
char ch;
scanf("%c",&ch);
if(ch!='\n')
{
printf("请检查输入是否合理！\n");
goto l;
}
if(!(s2[num]>=1&&s2[num]<=18))
{
printf("请检查输入是否合理！\n");
fflush(stdin);
goto l;
}
for(i=0;i<s1[num];i++)
{
{
printf("请检查输入是否合理！\n");
fflush(stdin);
goto l;
}
}
if((people[num].card[s2[num]].color==question1&&people[num].card[s2[num]].point>question2)||(logo[num1]==0&&logo[num2]==0))/*判断出牌是否合理*/
{
s1[num]++;
if(s1[num]==sum)
{
printf("\n\n\t\t\t%d号玩家获胜！\n",num);
end=1;
break;
}
question1=people[num].card[s2[num]].color;
question2=people[num].card[s2[num]].point;
}
else
{
printf("\t请检查输入是否合理！\n");
s1[num]--;
goto l;
}

printf("%d号玩家出牌：\n",num);
if(question1=='A')      /*打印玩家所出卡牌*/
printf("\tCLUB\n");
else if(question1=='B')
printf("\tDIAMOND\n");
else if(question1=='C')
printf("\tHEART\n");
else if(question1=='D')
if(question2==11)
printf("\tJ\n");
else if(question2==12)
printf("\tQ\n");
else if(question2==13)
printf("\tK\n");
else if(question2==14)
printf("\tA\n");
else
printf("\t%d\n",question2);
}
else
{
printf("%d号玩家出牌：\n",num);
printf("\t不要！\n");
system("pause");
}
printf("\n\n\n");
break;
}
return ;
}
int main()
{
int Color[4]={'A','B','C','D'};
int point[13]={2,3,4,5,6,7,8,9,10,11,12,13,14};
int i,j,k=1;                                        /*制造52张不同的牌*/
for(i=0;i<4;i++)
for(j=0;j<13;j++)
{
pai[k].color=Color[i];
pai[k].point=point[j];
k++;
}
int a[100];                                                     /*发牌阶段*/
int k1=1,k2=1,k3=1;
srand(time(NULL));
for(i=1;i<=52;)
{
int j;
int n;
n=rand()%(52-1+1)+1;
for(j=1;j<i;j++)
{
if(a[j]==n)
{
break;
}
}
if(j>=i)
{
a[i]=n;
if(i%3==0)
{
people[3].card[k3].color=pai[n].color;
people[3].card[k3].point=pai[n].point;
k3++;
}
if(i%3==1)
{
people[1].card[k1].color=pai[n].color;
people[1].card[k1].point=pai[n].point;
k1++;
}
if(i%3==2)
{
people[2].card[k2].color=pai[n].color;
people[2].card[k2].point=pai[n].point;
k2++;
}
i++;
}
}
printf("\n");
/*卡牌排序*/
paixu(1,18);
paixu(2,17);
paixu(3,17);

printf("*********************************************************\n");                  /*选择游戏模式*/
printf("*                                                       *\n");
printf("*                    Club Game                          *\n");
printf("*                                                       *\n");
printf("*                 选择1：三人模式                       *\n");
printf("*                 选择2：人机模式                       *\n");
printf("*                 选择0：退出游戏                       *\n");
printf("*********************************************************\n");
int Mode;
while(1)
{
char a;
scanf("%d",&Mode);
scanf("%c",&a);
if(Mode==0)
return 0;
if(a!='\n')
{
printf("\n请选择正确模式!或者输入数字 0 退出游戏!\n");
fflush(stdin);
continue;
}
if(Mode!=1&&Mode!=2)
{
printf("\n请选择正确模式!或者输入数字 0 退出游戏!\n");
fflush(stdin);
}
else
break;
}

/*三人模式*/

if(Mode==1)
{
system("cls");                                                                            /*出牌阶段*/
for(i=1;i<=18;i++)                                            /*判断哪位玩家先出牌*/
{
if(people[1].card[i].color=='A'&&people[1].card[i].point==2)
{
mark[1]=1;
begin[1]=1;
}
}
for(i=1;i<=17;i++)
{
if(people[2].card[i].color=='A'&&people[2].card[i].point==2)
{
mark[2]=1;
begin[2]=1;
}
}
for(i=1;i<=17;i++)
{
if(people[3].card[i].color=='A'&&people[3].card[i].point==2)
{
mark[3]=1;
begin[2]=1;
}
}
while(end==0)
{
game1(1,2,3,18);
if(end==1)
continue;
game1(2,3,1,17);
if(end==1)
continue;
game1(3,1,2,17);
}
}

/*人机模式*/

if(Mode==2)
{
system("cls");
for(i=1;i<=18;i++)                                            /*判断哪位玩家先出牌*/
{
if(people[1].card[i].color=='A'&&people[1].card[i].point==2)
{
mark[1]=1;
begin[1]=1;
}
}
for(i=1;i<=17;i++)
{
if(people[2].card[i].color=='A'&&people[2].card[i].point==2)
{
mark[2]=1;
begin[2]=1;
}
}
for(i=1;i<=17;i++)
{
if(people[3].card[i].color=='A'&&people[3].card[i].point==2)
{
mark[3]=1;
begin[3]=1;
}
}
while(end==0)
{
game1(1,2,3,18);
if(end==1)
continue;
game2(2,1,3,17);
if(end==1)
continue;
game2(3,1,2,17);
}

}
}
``````