资源描述:
《洗牌与发牌程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include"stdio.h"#include"time.h"#include"stdlib.h"into[52]={102,103,104,105,106,107,108,109,110,111,112,113,114,202,203,204,205,206,207,208,209,210,211,212,213,214,302,303,304,305,306,307,308,309,310,311,312,313,314,402,403,404,405,406,407,408,409,410,411,412,413,414},card2[13
2、][4],a,H,t,i,j,k;voidsjfp(){//随机分配模块。srand((unsigned)time(NULL));//将随机函数中的seed参数定义为当前的时间。for(j=0;j<4;j++){for(i=0;i<13;i++){a=rand()%52;//从0到51中按照当前时间的seed函数赋予a相应的值。card2[i][j]=o[a];o[a]=0;}}}//将已经发出去的牌标记为0以方便检查模块的工作。voidcheck(){//检查模块。srand((unsigned)time(NULL));for(j=0;j<4;j+
3、+){for(i=0;i<13;i++){if(card2[i][j]==0)//判断当前检查的牌是否为已经发出去过的牌。{a=rand()%52;card2[i][j]=o[a];//重新对当前检查的牌进行随机分配。o[a]=0;i--;}}}}voidpx(){//排序模块。srand((unsigned)time(NULL));for(j=0;j<4;j++){for(i=0;i<13;i++){for(k=i+1;k<13;k++){if(card2[i][j]4、d2[k][j];card2[k][j]=card2[i][j];card2[i][j]=t;}}}}}voidprint(){//输出模块。for(j=0;j<4;j++){for(i=0;i<13;i++){H=card2[i][j]/100;//将包含信息的"牌"中的信息读出。card2[i][j]=card2[i][j]%100;switch(H){//输出花色。case1:printf("黑桃");break;case2:printf("红心");break;case3:printf("方片");break;case4:printf("梅花
5、");break;}switch(card2[i][j]){//输出非数字牌。case14:printf("A");break;case11:printf("J");break;case12:printf("Q");break;case13:printf("K");break;default:printf("%d",card2[i][j]);break;}if(i==12)//一个人输出满13张牌后换行输出另一个人的牌。printf("");}}}voidmain(void){sjfp();check();px();print();}