尽量总人数不要输2!!!!!!!!!!
are you want to clear? (1/0)
Query rules by zero:(1/0)
摸牌?/决斗?(1/0)
#include<bits/stdc++.h>
using namespace std;
int p,cha;
int p1[100],p2[100],p3[100],st=1,tong[59];
struct Suits {
int check(int v) {
if(tong[v-2]+1>4&&v<15) {
return 0;
}
if(tong[v-2]+1>1&&v>=15) {
return 0;
}
return 1;
}
void reward(int win) {
srand((unsigned)time(NULL));
int s=3,e=12,k=4;
int n;
if(win==1) {
srand((unsigned)time(NULL));
for(int i=1; i<=cha; i++) {
n=rand()%(e-s+1)+s;
if(!check(n)) {
i--;
continue;
}
p1[k]=n;
tong[n-2]++;
k++;
}
}
if(win==2) {
srand((unsigned)time(NULL));
for(int i=1; i<=cha; i++) {
n=rand()%(e-s+1)+s;
if(!check(n)) {
i--;
continue;
}
p2[k]=n;
tong[n-2]++;
k++;
}
}
if(win==3) {
srand((unsigned)time(NULL));
for(int i=1; i<=cha; i++) {
n=rand()%(e-s+1)+s;
if(!check(n)) {
i--;
continue;
}
p3[k]=n;
tong[n-2]++;
k++;
}
}
cout<<"以为获胜者抓了"<<cha<<"张牌。"<<endl;
print(k);
}
int than_size(int one,int two) {
int maxx=0,maxx2=0,maxx3=0;
if(one==1||two==1) {
int x=rand()%2+1;
if(x==1) {
for(int i=1; i<=3; i++) {
maxx=max(maxx,p1[i]);
}
} else {
srand((unsigned)time(NULL));
int x2=rand()%(3-1+1)+1;
if(x2==0) maxx=p1[x2+1];
if(x2==4) maxx=p1[x2-1];
else {
maxx=p1[x2];
}
}
cout<<"人机出:"<<maxx<<endl;
}
if(one==2||two==2) {
cout<<endl<<"p2,请输入你任意一张牌的点数:";
cin>>maxx2;
bool flag=0;
while(!flag) {
for(int i=1; i<=3; i++) {
if(p2[i]==maxx2) flag=1;
}
if(!flag) cout<<"请输入正确的点数!"<<endl;
else break;
cin>>maxx2;
}
// if(maxx2>maxx) maxone=2,cha=maxx2-maxx;
}
if(two==3) {
cout<<endl<<"p3,请输入你任意一张牌的点数:";
cin>>maxx3;
bool flag=0;
while(!flag) {
for(int i=1; i<=3; i++) {
if(p3[i]==maxx3) flag=1;
}
if(!flag) cout<<"请输入正确的点数!"<<endl;
else break;
cin>>maxx3;
}
// if(maxx3>maxx&&maxx3>maxx2) maxone=3,cha=maxx3-max(maxx,maxx2);
}
if(maxx3>=maxx&&maxx3>=maxx2) {
cha=maxx3-max(maxx,maxx2);
return 3;
}
if(maxx2>=maxx&&maxx3<=maxx2) {
cha=maxx2-max(maxx,maxx3);
return 2;
}
cha=maxx-max(maxx2,maxx3);
return 1;
}
void clear() {
cout<<"Are you want to clear?";
int x;
cin>>x;
if(x==0) return;
else system("cls");
}
void print(int x) {
clear();
for(int i=1; i<=x*p; i++) {
if(i>x&&i<=2*x) {
if(i==x+1) {
cout<<endl<<"p2的牌的点数:";
}
if(p2[i-x]==0) continue;
cout<<p2[i-x]<<" ";
} else {
if(i==2*x+1) {
cout<<"p2,你记住了吗?"<<endl;
system("pause");
cout<<endl<<"p3的牌的点数:";
system("cls");
}
if(p3[i-2*x]==0) continue;
cout<<p3[i-2*x]<<" ";
}
}
cout<<"p3,你记住了吗?"<<endl;
system("pause");
system("cls");
}
int sum_of_playgers() {
cout<<"Please enter the number of people(2<=输入人数<=3):";
int people;
cin>>people;
while(people<2||people>3) {
cout<<"Please enter the correct number of people!";
cin>>people;
}
clear();
return people;
}
void rules() {
cout<<"Query rules by zero:";
bool FT;
cin>>FT;
if(!FT) {
cout<<"1.选择人数(其中有一个人机),每人摸两张牌。"<<endl;
cout<<"2.每人可以和某人抓牌(*1),两人在自己的牌中选一张,"<<endl;
cout<<"进行比大小,如p1出4,p2出6,那么p2抓(6-4)张牌,"<<endl;
cout<<"p2在自己牌中选两张最大的,其余扔掉,p1同p2。"<<endl;
cout<<"相等双方都不抓牌。"<<endl;
}
clear();
}
void game_ready() {
srand((unsigned)time(NULL));
int s=3,e=12;
int n=rand()%(e-s+1)+s,k=1;
for(int i=1; i<=n; i++) {
cout<<"游戏加载中.";
if(k==2) cout<<".";
if(k==3) {
cout<<"..",k=1;
system("cls");
continue;
}
for(int i=1; i<=1e9/2; i++) {}
system("cls");
k++;
}
rules();
}
void game_running() {
cout<<"抓牌中...."<<endl;
srand((unsigned)time(NULL));
int s=3,e=17;
for(int i=1; i<=p*2; i++) {
int n=rand()%(e-s+1)+s;
if(!check(n)) {
i--;
continue;
}
tong[n-2]++;
if(i<=2) {
p1[st]=n;
tong[n-2]++;
st++;
} else if(i<=4) {
if(i==3) st=1;
p2[st]=n;
tong[n-2]++;
st++;
} else {
if(i==5) st=1;
p3[st]=n;
tong[n-2]++;
st++;
}
}
st=3;
}
void climax_of_game() {
srand((unsigned)time(NULL));
int n=rand()%2+1;
int iop=0,o,t,t2;
if(n==1) {
cout<<endl<<"人机决定摸牌!"<<endl;
iop++;
o=1;
} else cout<<endl<<"人机不决定摸牌!"<<endl;
int n2;
cout<<"p2决定摸牌?";
cin>>n2;
if(n2==1) {
cout<<"p2决定摸牌!"<<endl;
iop++;
t=1;
} else cout<<"p2不决定摸牌!"<<endl;
int n3;
cout<<"p3决定摸牌?";
cin>>n3;
if(n3==1) {
cout<<"p3决定摸牌!"<<endl;
iop++;
t2=1;
} else cout<<"p3不决定摸牌!"<<endl;
if(iop>p/2) {
if(t==1&&t2==1) {
int s=3,e=17;
int n4=rand()%(e-s+1)+s;
while(check(n4)==0) {
n4=rand()%(e-s+1)+s;
}
st=3;
p2[st]=n4;
tong[n4-2]++;
int n5=rand()%(e-s+1)+s;
while(check(n5)==0) {
n5=rand()%(e-s+1)+s;
}
p3[st]=n5;
tong[n5-2]++;
print(st);
int win=than_size(2,3);
reward(win);
t=0,t2=0;
}
if(o==1&&t2==1) {
int s=3,e=17;
int n4=rand()%(e-s+1)+s;
while(check(n4)==0) {
n4=rand()%(e-s+1)+s;
}
st=3;
p1[st]=n4;
tong[n4-2]++;
int n5=rand()%(e-s+1)+s;
while(check(n5)==0) {
n5=rand()%(e-s+1)+s;
}
p3[st]=n5;
tong[n5-2]++;
print(st);
int win=than_size(1,3);
reward(win);
o=0,t2=0;
}
if(o==1&&t==1) {
int s=3,e=17;
int n4=rand()%(e-s+1)+s;
while(check(n4)==0) {
n4=rand()%(e-s+1)+s;
}
st=3;
p1[st]=n4;
tong[n4-2]++;
int n5=rand()%(e-s+1)+s;
while(check(n5)==0) {
n5=rand()%(e-s+1)+s;
}
p2[st]=n5;
tong[n5-2]++;
print(st);
int win=than_size(1,2);
reward(win);
o=0,t=0;
}
} else cout<<"不摸牌!"<<endl;
}
void Throw_cards() {
int k=0,k2=0,k3=0;
while(p1[k+1]!=0) k++;
while(p2[k2+1]!=0) k2++;
while(p3[k3+1]!=0) k3++;
//k--,k2--,k3--;
if(k>2) {
int x=rand()%2+1;
int m1=0,m2=0;
if(x==1) {
for(int i=1; i<=k; i++) {
if(p1[i]>m1) m1=p1[i],p1[i]=0;
}
for(int i=1; i<=k; i++) {
if(p1[i]>m2) m2=p1[i],p1[i]=0;
}
for(int i=1; i<=k; i++) {
if(p1[i]!=0) {
tong[p1[i]-2]--;
}
}
memset(p1,0,sizeof(p1));
p1[1]=m1;
p1[2]=m2;
} else {
int x2=rand()%(k-1+1)+1,s;
int x3=rand()%(k-1+1)+1,t;
if(x2==x3) {
s=p1[x2];
if(x3+1>k) {
s=p1[x3-1];
p1[x3-1]=0;
} else {
t=p1[x3+1];
p1[x3+1]=0;
}
for(int i=1; i<=k; i++) {
if(p1[i]!=0) {
tong[p1[i]-2]--;
}
}
memset(p1,0,sizeof(p1));
p1[1]=s;
p1[2]=t;
} else {
int s1=p1[x2],t1=p1[x3];
p1[x2]=0,p1[x3]=0;
for(int i=1; i<=k; i++) {
if(p1[i]!=0) {
tong[p1[i]-2]--;
}
}
memset(p1,0,sizeof(p1));
p1[1]=s1;
p1[2]=t1;
}
}
}
if(k2>2) {
cout<<endl<<"p2,请输入你想留下的两张牌"<<endl;
int n,m,flag=0;
cin>>n>>m;
while(!flag) {
for(int i=1; i<=k2; i++) {
if(p2[i]==n) {
p2[i]=0;
flag=1;
break;
}
}
if(!flag) cout<<"请输入正确的点数!"<<endl;
else break;
cin>>n;
}
flag=0;
while(!flag) {
for(int i=1; i<=k2; i++) {
if(p2[i]==m) {
p2[i]=0;
flag=1;
break;
}
}
if(!flag) cout<<"请输入正确的点数!"<<endl;
else break;
cin>>m;
}
for(int i=1; i<=k2; i++) {
if(p2[i]!=0) {
tong[p2[i]-2]--;
}
}
memset(p2,0,sizeof(p2));
p2[1]=n;
p2[2]=m;
}
if(k3>2) {
cout<<endl<<"p3,请输入你想留下的两张牌"<<endl;
int n,m,flag=0;
cin>>n>>m;
while(!flag) {
for(int i=1; i<=k3; i++) {
if(p3[i]==n) {
p3[i]=0;
flag=1;
break;
}
}
if(!flag) cout<<"请输入正确的点数!"<<endl;
else break;
cin>>n;
}
flag=0;
while(!flag) {
for(int i=1; i<=k3; i++) {
if(p3[i]==m) {
p3[i]=0;
flag=1;
break;
}
}
if(!flag) cout<<"请输入正确的点数!"<<endl;
else break;
cin>>m;
}
for(int i=1; i<=k3; i++) {
if(p3[i]!=0) {
tong[p3[i]-2]--;
}
}
memset(p3,0,sizeof(p3));
p3[1]=n;
p3[2]=m;
}
print(2);
}
int duel() {
srand((unsigned)time(NULL));
int n=rand()%3+1;
int iop=0;
if(n==1) {
int a=p1[1]+p1[2];
int b=p2[1]+p2[2];
int c=p3[1]+p3[2];
if(a>b&&a>c) cout<<endl<<"人机决定决斗!"<<endl,iop++;
else cout<<endl<<"人机不决定决斗!"<<endl;
} else cout<<endl<<"人机不决定决斗!"<<endl;
int n2;
cout<<"p2决定决斗?";
cin>>n2;
if(n2==1) {
cout<<"p2决定决斗!"<<endl;
iop++;
} else cout<<"p2不决定决斗!"<<endl;
int n3;
cout<<"p3决定决斗?";
cin>>n3;
if(n3==1) {
cout<<"p3决定决斗!"<<endl;
iop++;
} else cout<<"p3不决定决斗!"<<endl;
if(iop>p/2) {
int a=p1[1]+p1[2];
int b=p2[1]+p2[2];
int c=p3[1]+p3[2];
if(a>b&&a>c) cout<<endl<<"人机获胜!"<<endl;
if(b>a&&b>c) cout<<endl<<"p2获胜!"<<endl;
if(c>b&&c>a) cout<<endl<<"p3获胜!"<<endl;
if(a==b&&b==c) cout<<"平局!"<<endl;
system("pause");
return 0;
} else {
cout<<"不决斗!"<<endl;
return 1;
}
}
} suits;
int main() {
p=suits.sum_of_playgers();
suits.rules();
suits.game_ready();
suits.game_running();
suits.print(2);
int flag=1;
while(flag) {
suits.climax_of_game();
suits.Throw_cards();
if(!suits.duel()) break;
}
cout<<"游戏结束........"<<endl;
return 0;
}
//谢谢大家支持!!!!!!!!!!(运行错误投诉我)
//创作不易 点攒攒支持一下!我才上5nian ji!