#include<bits/stdc++.h>//注意!严禁盗用,违者必究!!!
using namespace std;
int bh1,bh2,xl1,xl2,sj,sps1=4,sps2=4,shu;
string shoupai1[40],shoupai2[40],zhuangbei1[2],zhuangbei2[2];
int Shoupai1[40]={0},Shoupai2[40]={0},xzs,zt1=0,zt2=0,jg=0;
char fh='L';
bool bol1=false,bol2=false,sb1=false,sb2=false;
void huanggai1(){   bh1=0;   xl1=4;   } 
void zhangfei1(){   bh1=1;   xl1=4;   }
void xuchu1(){   bh1=2;   xl1=4;   }
void liubei1(){   bh1=3;   xl1=4;   } 
void xiahoudun1(){   bh1=4;   xl1=4;   }
void sunquan1(){   bh1=5;   xl1=4;   }
void huanggai2(){   bh2=0;   xl2=4;   } 
void zhangfei2(){   bh2=1;   xl2=4;   }
void xuchu2(){   bh2=2;   xl2=4;   }
void liubei2(){   bh2=3;   xl2=4;   } 
void xiahoudun2(){   bh2=4;   xl2=4;   }
void sunquan2(){   bh2=5;   xl2=4;   }
void csp1(int i){
	sj=rand()%26;
	if(sj<5) {
		shoupai1[i]="\b杀 ";
		Shoupai1[i]=1;
	}
	if(sj>=5&&sj<10) {
		shoupai1[i]="\b闪 ";
		Shoupai1[i]=2;
	} 
	if(sj>=10&&sj<=11) {
		shoupai1[i]="\b桃 ";
		Shoupai1[i]=3;	
	}
	if(sj==12||sj==13) {
		shoupai1[i]="\b过河拆桥 ";
		Shoupai1[i]=4;
	}
	if(sj==14||sj==15) {
		shoupai1[i]="\b顺手牵羊 ";
		Shoupai1[i]=5;
	}
	if(sj==16) {
		shoupai1[i]="\b无中生有 ";
		Shoupai1[i]=6;
	} 
	if(sj==18||sj==19) {
		shoupai1[i]="\b万箭齐发 ";
		Shoupai1[i]=7;
	}
	if(sj==20||sj==21) {
		shoupai1[i]="\b南蛮入侵 ";
		Shoupai1[i]=8;
	}
	if(sj==22||sj==23) {
		shoupai1[i]="\b桃园结义 ";
		Shoupai1[i]=9;
	}
	if(sj==24) {
		shoupai1[i]="\b青釭剑 ";
		Shoupai1[i]=10;
	} 
	if(sj==17) {
		shoupai1[i]="\b古锭刀 ";
		Shoupai1[i]=11;
	}
	if(sj==25) {
		shoupai1[i]="\b八卦阵 ";
		Shoupai1[i]=12;
	}
}
void csp2(int i){
	sj=rand()%26;
	if(sj<5) {
		shoupai2[i]="\b杀 ";
		Shoupai2[i]=1;
	}
	if(sj>=5&&sj<10) {
		shoupai2[i]="\b闪 ";
		Shoupai2[i]=2;
	} 
	if(sj>=10&&sj<=11) {
		shoupai2[i]="\b桃 ";
		Shoupai2[i]=3;	
	}
	if(sj==12||sj==13) {
		shoupai2[i]="\b过河拆桥 ";
		Shoupai2[i]=4;
	}
	if(sj==14||sj==15) {
		shoupai2[i]="\b顺手牵羊 ";
		Shoupai2[i]=5;
	}
	if(sj==16) {
		shoupai2[i]="\b无中生有 ";
		Shoupai2[i]=6;
	} 
	if(sj==18||sj==19) {
		shoupai2[i]="\b万箭齐发 ";
		Shoupai2[i]=7;
	}
	if(sj==20||sj==21) {
		shoupai2[i]="\b南蛮入侵 ";
		Shoupai2[i]=8;
	}
	if(sj==22||sj==23) {
		shoupai2[i]="\b桃园结义 ";
		Shoupai2[i]=9;
	}
	if(sj==24) {
		shoupai2[i]="\b青釭剑 ";
		Shoupai2[i]=10;
	} 
	if(sj==17) {
		shoupai2[i]="\b古锭刀 ";
		Shoupai2[i]=11;
	}
	if(sj==25) {
		shoupai2[i]="\b八卦阵 ";
		Shoupai2[i]=12;
	}
}
void yd1(){
	for(int i=0;i<sps2;++i) {
		if(shoupai2[i]=="L ") 
			for(int j=i;j<sps2;j++) shoupai2[j]=shoupai2[j+1];
		if(Shoupai2[i]==0) 
			for(int j=i;j<sps2;j++) Shoupai2[j]=Shoupai2[j+1];
	}	
}
void yd2(){
	for(int i=0;i<sps1;++i) {
		if(shoupai1[i]=="L ") 
			for(int j=i;j<sps1;j++) shoupai1[j]=shoupai1[j+1];
		if(Shoupai1[i]==0) 
			for(int j=i;j<sps1;++j) Shoupai1[j]=Shoupai1[j+1];
	}		
}
int main(){
	srand(time(NULL));
	cout<<"\b三国杀(简配版)\n";
	_sleep(650);
	cout<<"\b由张爹地自主研发并出品\n";
	_sleep(650);
	cout<<"\b未经作者本人许可严禁盗用源码。以修改的名义进行盗用、搬窃,并重新命名发布的,一律视为盗用。违者必究!\n";
	_sleep(650);
	cout<<"\b游戏开始\n";
	_sleep(1000);
	cout<<"\b玩家1抽武将牌\n";
	_sleep(500); 
	sj=rand()%12;
	if(sj==0||sj==8) {
		huanggai1();
		cout<<"\b玩家1抽到了黄盖\n"; 
	}
	else if(sj==2||sj==3) {
		zhangfei1();
		cout<<"\b玩家1抽到了张飞\n";
	}
	else if(sj==7||sj==5) {
		xuchu1();
		cout<<"\b玩家1抽到了许褚\n";
	}
	else if(sj==10||sj==4) {
		liubei1();
		cout<<"\b玩家1抽到了刘备\n";
	}
	else if(sj==1||sj==9) {
		xiahoudun1();
		cout<<"\b玩家1抽到了夏侯惇\n";
	}
	else if(sj==6||sj==11) {
		sunquan1();
		cout<<"\b玩家1抽到了孙权\n";
	}
	
	_sleep(850); 
	cout<<"\b玩家2抽武将牌\n";
	_sleep(500); 
	sj=rand()%6;
	if(sj==0||sj==1) {
		huanggai2();
		cout<<"\b玩家2抽到了黄盖\n"; 
	}
	else if(sj==2||sj==3) {
		zhangfei2();
		cout<<"\b玩家2抽到了张飞\n";
	}
	else if(sj==4||sj==5) {
		xuchu2();
		cout<<"\b玩家2抽到了许褚\n";
	}
	else if(sj==6||sj==7) {
		liubei2();
		cout<<"\b玩家2抽到了刘备\n";
	}
	else if(sj==8||sj==9) {
		xiahoudun2();
		cout<<"\b玩家2抽到了夏侯惇\n";
	}
	else if(sj==10||sj==11) {
		sunquan2();
		cout<<"\b玩家2抽到了孙权\n";
	}
	_sleep(1250);
	cout<<"\b玩家1抽初始手牌\n";
	for(int i=0;i<4;++i) csp1(i);
	_sleep(500);
	for(int i=0;i<4;++i) cout<<shoupai1[i]<<" ";
	cout<<"\b已确认?是则按Y\n";
	while(fh!='Y'&&scanf("%c",&fh)!=EOF) _sleep(1);
	cout<<"\n\n\n";
	fh='L';
	cout<<"\b玩家2抽初始手牌\n"; 
	for(int i=0;i<4;++i) csp2(i);
	_sleep(500);
	for(int i=0;i<4;++i) cout<<shoupai2[i]<<" ";
	cout<<"\b已确认?是则按Y\n";
	while(fh!='Y'&&scanf("%c",&fh)!=EOF) _sleep(1);
	cout<<"\n\n\n";
	while(1) {
		shu=0;
		xzs=1;
		cout<<"\b玩家1摸牌阶段\n";
		if(bh1==2) {
			cout<<"\b是否使用技能?\n";
			cout<<"\b是则输入Y,否则输入U\n"; 
			cin>>fh;
			if(fh=='Y') bol1=true;
		}
		if(bol1) {
			csp1(sps1);
			sps1++;
		}
		else {
			csp1(sps1);
			sps1++;
			csp1(sps1);
			sps1++;
		}
		fh='L';
		_sleep(750);
		while(1) {
			fh='L';
			cout<<"\n";
			for(int i=0;i<sps1;++i) 
				if(shoupai1[i]!="L ") cout<<shoupai1[i]<<"  ";
			cout<<"\n";
			for(int i=0;i<2;++i) 
				if(zhuangbei1[i]!="L ") cout<<zhuangbei1[i]<<" ";
			cout<<"\n\b玩家1出牌阶段\n";
			cout<<"\n\b玩家1剩余血量为"<<xl1<<"\n";
			cout<<"\b玩家2剩余血量为"<<xl2<<"\n";
			cout<<"\b请输入即将出牌的牌的号码,或者跳过该回合?(输入50)\n" ;
			cin>>shu;
			xzs=1;
			if(shu==50) break;
			else {
				cout<<"\b请输入所选牌将要执行的操作,按Y使用\n。如果要使用技能,请输入100\n";
				cin>>fh;
				if(fh=='Y') {
					if(Shoupai1[shu-1]==4) {
						sj=rand()%sps2;
						shoupai2[sj]="L ";
						shoupai1[shu-1]="L ";
						Shoupai2[sj]=0;
						Shoupai1[shu-1]=0;
						yd1();   yd2();
						sps2--;   sps1--;
					}
					else if(Shoupai1[shu-1]==5) {
						sj=rand()%sps2;
						shoupai1[shu-1]=shoupai2[sj];
						shoupai2[sj]="L "; 
						Shoupai2[sj]=0;
						Shoupai1[shu-1]=Shoupai2[sj];
						yd1();  yd2();
						sps2--;
					}
					else if(Shoupai1[shu-1]==7) {
						int s=0,x;
						for(int i=0;i<sps2;++i) 
							if(Shoupai2[i]==2) {
								s++;   x=i;   break;
							}
						if(s!=0) {
							shoupai2[x]="L ";
							Shoupai2[x]=0;
							yd1();   yd2();
							sps2--;
						}
						else xl2--;
						shoupai1[shu-1]="L ";
						Shoupai1[shu-1]=0;
						yd1();   yd2();
						sps1--;
					}
					else if(Shoupai1[shu-1]==6) {
						csp1(sps1);
						sps1++;
						csp1(sps1);
						sps1++;
						shoupai1[shu-1]="L ";
						Shoupai1[shu-1]=0;
						yd1();   yd2();
						sps1--;
					} 
					else if(Shoupai1[shu-1]==8) {
						int s=0,x;
						for(int i=0;i<sps2;++i) 
							if(Shoupai2[i]==1) {
								s++;   x=i;  break;
							}
						if(s!=0) {
							shoupai2[x]="L ";
							Shoupai2[x]=0;
							shoupai1[shu-1]="L";
							Shoupai1[shu-1]=0;
							yd1();   yd2();
							sps2--;
						}
						else xl2--;
						shoupai1[shu-1]="L ";
						Shoupai1[shu-1]=0;
						yd1();   yd2();
						sps1--;
					}
					else if(Shoupai1[shu-1]==9) {
						shoupai1[shu-1]="L ";
						Shoupai1[shu-1]=0;
						xl1++;
						xl2++;
						yd1();   yd2();
						sps1--;
						if(xl1>4) xl1=4;
						if(xl2>4) xl2=4;
					}
					else if(Shoupai1[shu-1]==1) {
						if(xzs>0) {
							shoupai1[shu-1]="L ";
							Shoupai1[shu-1]=0;
							int s=0,x;
							for(int i=0;i<sps2;++i) 
								if(Shoupai2[i]==2) {   s++;   x=i;   break;   }
							if(s!=0) {
								shoupai2[x]="L ";
								Shoupai2[x]=0;
								shoupai1[shu-1]="L ";
								Shoupai1[shu-1]=0;
								yd1();   yd2();
								sps2--;
							}
							else {
								if(bh1==2&&bol1) xl2-=2;
								else if((bh1==2&&bol1)&&((zt1==1||zt1==4)&&sps1==0)) xl2-=3;
								else if(bh1=!2&&((zt1==1||zt1==4)&&sps1==0)) xl2-=2;
								else if(bh1!=2&&zt1!=1) xl2--;
								else if(bh1!=2&&zt1!=4) xl2--;
								else if(bh1!=2&&((zt1==1||zt1==4)&&sps1!=0)) xl2--;
							}
							xzs=0;
							yd1();   yd2(); 
							sps1--;
						}
						else if(bh1==1) {
							shoupai1[shu-1]="L ";
							Shoupai1[shu-1]=0;
							int s=0,x;
							for(int i=0;i<sps2;++i) 
								if(Shoupai2[i]==2) {
									s++;
									x=i;
								break;
								}
							if(s!=0) {
								shoupai2[x]="L ";
								Shoupai2[x]=0;
								shoupai1[shu-1]="L ";
								Shoupai1[shu-1]=0;
								yd1();   yd2();
								sps2--;
							}
							else {
								if(bh1==2&&bol1) xl2-=2;
								else if((bh1==2&&bol1)&&((zt1==1||zt1==4)&&sps1==0)) xl2-=3;
								else if(bh1=!2&&((zt1==1||zt1==4)&&sps1==0)) xl2-=2;
								else if(bh1!=2&&zt1!=1) xl2--;
								else if(bh1!=2&&zt1!=4) xl2--;
								else if(bh1!=2&&((zt1==1||zt1==4)&&sps1!=0)) xl2--;
							}
							xzs=0;
							yd1();   yd2(); 
							sps1--;
						}
						else cout<<"\n\n\b您已经使用过【杀】了\n\n";
					}
					else if(Shoupai1[shu-1]==3) {
						xl1++;
						if(xl1>4) xl1=4;
						shoupai1[shu-1]="L ";
						Shoupai1[shu-1]=0;
						yd1();   yd2();
						sps1--;
					}
					else if(Shoupai1[shu-1]==10) {
							zhuangbei1[0]=shoupai1[shu-1];
							shoupai1[shu-1]="L ";
							Shoupai1[shu-1]=0;
							yd1();   yd2();
							sps1--;
							if(zt1==3) zt1=5;
							else zt1=2;
					}
					else if(Shoupai1[shu-1]==12) {
						zhuangbei1[1]=shoupai1[shu-1];
						shoupai1[shu-1]="L ";
						Shoupai1[shu-1]=0;
						yd1();   yd2();
						sps1--;
						if(zt1==1) zt1=4;
						else if(zt1==2) zt1=5;
						else zt1=3;
					}
					else if(Shoupai1[shu-1]==11) {
							zhuangbei1[0]=shoupai1[shu-1];
							shoupai1[shu-1]="L ";
							Shoupai1[shu-1]=0;
							yd1();   yd2();
							sps1--;
							if(zt1==3) zt1=4;
							else zt1=1;
					}
					else if(shu==100) {
						if(bh1==0) {
							xl1--;
							csp1(sps1);
							sps1++;
							csp1(sps1);
							sps1++;
							if(xl1<=0) {
								jg=2;
								break;
							}
						} //黄盖技能 
						else if(bh1==3) {
							xl1++;
							sj=rand()%sps1;
							Shoupai2[sps2]=Shoupai1[sj];
							shoupai2[sps2]=shoupai1[sj];
							shoupai1[sj]="L ";
							Shoupai1[sj]=0;
							yd1();  yd2();
							sps1++;  sps2--;
							sj=rand()%sps1;
							Shoupai2[sps2]=Shoupai1[sj];
							shoupai2[sps2]=shoupai1[sj];
							shoupai1[sj]="L ";
							Shoupai1[sj]=0;
							yd1();  yd2();
							sps1++;  sps2--;
						} //刘备技能 
						else if(bh1==5) {
							cout<<"\b输入你要弃置的手牌编号\n";
							cin>>shu;
							shoupai1[shu-1]="L ";
							Shoupai1[shu-1]=0;
							csp1(shu-1);
							yd1();   yd2();
							sps1--;
						} //孙权技能 
					} 
				}
			}
		}
		bol1=false;
		shu=0;
		if(sps1>xl1) 
			while(sps1>xl1) {
				cout<<"\n\b请输入弃置牌的编号\n";
				cin>>shu;
				sps1--;
				shoupai1[shu-1]="L ";
				Shoupai1[shu-1]=0;
				yd1();   yd2();
				cout<<"\n";
				for(int i=0;i<sps1;++i) cout<<shoupai1[i]<<" ";
				cout<<"\n";
			}
		if(xl1<=0) {
			jg=2;
			break;
		}
		else if(xl1<=0){
			jg=1;
			break;
		}
		//以下为玩家2 
		xzs=1;
		cout<<"\b玩家2摸牌阶段\n";
		if(bh2==2) {
			cout<<"\b是否使用技能?\n";
			cout<<"\b是则输入Y,否则输入U\n"; 
			cin>>fh;
			if(fh=='Y') bol2=true;
		}
		if(bol2) {
			csp2(sps2);
			sps2++;
		}
		else {
			csp2(sps2);
			sps2++;
			csp2(sps2);
			sps2++;
		}
		fh='L';
		_sleep(850);
		for(int i=0;i<sps2;++i) cout<<shoupai2[i]<<"  ";
		_sleep(750);
		while(1) {
			fh='L';
			cout<<"\n";
			for(int i=0;i<sps2;++i) cout<<shoupai2[i]<<"  ";
			cout<<"\n";
			for(int i=0;i<2;++i) cout<<zhuangbei2[i]<<" ";
			cout<<"\n\b玩家2出牌阶段\n";
			cout<<"\n\b玩家1剩余血量为"<<xl1<<"\n";
			cout<<"\b玩家2剩余血量为"<<xl2<<"\n";
			cout<<"\b请输入即将出牌的牌的号码,或者跳过该回合?(输入50)\n。如果要使用技能,请输入100\n" ;
			cin>>shu;
			if(shu==50) break;
			else {
				cout<<"\b请输入所选牌将要执行的操作,按Y使用\n";
				cin>>fh;
				if(fh=='Y') {
					if(Shoupai2[shu-1]==4) {
						sj=rand()%sps1;
						shoupai1[sj]="L ";
						shoupai2[shu-1]="L ";
						Shoupai1[sj]=0;
						Shoupai2[shu-1]=0;
						sps1--;  sps2--;
						yd1();  yd2();
					}
					else if(Shoupai2[shu-1]==5) {
						sj=rand()%sps1;
						shoupai2[shu-1]=shoupai1[sj];
						Shoupai2[shu-1]=Shoupai1[sj];
						shoupai1[sj]="L "; 
						Shoupai1[sj]=0;
						sps1--;
						yd1();  yd2();
					}
					else if(Shoupai2[shu-1]==7) {
						int s=0,x;
						for(int i=0;i<sps1;++i) 
							if(Shoupai1[i]==2) {
								s++;
								x=i;
								break;
							}
						if(s!=0) {
							shoupai1[x]="L ";
							Shoupai1[x]=0;
							shoupai2[shu-1]="L ";
							Shoupai2[shu-1]=0;
							sps1--;
							yd1();  yd2();
						}
						else xl1--;
						shoupai2[shu-1]="L ";
						Shoupai2[shu-1]=0;
						sps2--;
						yd1();  yd2();
					}
					else if(Shoupai2[shu-1]==8) {
						int s=0,x;
						for(int i=0;i<sps1;++i) 
							if(Shoupai1[i]==1) {
								s++;   x=i;  break;
							}
						if(s!=0) {
							shoupai1[x]="L ";
							Shoupai2[shu-1]=0;	
							sps1--;
							yd1();  yd2();
						}
						else xl1--;
						shoupai2[shu-1]="L ";
						Shoupai2[shu-1]=0;
						sps2--;
						yd1();  yd2();
					}
					else if(Shoupai2[shu-1]==6) {
						csp2(sps2);
						sps2++;
						csp2(sps2);
						sps2++;
						sps2++;
						shoupai2[shu-1]="L ";
						Shoupai2[shu-1]=0;
						yd1();   yd2();
					} 
					else if(Shoupai2[shu-1]==9) {
						shoupai2[shu-1]="L ";
						Shoupai2[shu-1]=0;
						yd1();  yd2();
						sps2--;
						xl1++;
						xl2++;
						if(xl1>4) xl1=4;
						if(xl2>4) xl2=4;
					}
					else if(Shoupai2[shu-1]==1) {
						if(xzs>0) {
							shoupai2[shu-1]="L ";
							Shoupai2[shu-1]=0;
							yd1();  yd2();
							sps2--;
							int s=0,x;
							for(int i=0;i<sps1;++i) 
								if(Shoupai1[i]==2) {
									s++;
									x=i;
								break;
								}
							if(s!=0) {
								shoupai1[x]="L ";
								Shoupai2[shu-1]=0;
								yd1();  yd2();
								sps1--;
							}
							else xl1--;
							xzs--;
						}
						else if(bh2==1) {
							shoupai2[shu-1]="L ";
							Shoupai2[shu-1]=0;
							sps2--;
							yd1();  yd2();
							int s=0,x;
							for(int i=0;i<sps1;++i) 
								if(Shoupai1[i]==2) {
									s++;
									x=i;
								break;
								}
							if(s!=0) {
								shoupai1[x]="L ";
								Shoupai2[shu-1]=0;
								sps1--;
								yd1();  yd2();
							}
							else xl1--;
							xzs--;
						}
						else cout<<"\n\n\b您已经使用过【杀】了\n\n";
					}
					else if(Shoupai2[shu-1]==10) {
						zhuangbei2[0]=shoupai2[shu-1];
						shoupai2[shu-1]="L ";
						Shoupai2[shu-1]=0;
						sps2--;
						yd1();  yd2();
						if(zt2==3) zt2=5;
						else zt2=2;
					}
					else if(Shoupai2[shu-1]==12) {
						zhuangbei2[1]=shoupai2[shu-1];
						shoupai2[shu-1]="L ";
						Shoupai2[shu-1]=0;
						sps2--;
						yd1();  yd2();
						if(zt2==1) zt2=4;
						else if(zt2==2) zt2=5;
						else zt2=3;
					}
					else if(Shoupai2[shu-1]==11) {
							zhuangbei2[0]=shoupai1[shu-1];
							shoupai2[shu-1]="L ";
							Shoupai2[shu-1]=0;
							sps2--;
							yd1();   yd2();
							if(zt2==3) zt2=4;
							else zt2=1;
					}
				}  
				else if(shu==100) {
					if(bh2==0) {
						xl2--;
						csp2(sps2);
						sps2++;
						csp2(sps2);
						sps2++;
					} //黄盖技能 
					else if(bh2==3) {
						xl2++;
						sj=rand()%sps2;
						Shoupai1[sps1]=Shoupai2[sj];
						shoupai1[sps1]=shoupai2[sj];
						shoupai2[sj]="L ";
						Shoupai2[sj]=0;
						sps1++;  sps2--;
						yd1();  yd2();
						sj=rand()%sps2;
						Shoupai1[sps1]=Shoupai2[sj];
						shoupai1[sps1]=shoupai2[sj];
						shoupai2[sj]="L ";
						Shoupai2[sj]=0;
						sps1++;  sps2--;
						yd1();  yd2();
					} //刘备技能 
					else if(bh2==4) {	
						cout<<"\b输入你要弃置的手牌编号\n";
						cin>>shu;
						shoupai2[shu-1]="L ";
						Shoupai2[shu-1]=0;
						csp2(shu-1);
						yd1();   yd2();
					}
				} 
			} //出牌阶段
		} //摸牌阶段 
		bol1=false;
		shu=0;
		if(sps2>xl2) 
			while(sps2>xl2) {
				cout<<"\n\b请输入弃置牌的编号\n";
				cin>>shu;
				sps2--;
				shoupai2[shu-1]="L ";
				Shoupai2[shu-1]=0;
				yd1();   yd2();
				cout<<"\n";
				for(int i=0;i<sps2;++i) cout<<shoupai2[i]<<" ";
				cout<<"\n";
			}
		if(xl1<=0) {
			jg=2;
			break;
		}
		else if(xl2<=0) {
			jg=1;
			break;
		}
	}
	if(jg==2) {
		cout<<"\n\b玩家2获胜!\n";
		return 0;
	}
	cout<<"\n\b玩家1获胜!\n";
	return 0;
}