두지주 그룹 시뮬레이션 구현 (대체 부분만)
3295 단어 두지주
( )
ckeck
#include<stdio.h>
#include<stdlib.h>
#include <time.h>
#include<string.h>
#define n 14
#define m 4
void paixu(int v[])
{
int i=0,j=0,t=0;
for(i=0;i<20;i++)
{
for(j=0;j<19-i;j++) { if(v[j]>v[j+1]) {t=v[j+1];v[j+1]=v[j];v[j]=t;} }
}
}
void display(int v[])
{
int i=0;
printf("
");
paixu(v);
for(i=0;i<20;i++)
{
if (v[i]!=0&&v[i]<11) printf("%3d",v[i]);
if (v[i]==11) printf(" J ");
if (v[i]==12) printf(" Q ");
if (v[i]==13) printf(" k ");
if (v[i]==14) printf(" A ");
if (v[i]==15) printf(" 2 ");
if (v[i]==16) printf(" ");
if (v[i]==17) printf(" ");
}
printf("
");
}
void fapai(int a[],int b[],int c[])
{
printf("
n1 a
");
display(a);
printf("
n2 b
");
display(b);
printf("
n3 c
");
display(c);
}
int check(int v[])
{
int i=0,count=0;
if(v[i]!=0) count++;
if(count==0) { printf("
win
");}
return count;
}
void player(int aa[],int c[],int cc[])
{
int i,j,k;
int count=0;
int xx=0,x;
for(i=0;i<20;i++)
{ cc[i]=0; if(aa[i]!=0) count++; }
printf("
count=%d
",count);
if(count==0) {printf("
enter anycard
");scanf("%d",&x);cc[0]=x;printf("
cc%d
",cc[0]);for(i=0;i<20;i++)if(c[i]==c[0])c[i]=0; }
if(count==1) {printf("
enter onecard
");scanf("%d",&x);cc[0]=x;printf("
cc%d
",cc[0]);for(i=0;i<20;i++)if(c[i]==c[0])c[i]=0; }
if(count==2) {printf("
enter twocards
");scanf("%d",&x);cc[0]=x;scanf("%d",&x);cc[1]=x;printf("
cc%d , %d
",cc[0],cc[1]); }
paixu(cc);
}
void playee(int cc[],int b[],int bb[])
{
int i,j,k;
int count=0;
int xx=0,x;
for(i=0;i<20;i++)
{ bb[i]=0; if(cc[i]!=0) count++; }
printf("
count=%d
",count);
if(count==0)
{
printf("
enter anycard
");//for(i=0;i<20;i++)if(b[i]>cc[19]){ bb[0]=b[i]; b[i]=0;}
}
paixu(bb);
}
void play(int a[],int b[],int c[])
{
int aa[20]={0},na=0;
int bb[20]={0},nb=0;
int cc[20]={0},nc=0;
int num=5;
while(num--)
{
player(aa,c,cc); nc=check(c);
playee(cc,b,bb); nb=check(b);
playee(bb,a,aa); na=check(a);
//if(na<num)num=a; if(nb<num)num=b; if(nc<num) num=c;
}
}
void main()
{
int r,l;
int x[n][m]={0};
int a[20]={0},b[20]={0},c[20]={0};
int i,j,k=0;
time_t t;
srand((unsigned)time(&t));
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
x[i][j]=i+3;
// printf("%3d",x[i][j]);
}
}
//x[13][0]=16;
x[13][1]=17;
x[13][2]=0;
x[13][3]=0;
while(k<17)
{
r=rand()%14;
l=rand()%4;
if(x[r][l]!=0){ a[k]=x[r][l];x[r][l]=0;k++;}
// else continue;
}
k=0;
while(k<17)
{
r=rand()%14;
l=rand()%4;
if(x[r][l]!=0){ b[k]=x[r][l];x[r][l]=0;k++;}
// else continue;
}
k=0;
for(i=0;i<14;i++)
{ for(j=0;j<4;j++)
{
if(x[i][j]!=0) { c[k]=x[i][j]; k++; }
}
}
fapai(a,b,c);
play(a,b,c);
//num();
}