//蒟蒻自制,MAYBE有一点bug

#include <bits/stdc++.h>
#include <cstdlib>
#include <ctime>
#include <unistd.h> 
#include <windows.h>
using namespace std;
//防止版本低to_string CE 
string tostr(int x){
    string res;
    if(x==0) return "0";
    bool neg=0;
    if(x<0){
        neg=1;
        x=-x;
    }
    while(x>0){
        res+=(char)('0'+(x%10));
        x/=10;
    }
    if(neg)res+='-';
    reverse(res.begin(), res.end());
    return res;
}
void scolor(int a){
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a/**16+0*/);
} 
//数字	颜色
//0	黑色
//1	蓝色
//2	绿色
//3	青色(浅蓝)
//4	红色
//5	紫色(洋红)
//6	黄色
//7	白色(默认)
//8	灰色(暗灰)
//9	亮蓝
//10	亮绿(A)
//11	亮青(B)
//12	亮红(C)
//13	亮紫(D)
//14	亮黄(E)
//15	亮白(F)
string s[4]={" ","剪刀","石头","布"};
struct Game{
	int wingame,losegame,okgame,sumgame,killwho;
	Game(){
		wingame=0;
		losegame=0;
		okgame=0;
		sumgame=0;
		killwho=0;
	}
};
void prinsc(string username,int wingame,int losegame,int okgame,int sumgame){
	cout << username << "的战绩:\n";
	cout << "赢局:" << wingame << "\n";
	cout << "输局:" << losegame << "\n";
	cout << "平局:" << okgame << "\n";
	cout << "总场次:" << sumgame << "\n";
}
int getit(int l,int r){
	int kill;
	do{
		cin >> kill;
		if(kill>r||kill<l){
			cout << "输入给我输入好的啊," << l << "~" << r << '\n';
		}
	} while(kill<l||kill>r);
	return kill;
}
bool iwin(int a,int b){
	if((a==2&&b==1)||(a==3&&b==2)||(a==1&&b==3)){
		return 1;
	}
	return 0;
}
int main(){
	srand(time(0));
	while(1){
		system("cls");
		scolor(7);
		int cl;
		cout << "请选择颜色:0黑色(慎用) 1蓝色 2绿色 3青色 4红色 5紫色 6黄色 7白色 8灰色 9亮蓝 10亮绿 11亮青 12亮红 13亮紫 14亮黄 15亮白 16随机 17???\n"; 
		cl=getit(0,17);
		bool k=(cl==17);
		if(cl!=16)scolor(cl);
		else scolor(rand()); 
		system("cls");
		int choose;
		cout << "请选择模式:1:普通 2:super 0结束\n";
		if(k)scolor(rand()); 
		choose=getit(0,2);
		if(choose==1){
			system("cls");
			cout << "石头剪刀布(普通):\n石头>剪刀;剪刀>布;布>石头\n请选择是人机对战还是真人对战:\n1为人机对战 2为真人对战 0结束游戏\n";
			if(k)scolor(rand()); 
			int mod;
			mod=getit(0,2);
			if(!mod)goto en2;
			if(mod==1){
				string username;
				cout << "人机局\n请输入名字:\n";
				if(k)scolor(rand()); 
				cin >> username; 
				int user,wingame=0,losegame=0,okgame=0,sumgame=0;
				while(1){
					int robot=rand()%3+1;
					int kill; 
					cout << "请输入您想要出的动作:1.剪刀 2.石头 3.布\n0为结束游戏(输入数字)";
					if(k)scolor(rand()); 
					user=getit(0,3);
					if(!user){
						break;
					}
					cout << "您出的" << s[user] << " 人机出的" << s[robot] << '\n';	
					if(k)scolor(rand()); 
					if(user==robot){	
						cout << "平局\n";
						okgame++;
					}else if(!iwin(user,robot)){
						cout << "失败\n";
						losegame++;
					}else {
						cout << "胜利\n";
						wingame++;
					}
					cout << "输入1继续 0结束\n";
					if(k)scolor(rand()); 
					kill=getit(0,1);
					if(!kill)break;
				}
				sumgame=wingame+losegame+okgame;
				prinsc("您",wingame,losegame,okgame,sumgame);
				if(k)scolor(rand()); 
				int kill;
			}else if(mod==2){
				cout << "真人局\n";
				if(k)scolor(rand()); 
				int user1,user2;
				string username1,username2;
				int wingame=0,losegame=0,okgame=0,sumgame=0;
				cout << "请输入名字\n玩家1:";
				if(k)scolor(rand()); 
				cin >> username1;
				cout << "\n玩家2:";
				if(k)scolor(rand()); 
				cin >> username2;
				while(1){
					int kill; 
					cout << "请输入" << username1 << "想要出的动作:1.剪刀 2.石头 3.布\n0为结束游戏(输入数字)";
					if(k)scolor(rand()); 
					user1=getit(0,3);
					if(!user1){
						break;
					}
					system("cls");
					cout << "请输入" << username2 << "想要出的动作:1.剪刀 2.石头 3.布\n0为结束游戏(输入数字)";
					if(k)scolor(rand()); 
					user2=getit(0,3);
					if(!user2){
						break;
					}
					cout << username1 << "出的" << s[user1] << " " << username2 << "出的" << s[user2] << '\n';	
					if(k)scolor(rand()); 
					if(user1==user2){	
						cout << "平局\n";
						okgame++;
					}else if(!iwin(user1,user2)){
						cout << username2 << "失败,"<< username1 << "胜利\n";
						losegame++;
					}else {
						cout << username1 << "失败,"<< username2 << "胜利\n";
						wingame++;
					}
					if(k)scolor(rand()); 
					cout << "输入1继续 0结束\n";
					kill=getit(0,1);
					if(!kill)break;
				}
				sumgame=wingame+losegame+okgame;
				prinsc(username1,losegame,wingame,okgame,sumgame);
				if(k)scolor(rand()); 
				prinsc(username2,wingame,losegame,okgame,sumgame);
				if(k)scolor(rand()); 
			}
		}else if(choose==2){
			system("cls");
			cout << "石头剪刀布(super):\n石头>剪刀;剪刀>布;布>石头\n1为对战 0为结束游戏\n";
			if(k)scolor(rand()); 
			int mod;
			mod=getit(0,1);
			if(!mod)goto en2;
			else{
				cout << "真人/人机局\n请输入人数,2~10\n";
				if(k)scolor(rand()); 
				int usercnt;
				usercnt=getit(2,10);
				int user[15];
				string username[15];
				Game usergame[15];
				cout << "请输入真人数,0~" << usercnt << "\n";
				if(k)scolor(rand()); 
				int trcnt;
				trcnt=getit(0,usercnt);
				for(int i=1;i<=trcnt;i++){
					cout << "请玩家" << i << "输入名字:\n";
					if(k)scolor(rand()); 
					cin >> username[i];
					username[i]=tostr(i)+"号"+username[i];
				}
				int robot[15];
				string robotname[15];
				int robotkill[15];
				for(int i=trcnt+1;i<=usercnt;i++){
					robotname[i]=tostr(i)+"号(人机)";
				}
				while(1){
					int kill;
					bool flag=0;
					for(int i=trcnt+1;i<=usercnt;i++){
						do{
							robotkill[i]=rand()%usercnt+1;
						}while(robotkill[i]==i);
					}
					for(int ti=1;ti<=trcnt;ti++){
						system("cls");
						cout << "请输入" << username[ti] << "想要出的动作:1.剪刀 2.石头 3.布\n0为结束游戏(输入数字)\n";
						if(k)scolor(rand()); 
						user[ti]=getit(0,3);
						if(user[ti]==0){
							goto en;
						}
						cout << "请选择决斗对象:\n";
						if(k)scolor(rand()); 
						for(int i=1;i<=trcnt;i++){
							cout << i << ".  " << username[i] << '\n';
						}
						for(int i=trcnt+1;i<=usercnt;i++){
							cout << i << ".  " << robotname[i] << '\n';
						}
						do{
							usergame[ti].killwho=getit(1,usercnt);
							if(usergame[ti].killwho==ti)cout << "不可为自己!\n";
							if(k)scolor(rand()); 
						}while(usergame[ti].killwho==ti);

					}
					for(int i=trcnt+1;i<=usercnt;i++){
						robot[i]=rand()%3+1;
					}
					for(int i=1;i<=trcnt;i++){
						if(flag) goto en;
						int opp=usergame[i].killwho;
						cout << username[i] << "的决斗对象是:" << opp << "\n";
						if(k)scolor(rand()); 
						string userobjname;  
						int userobjact;   
						if(opp<=trcnt){
							userobjact=user[opp];
							userobjname=username[opp];
						}else{
							userobjact=robot[opp];
							userobjname=robotname[opp];
						}
						cout << username[i] << "出的" << s[user[i]] << " " << userobjname << "出的" << s[userobjact] << "\n";
						if(k)scolor(rand()); 
						if(user[i]==userobjact){
							cout << "平局\n";
							usergame[i].okgame++;
							if(opp<=trcnt) usergame[opp].okgame++;
						}else if(!iwin(user[i],userobjact)){
							cout << username[i] << "失败,"<< userobjname << "胜利\n";
							usergame[i].losegame++;
							if(opp<=trcnt) usergame[opp].wingame++;
						}else {
							cout << userobjname << "失败,"<< username[i] << "胜利\n";
							usergame[i].wingame++;
							if(opp<=trcnt) usergame[opp].losegame++;
						}
						if(k)scolor(rand()); 
						cout << "输入1继续 0结束\n";
						kill=getit(0,1);
						if(!kill){goto en;}
					}
					for(int i=trcnt+1;i<=usercnt;i++){
						if(flag) goto en;
						cout << robotname[i] << "的决斗对象是:";
						if(k)scolor(rand()); 
						int opp=robotkill[i];
						int myact=robot[i];
						int userobjact; 
						string userobjname; 
						if(opp<=trcnt){
							userobjact=user[opp];
							userobjname=username[opp];
						}else{
							userobjact=robot[opp];
							userobjname=robotname[opp];
						}
						cout << userobjname << '\n';
						cout << robotname[i] << "出的" << s[myact] << " " << userobjname << "出的" << s[userobjact] << '\n';
						if(k)scolor(rand()); 
						if(myact==userobjact){
							cout << "平局\n";
							if(opp<=trcnt) usergame[opp].okgame++;
						}else if(!iwin(myact,userobjact)){
							cout << robotname[i] << "失败,"<< userobjname << "胜利\n";
							if(opp<=trcnt) usergame[opp].wingame++;
						}else {
							cout << userobjname << "失败,"<< robotname[i] << "胜利\n";
							if(opp<=trcnt) usergame[opp].losegame++;
						}
						if(k)scolor(rand()); 
						cout << "输入1继续 0结束\n";
						kill=getit(0,1);
						if(!kill){goto en;}
					}
				}
				en: 
				for(int i=1;i<=trcnt;i++){
					usergame[i].sumgame=usergame[i].wingame+usergame[i].okgame+usergame[i].losegame;
				}
				for(int i=1;i<=trcnt;i++){
					prinsc(username[i],usergame[i].wingame,usergame[i].losegame,usergame[i].okgame,usergame[i].sumgame);
					if(k)scolor(rand()); 
				}
			}
		}
		en2: 
		int kill;
		cout << "是否再来一局?0结束1继续\n";
		kill=getit(0,1);
		if(!kill)break;
	}
	return 0;
}