此程序比上一次发表的发牌程序在时间和空间上都有很大的改进,算法更有效,源代码更精简。欢迎各位指教。跳骚侦察来看看怎么样?
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
main()
{
char card[5][50];
char cardcard[]={'2','2','3','3','4','4','5','5','6','6','7','7','8','8','9','9','1','1','J','J','Q','Q','K','K','A','A'};
char cardjoker[]={'j','r','j','r','J','R','J','R'}; /*jr 表示小王,JR表示大王*/
char *pr[]={"East","South","West","North"};
int i,j,p[5],player,p_max[5]={25,25,25,25,8};/*p[] 存储玩家牌的数目,player表示玩家,4表示底牌*/
printf("\n\n\n ******************************************************************************\n");
printf(" * *\n");
printf(" * Copyright belonged to mb459 *\n");
printf(" * mb459@sohu.com QQ:83981459 *\n");
printf(" * *\n");
printf(" ******************************************************************************\n\n\n\n");
for(i=0;i<5;i++)p[i]=0;
srand((unsigned)time(NULL));
for(i=3;i<7;i++)
for(j=0;j<26;j++)
{player=rand()%108/25; /*随机生成将要得到当前牌的玩家*/
if(p[player]==p_max[player])
{
j--;
continue;
}
else
{
card[player][p[player]*2]=i;
card[player][p[player]*2+1]=cardcard[j];
p[player]++;
}
}
for(i=0;i<7;i+=2) /*处理大小王*/
{player=rand()%108/25;
if(p[player]==p_max[player])
{
i-=2;
continue;
}
else {
card[player][p[player]*2]=cardjoker[i];
card[player][p[player]*2+1]=cardjoker[i+1];
p[player]++;
}
}
for(i=0;i<4;i++) /*打印玩家的牌*/
{
printf("%s:\n",pr[i]);
for(j=0;j<50;j++)
{
printf("%c",card[i][j]);
if(card[i][j]=='1')printf("0");
}
printf("\n");
}
printf("The left cards:\n"); /*打印底牌*/
for(i=0;i<16;i++)
{
printf("%c",card[4][i]);
if(card[4][i]=='1')printf("0");
}
printf("\n");
getche();
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |