嗯嗯
嗯嗯[此贴子已经被作者于2018-3-13 16:24编辑过]
#include <stdio.h> #include<time.h> #include<windows.h> #include<stdlib.h> int cards[20]; void showcards(int i,int j); int bullpoint(int m,int n); int main(void) { int i,m,n,c1,c2; int flag[4][13]={0}; srand((unsigned)time(NULL)); for(i=0;i<20;i+=2) { do { m=rand()%4+13; n=rand()%13; } while(flag[m-13][n]); cards[i]=m; cards[i+1]=n; flag[m-13][n]=1; } printf("我的牌是:"); showcards(0,9); putchar(10); printf("你的牌是:"); showcards(10,19); c1=bullpoint(1,9); c2=bullpoint(11,19); putchar(10); if(c1>c2) { if(c1>=3*13) //用13进制的十位表示那种牌,个位表示这个顺子到几、三个几、四个几 printf("顺子我赢!"); else if(c1>=2*13) printf("四带一我赢!"); else if(c1>=13) printf("三带二我赢!"); else printf("我赢!"); } else if(c1<c2) { if(c2>=3*13) printf("顺子你赢!"); else if(c2>=2*13) printf("四带一你赢!"); else if(c2>=13) printf("三带二你赢!"); else printf("你赢!"); } else printf("平手!"); putchar(10); return 0; } void showcards(int i,int j) { int ii; for(ii=i;ii<=j;++ii) { if(cards[ii]==13) putchar(3); if(cards[ii]==14) putchar(6); if(cards[ii]==15) putchar(4); if(cards[ii]==16) putchar(5); if(cards[ii]<9) printf("%d ",cards[ii]+2); if(cards[ii]==9) printf("J "); if(cards[ii]==10) printf("Q "); if(cards[ii]==11) printf("K "); if(cards[ii]==12) printf("A "); } } int bullpoint(int m,int n) { int i,j,t,point1,point2,count1=1; for(i=m;i<=n;i+=2) { for(j=i+2;j<=n;j+=2) { if(cards[i]<cards[j]) { t=cards[i]; cards[i]=cards[j]; cards[j]=t; } } } for(i=m;i<=n-2;i+=2) //顺子 如果cards[i-1]和后面的cards[i+1]、cards[i31]这些再相比较可以得出是不是同花顺或是同花 { if(cards[i]-1!=cards[i+2]) break; } if(i==n) { point1=3; point2=cards[m]-4; } for(i=m;i<=n-2;i+=2) //两种牌(四带一、三带二) 如果是三种牌(三带一带一、两对) { if(cards[i]!=cards[i+2]) count1++; } if(count1==2) { if(cards[m+2]==cards[m+4]&&cards[m+4]==cards[m+6]) { point1=2; point2=cards[m+2]; } else if(cards[m+2]==cards[m+4]) { point1=1; point2=cards[m]; } else { point1=1; point2=cards[m+6]; } } else { point1=0; point2=cards[m]; } return (point1*13+point2); }
[此贴子已经被作者于2018-3-12 08:03编辑过]