#include<bits/stdc++.h>
using namespace std;
int basic[2][4];//jade,defend,move,rebound
int pig[2][5];
int poke[2][4];
int light[2][3];
int chop[2][3];
int hole[2][3];
int shield[2][2];
int fist[2][4];
int opt[2],year[2];
int M,winner,cnt;
int win1,win0;
int history[2][50000];
void clear(){
	for(int i=0;i<=1;i++){
		for(int j=0;j<=2;j++){
			light[i][j]=0;
			hole[i][j]=0;
			chop[i][j]=0;
		}
		for(int j=0;j<=3;j++){
			basic[i][j]=0;
			poke[i][j]=0;
			fist[i][j]=0;
		}
		for(int j=0;j<=4;j++){
			pig[i][j]=0;
		}
		
		for(int j=0;j<=1;j++){
			shield[i][j]=0;
		}
		year[i]=0;
		opt[i]=0;
		for(int j=0;j<50000;j++)history[i][j]=0;
	}
}
void pri(int n){
	cout<<"you are player"<<n<<endl;
	cout<<"1 jade  "<<basic[n][0]<<endl;
	cout<<"2 defend  "<<basic[n][1]<<endl;
	cout<<"3 move  "<<basic[n][2]<<endl;
	cout<<"4 rebound  "<<basic[n][3]<<endl;
	cout<<"5 poke  "<<poke[n][0]<<endl;
	cout<<"6 th  "<<poke[n][1]<<endl;
	cout<<"7 tth  "<<poke[n][2]<<endl;
	cout<<"8 hm  "<<poke[n][3]<<endl;
	cout<<"9 spig  "<<pig[n][0]<<endl;
	cout<<"10 mpig  "<<pig[n][1]<<endl;
	cout<<"11 bpig  "<<pig[n][2]<<endl;
	cout<<"12 fpig  "<<pig[n][3]<<endl;
	cout<<"13 bfpig  "<<pig[n][4]<<endl;
	cout<<"14 slight  "<<light[n][0]<<endl;
	cout<<"15 mlight  "<<light[n][1]<<endl;
	cout<<"16 blight  "<<light[n][2]<<endl;
	cout<<"17 chop  "<<chop[n][0]<<endl;
	cout<<"18 strchop  "<<chop[n][1]<<endl;
	cout<<"19 pchop  "<<chop[n][2]<<endl;
	cout<<"20 bhole  "<<hole[n][0]<<endl;
	cout<<"21 whhole  "<<hole[n][1]<<endl;
	cout<<"22 wormhole  "<<hole[n][2]<<endl;
	cout<<"23 sfist  "<<fist[n][0]<<endl;
	cout<<"24 mfist  "<<fist[n][1]<<endl;
	cout<<"25 bfist  "<<fist[n][2]<<endl;
	cout<<"26 strfist  "<<fist[n][3]<<endl;
	cout<<"27 shield  "<<shield[n][0]<<endl;
	cout<<"28 clock  "<<shield[n][1]<<endl;
}
void printh(int n){
	cout<<"you are player"<<n<<endl;
	cout<<"1 jade  "<<endl;
	cout<<"2 defend  "<<endl;
	cout<<"3 move  "<<endl;
	cout<<"4 rebound  "<<endl;
	cout<<"5 poke  "<<endl;
	cout<<"6 th  "<<endl;
	cout<<"7 tth  "<<endl;
	cout<<"8 hm  "<<endl;
	cout<<"9 spig  "<<endl;
	cout<<"10 mpig  "<<endl;
	cout<<"11 bpig  "<<endl;
	cout<<"12 fpig  "<<endl;
	cout<<"13 bfpig  "<<endl;
	cout<<"14 slight  "<<endl;
	cout<<"15 mlight  "<<endl;
	cout<<"16 blight  "<<endl;
	cout<<"17 chop  "<<endl;
	cout<<"18 strchop  "<<endl;
	cout<<"19 pchop  "<<endl;
	cout<<"20 bhole  "<<endl;
	cout<<"21 whhole  "<<endl;
	cout<<"22 wormhole  "<<endl;
	cout<<"23 sfist  "<<endl;
	cout<<"24 mfist  "<<endl;
	cout<<"25 bfist  "<<endl;
	cout<<"26 strfist  "<<endl;
	cout<<"27 shield  "<<endl;
	cout<<"28 clock  "<<endl;
}
float dmg[30]={0,0,0,0,0,0.5,0.5,1,2,0.5,1,2,4,8,0.5,1,2,0.5,1,3.5,0,1,2,0.5,1,2,4,0,0};
bool chck(int n){
	if(year[n]==0){
		if(opt[n]==28 and shield[n][0]>=2){
			shield[n][0]-=2;
			shield[n][1]+=1;
			return true;
		}
		if(opt[n]==27 and basic[n][1]>=2){
			basic[n][1]-=2;
			shield[n][0]+=1;
			return true;
		}
		if(opt[n]==26 and fist[n][2]>=2){
			fist[n][2]-=2;
			fist[n][3]+=1;
			return true;
		}
		if(opt[n]==25 and fist[n][1]>=2){
			fist[n][1]-=2;
			fist[n][2]+=1;
			return true;
		}
		if(opt[n]==24 and fist[n][0]>=2){
			fist[n][0]-=2;
			fist[n][1]+=1;
			return true;
		}
		if(opt[n]==23 and basic[n][0]>=3){
			basic[n][0]-=3;
			fist[n][0]+=1;
			return true;
		}
		if(opt[n]==22 and hole[n][1]>=1){
			hole[n][1]-=1;
			hole[n][2]+=1;
			return true;
		}
		if(opt[n]==21 and hole[n][0]>=2){
			hole[n][0]-=2;
			hole[n][1]+=1;
			return true;
		}
		if(opt[n]==20 and basic[n][0]>=4){
			basic[n][0]-=4;
			hole[n][0]-=2;
			return true;
		}
		if(opt[n]==19 and chop[n][1]>=1 and pig[n][1]>=1){
			chop[n][1]-=1;
			pig[n][1]-=1;
			chop[n][2]+=1;
			return true;
		}
		if(opt[n]==18 and chop[n][0]>=2){
			chop[n][0]-=2;
			chop[n][1]+=1;
			return true;
		}
		if(opt[n]==17 and basic[n][0]>=1 and basic[n][1]>=1){
			basic[n][1]-=1;
			basic[n][0]-=1;
			chop[n][0]+=1;
			return true;
		}
		if(opt[n]==16 and light[n][1]>=2){
			light[n][1]-=2;
			light[n][2]+=1;
			return true;
		}
		if(opt[n]==15 and light[n][0]>=2){
			light[n][0]-=2;
			light[n][1]+=1;
			return true;
		}
		if(opt[n]==14 and basic[n][2]>=3){
			basic[n][2]-=3;
			light[n][0]+=1;
			return true;
		}
		if(opt[n]==13 and pig[n][3]>=2){
			pig[n][3]-=2;
			pig[n][4]+=1;
			return true;
		}
		if(opt[n]==12 and pig[n][2]>=2){
			pig[n][2]-=2;
			pig[n][3]+=1;
			return true;
		}
		if(opt[n]==11 and pig[n][1]>=2){
			pig[n][1]-=2;
			pig[n][2]+=1;
			return true;
		}
		if(opt[n]==10 and pig[n][0]>=2){
			pig[n][0]-=2;
			pig[n][1]+=1;
			return true;
		}
		if(opt[n]==9 and basic[n][0]>=2){
			basic[n][0]-=2;
			pig[n][0]+=1;
			return true;
		}
		if(opt[n]==5 and basic[n][0]>=1){
			basic[n][0]-=1;
			poke[n][0]+=1;
			return true;
		}
		if(opt[n]==4){
			basic[n][3]+=M;
			return true;
		}
		if(opt[n]==3){
			basic[n][2]+=M;
			return true;
		}
		if(opt[n]==2){
			basic[n][1]+=M;
			return true;
		}
		if(opt[n]==1){
			basic[n][0]+=M;
			return true;
		}	
		if(opt[n]==6  and poke[n][0]>=2){
			poke[n][1]+=1;	
			poke[n][0]-=2;
			year[n]++;
			return true;
		}
	}
	else{
		if(opt[n]==8 and year[n]==2){
			poke[n][3]+=1;
			year[n]=0;
			return true;
		}
		if(opt[n]==7 and year[n]==1){
			poke[n][2]+=1;
			year[n]++;
			return true;
		}
	}
	return false;
}
void damage(int n, float dg){
	if(dg==0.5){
		if(shield[n][0]>=1){
			shield[n][0]-=1;
		}
		else{
			if(shield[n][1]>=1){
				shield[n][0]+=1;
				shield[n][1]-=1;
			}
			else{
				winner=1-n;
			}
		}
	}
	else{
		int d=ceil(dg);
		if(shield[n][1]<d){
			winner=1-n;
		}
		else{
			shield[n][1]-=d;
		}
	}
}
void propt(int n){
	if(opt[n]==1)cout<<"jade"<<endl;
	if(opt[n]==2)cout<<"defend"<<endl;
	if(opt[n]==3)cout<<"move"<<endl;
	if(opt[n]==4)cout<<"rebound"<<endl;
	if(opt[n]==5)cout<<"poke"<<endl;
	if(opt[n]==6)cout<<"th"<<endl;
	if(opt[n]==7)cout<<"tth"<<endl;
	if(opt[n]==8)cout<<"hm"<<endl;
	if(opt[n]==9)cout<<"spig"<<endl;
	if(opt[n]==10)cout<<"mpig"<<endl;
	if(opt[n]==11)cout<<"bpig"<<endl;
	if(opt[n]==12)cout<<"fpig"<<endl;
	if(opt[n]==13)cout<<"bfpig"<<endl;
	if(opt[n]==14)cout<<"slight"<<endl;
	if(opt[n]==15)cout<<"mlight"<<endl;
	if(opt[n]==16)cout<<"blight"<<endl;
	if(opt[n]==17)cout<<"chop"<<endl;
	if(opt[n]==18)cout<<"strchop"<<endl;
	if(opt[n]==19)cout<<"pchop"<<endl;
	if(opt[n]==20)cout<<"bhole"<<endl;
	if(opt[n]==21)cout<<"whhole"<<endl;
	if(opt[n]==22)cout<<"wormhole"<<endl;
	if(opt[n]==23)cout<<"sfist"<<endl;
	if(opt[n]==24)cout<<"mfist"<<endl;
	if(opt[n]==25)cout<<"bfist"<<endl;
	if(opt[n]==26)cout<<"strfist"<<endl;
	if(opt[n]==27)cout<<"shield"<<endl;
	if(opt[n]==28)cout<<"clock"<<endl;
}
void prin(int nm){
	if(nm==1)cout<<"jade ";
	if(nm==2)cout<<"defend ";
	if(nm==3)cout<<"move ";
	if(nm==4)cout<<"rebound ";
	if(nm==5)cout<<"poke ";
	if(nm==6)cout<<"th ";
	if(nm==7)cout<<"tth ";
	if(nm==8)cout<<"hm ";
	if(nm==9)cout<<"spig ";
	if(nm==10)cout<<"mpig ";
	if(nm==11)cout<<"bpig ";
	if(nm==12)cout<<"fpig ";
	if(nm==13)cout<<"bfpig ";
	if(nm==14)cout<<"slight ";
	if(nm==15)cout<<"mlight ";
	if(nm==16)cout<<"blight ";
	if(nm==17)cout<<"chop ";
	if(nm==18)cout<<"strchop ";
	if(nm==19)cout<<"pchop ";
	if(nm==20)cout<<"bhole ";
	if(nm==21)cout<<"whhole ";
	if(nm==22)cout<<"wormhole ";
	if(nm==23)cout<<"sfist ";
	if(nm==24)cout<<"mfist ";
	if(nm==25)cout<<"bfist ";
	if(nm==26)cout<<"strfist ";
	if(nm==27)cout<<"shield ";
	if(nm==28)cout<<"clock ";
}
void eat(int n){
	
}
void summarize(){
	if(opt[1]<23 and opt[1]>19){
		if(opt[0]<23 and opt[0]>19){
			if(dmg[opt[1]]>dmg[opt[0]]){
				damage(0,dmg[opt[1]]);
			}
			if(dmg[opt[1]]<dmg[opt[0]]){
				damage(1,dmg[opt[0]]);
			}
		}
		else{
			if(opt[0]==4){
				damage(1,dmg[opt[1]]);
			}
			else{
				eat(1);
				damage(0,dmg[opt[1]]);
			}
		}
	}
	else{
		if(opt[0]<23 and opt[0]>19){
			if(opt[1]==4){
				damage(0,dmg[opt[0]]);
			}
			else{
				eat(0);
				damage(1,dmg[opt[0]]);
			}
		}
		else{
			if(dmg[opt[1]]==0 and dmg[opt[0]]!=0){
				if(opt[1]==27){
					if(dmg[opt[0]]>=4){
						damage(1,dmg[opt[0]]-3);
					}
					shield[1][0]--;
				}
				if(opt[1]==28){
					if(dmg[opt[0]]==0.5){
						shield[1][0]++;
					}
					shield[1][1]--;
				}
				if(opt[1]==3){
					if((opt[0]>=5 and opt[0]<=8) or (opt[0]>=14 and opt[0]<=15)){}
					else damage(1,dmg[opt[0]]);
				}
				if(opt[1]==4){
					if(opt[0]==23 or opt[0]==18 or opt[0]==19 or opt[0]==9){
						damage(0,dmg[opt[0]]);
					}
					else{
						damage(1,dmg[opt[0]]);
					}
				}
				if(opt[1]==2){
					if(opt[0]!=5 and opt[0]!=9 and opt[0]!=14 and opt[0]!=17){
						damage(1,dmg[opt[0]]);
					}
				}
				if(opt[1]==1){
					if(opt[0]!=23){
						damage(1,dmg[opt[0]]);
					}
				}
			}
			if(dmg[opt[0]]==0 and dmg[opt[1]]!=0){
				if(opt[0]==27){
					if(dmg[opt[1]]>=4){
						damage(0,dmg[opt[1]]-3);
					}
					shield[0][0]--;
				}
				if(opt[0]==28){
					if(dmg[opt[1]]==0.5){
						shield[0][0]++;
					}
					shield[0][1]--;
				}
				if(opt[0]==3){
					if((opt[1]>=5 and opt[1]<=8) or (opt[1]>=14 and opt[1]<=15)){}
					else damage(0,dmg[opt[1]]);
				}
				if(opt[0]==4){
					if(opt[1]==23 or opt[1]==18 or opt[1]==19 or opt[1]==9){
						damage(1,dmg[opt[1]]);
					}
					else{
						damage(0,dmg[opt[1]]);
					}
				}
				if(opt[0]==2){
					if(opt[1]!=5 and opt[1]!=9 and opt[1]!=14 and opt[1]!=17){
						damage(0,dmg[opt[1]]);
					}
				}
				if(opt[0]==1){
					if(opt[1]!=23){
						damage(0,dmg[opt[1]]);
					}
				}
			}
			if(dmg[opt[0]]!=0 and dmg[opt[1]]!=0){
				if(opt[0]==23 and opt[1]==5){
					damage(1,0.5);
				}
				else{
					if(opt[1]==23 and opt[0]==5){
						damage(0,0.5);
					}
					else{
						if(dmg[opt[1]]>dmg[opt[0]]){
							damage(0,dmg[opt[1]]);
						}
						if(dmg[opt[0]]>dmg[opt[1]]){
							damage(1,dmg[opt[0]]);
						}
					}
				}
			}
		}
	}
	cout<<"player0 is    ";
	propt(0);
	cout<<endl<<"player1 is    ";
	propt(1);
	cout<<endl;
	if(winner==1){
		cout<<"player 1 win"<<endl;
	}
	if(winner==0){
		cout<<"player 0 win"<<endl;
	}
}
void p(int n){
	pri(n);
	if(year[n]>=4)year[n]=0;
	opt[n]=-1;
	while(!chck(n)){
		cin>>opt[n];
	}
}
void game(){
	cout<<"M=";
	cin>>M;
	cnt=0;
	system("pause");
	system("cls"); 
	clear();
	winner=-1;
	while (true){
		p(0);
		system("cls"); 
		system("pause");
		system("cls"); 
		p(1);
		system("cls");
		summarize();
		system("pause");
		system("cls"); 
		history[0][cnt]=opt[0];
		history[1][cnt]=opt[1];
		cnt++;
		if (winner !=-1)break;
	}
}

int main(){
	int ply=1;
	while(ply>0){
		game();
		cout<<"history  check?"<<endl;
		int a;
		cin>>a;
		if(a==114){
			pri(0);
			cout<<endl;
			pri(1);
			cout<<endl;
			for(int i=0;i<=cnt;i++){
				prin(history[0][i]);
				prin(history[1][i]);
				cout<<endl;
			}
		}
		system("pause");
		system("cls");
		if(winner==0)win0++;
		if(winner==1)win1++;
		cout<<"player0:"<<win0<<endl;
		cout<<"player0:"<<(double(win0*100))/(double(win0+win1))<<"%"<<endl;
		cout<<"player1:"<<win1<<endl;
		cout<<"player1:"<<(double(win1*100))/(double(win0+win1))<<"%"<<endl;
		cout<<"play?";
		cin>>ply;
	}
	
}