跳到正文

休闲·娱乐

石头剪刀布机器 / Rps-bot【3.0 未完工】

Real_Madrid_Fighting约 19 分钟
原文
文章信息与版本

文章信息

发布
2025年7月3日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 19 分钟
获赞
1

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#include<Windows.h>
using namespace std;
long long jishengzhi,oe,jsj,oe1,jsj1,oe2,jsj2,pre,f;
char jq,c;
void Rps_bot_1();
void Rps_bot_2();
void Rps_bot_2_1();
void Rps_bot_3();
void yuanli();
void crab();
void Rps_bot_3(){
	oe=jsj=0;
	pre=-1;
	Sleep(1500);
	system("cls");
	cout<<"你好,我是石头剪刀布机器3.0,快来和我对战吧!\n";
	Sleep(3500);
	system("cls");
	cout<<"玩几胜制?(1表示一局定胜负)\n";
	cin>>jishengzhi;
	Sleep(1000);
	system("cls");
	while(1){
		if(oe+jsj==0){
			f=rand()%1000+1;
			if(f>=1&&f<=354)
				jsj1=1;
			else if(f>=355&&f<=704)
				jsj1=2;
			else
				jsj1=3;
		}
		else{
			f=rand()%100+1;
			if(f<=25)
				jsj1=rand()%3+1;
			else{
				if(pre==)
			}
		}
		while(1){
			cout<<"【1.出石头 2.出剪刀 3.出布】\n";
			cin>>oe1;
			if(oe1<=0||oe1>=4)
				cout<<"输入无效,请重新输入\n"; 
			else
				break;
		}
		if(jsj1==1)
			cout<<"计算机出石头\n";
		else if(jsj1==2)
			cout<<"计算机出剪刀\n";
		else
			cout<<"计算机出布\n";
		if(jsj1-oe1==1||jsj1-oe1==-2){
			pre=1;
			oe++;
			cout<<"你赢了\n";
			jsj2=jsj1;
			oe2=oe1;
		}
		else if(jsj1==oe1){
			jsj2=jsj1;
			pre=0;
			cout<<"平局\n";
			oe2=oe1;
		}
		else{
			pre=2;
			jsj++;
			cout<<"你输了\n";
			jsj2=jsj1;
			oe2=oe1;
		}
		cout<<"比分"<<oe<<":"<<jsj;
		if(oe==jsj&&oe+1==jishengzhi)
			cout<<",双方拿到赛点";
		else if(jsj!=jishengzhi&&oe+1==jishengzhi)
			cout<<",你拿到赛点";
		else if(oe!=jishengzhi&&jsj+1==jishengzhi)
			cout<<",计算机拿到赛点";
		cout<<"\n";
		if(oe==jishengzhi||jsj==jishengzhi){
			if(oe==jishengzhi)
				cout<<"你获胜!\n";
			else
				cout<<"计算机获胜!\n";
			cout<<"A.查看猜拳原理。\nB.换1.0试试。\nC.换2.0试试。\nD.换螃蟹模式试试。\nE.退出。\n";
			while(1){
				cin>>c;
				if(c=='A')
					yuanli();
				else if(c=='B')
					Rps_bot_1();
				else if(c=='C')
					Rps_bot_2();
				else if(c=='D')
					crab();
				else if(c=='E')
					exit(0);
				else
					cout<<"输入不合法,请重新输入\n";
			}
		}
		else{
			Sleep(2500);
			system("cls");
		}
	}
}
void Rps_bot_1(){
	oe=jsj=0;
	Sleep(1500);
	system("cls");
	cout<<"你好,我是石头剪刀布机器1.0,快来和我对战吧!\n";
	Sleep(3000);
	system("cls");
	cout<<"玩几胜制?(1表示一局定胜负)\n";
	cin>>jishengzhi;
	Sleep(1000);
	system("cls");
	while(1){
		while(1){
			cout<<"【1.出石头 2.出剪刀 3.出布】\n";
			cin>>oe1;
			if(oe1<=0||oe1>=4)
				cout<<"输入无效,请重新输入\n"; 
			else
				break;
		}
		jsj1=rand()%3+1;
		if(jsj1==1)
			cout<<"计算机出石头\n";
		else if(jsj1==2)
			cout<<"计算机出剪刀\n";
		else
			cout<<"计算机出布\n";
		if(jsj1-oe1==1||jsj1-oe1==-2){
			oe++;
			cout<<"你赢了\n";
		}
		else if(jsj1==oe1)
			cout<<"平局\n";
		else{
			jsj++;
			cout<<"你输了\n";
		}
		cout<<"比分"<<oe<<":"<<jsj;
		if(oe==jsj&&oe+1==jishengzhi)
			cout<<",双方拿到赛点";
		else if(jsj!=jishengzhi&&oe+1==jishengzhi)
			cout<<",你拿到赛点";
		else if(oe!=jishengzhi&&jsj+1==jishengzhi)
			cout<<",计算机拿到赛点";
		cout<<"\n";
		if(oe==jishengzhi||jsj==jishengzhi){
			if(oe==jishengzhi)
				cout<<"你获胜!\n";
			else
				cout<<"计算机获胜!\n";
			cout<<"A.换2.0试试。\nB.换2.1试试。\nC.换螃蟹模式试试。\nD.退出。\n";
			while(1){
				cin>>c;
				if(c=='A')
					Rps_bot_2();
				else if(c=='B')
					Rps_bot_2_1();
				else if(c=='C')
					crab();
				else if(c=='D')
					exit(0);
				else
					cout<<"输入不合法,请重新输入\n";
			}
		}
		else{
			Sleep(2500);
			system("cls");
		}
	}
}
void yuanli(){
	Sleep(2000);
	system("cls");
	cout<<"知道我刚才是怎么玩的吗?现在我就来揭晓谜底吧。\n";
	Sleep(3500);
	cout<<"根据国际石头剪刀布协会的数次实验统计信息,在所有实验对象中第一次出布的概率为29.6%,第一次出剪刀的概率为35%,而第一次出石头的概率最高,为35.4%。所以第一次出布能压制对手的概率最高。\n";
	Sleep(6000);
	cout<<"接下来就进入了心理博弈阶段。根据实验统计信息,大家出拳有一个规律:获胜保持不变,平、负做出调整。因此,你只要根据这个规律猜出对手接下来要出什么,然后出能战胜这个手势的手势就行了。\n";
	Sleep(6000);
	cout<<"具体策略如下:如果你上一轮赢了,就出对手刚出过的手势;如果你上一轮输了,就出上一轮双方都没有出过的手势;如果上一轮是平局,就出胜过上一轮出过的手势的手势。\n";
	Sleep(6000);
	cout<<"最后也是最重要的一道提醒:用这个“必胜策略”的唯一难点就是对手可能也学过这招(毕竟如果让两个Rps-bot 2.0对战,永远都是平局,包括刚学过这些策略的你!)。\n";
	Sleep(6000);
	cout<<"所以这时,你就可以玩这招:以其人之道还治其人之身。你可以站在对方的角度,用上面的策略想想如果你是对方,你会出什么;然后出能胜过这个手势的手势即可。\n";
	Sleep(6000);
	cout<<"不过“以其人之道还其人之身”仅用于少数几轮的试探,除非你确定对手学过前面的招数而又不知道“以其人之道还治其人之身”,你才可以全用这招。注意对手可能会中途变卦换招数,所以你也要学会随机应变,不要死板地按照所谓的必胜原理来。2.1版本就是仅在少数轮次(概率为15%)使用“以其人之道还治其人之身”招数。\n";
	Sleep(6000);
	cout<<"学到了这些锦囊妙计的你,赶紧去和小伙伴练练手吧!(当然,你也可以用第二招把2.0打得片甲不留!)\n";
	Sleep(2000);
	cout<<"A.试试1.0。\nB.试试2.0。\nC.试试2.1。\nD.试试螃蟹模式。\nE.退出。\n";
	while(1){
		cin>>c;
		if(c=='A')
			Rps_bot_1();
		else if(c=='B')
			Rps_bot_2();
		else if(c=='C')
			Rps_bot_2_1();
		else if(c=='D')
			crab();
		else if(c=='E')
			exit(0);
		else
			cout<<"输入不合法,请重新输入\n";
	}
}
void Rps_bot_2(){
	oe=jsj=0;
	pre=-1;
	Sleep(1500);
	system("cls");
	cout<<"你好,我是石头剪刀布机器2.0!和上一个版本(石头剪刀布机器1.0,纯随机)不同,这个版本的我加入了一些对战策略。快去试试吧!\n";
	Sleep(3000);
	system("cls");
	cout<<"玩几胜制?(1表示一局定胜负)\n";
	cin>>jishengzhi;
	Sleep(1000);
	system("cls");
	while(1){
		if(oe+jsj==0)
			jsj1=3;
		else if(pre==1||pre==2){
			if(jsj2==3)
				jsj1=1;
			else
				jsj1=jsj2+1;
		}
		else{
			if(jsj2==1)
				jsj1=3;
			else
				jsj1=jsj2-1;
		}
		while(1){
			cout<<"【1.出石头 2.出剪刀 3.出布】\n";
			cin>>oe1;
			if(oe1<=0||oe1>=4)
				cout<<"输入无效,请重新输入\n"; 
			else
				break;
		}
		if(jsj1==1)
			cout<<"计算机出石头\n";
		else if(jsj1==2)
			cout<<"计算机出剪刀\n";
		else
			cout<<"计算机出布\n";
		if(jsj1-oe1==1||jsj1-oe1==-2){
			pre=1;
			oe++;
			cout<<"你赢了\n";
			jsj2=jsj1;
			oe2=oe1;
		}
		else if(jsj1==oe1){
			pre=0;
			cout<<"平局\n";
			jsj2=jsj1;
			oe2=oe1;
		}
		else{
			pre=2;
			jsj++;
			cout<<"你输了\n";
			jsj2=jsj1;
			oe2=oe1; 
		}
		cout<<"比分"<<oe<<":"<<jsj;
		if(oe==jsj&&oe+1==jishengzhi)
			cout<<",双方拿到赛点";
		else if(jsj!=jishengzhi&&oe+1==jishengzhi)
			cout<<",你拿到赛点";
		else if(oe!=jishengzhi&&jsj+1==jishengzhi)
			cout<<",计算机拿到赛点";
		cout<<"\n";
		if(oe==jishengzhi||jsj==jishengzhi){
			if(oe==jishengzhi)
				cout<<"你获胜!\n";
			else
				cout<<"计算机获胜!\n";
			cout<<"A.查看猜拳原理。\nB.换1.0试试。\nC.换2.1试试。\nD.换螃蟹模式试试。\nE.退出。\n";
			while(1){
				cin>>c;
				if(c=='A')
					yuanli();
				else if(c=='B')
					Rps_bot_1();
				else if(c=='C')
					Rps_bot_2_1();
				else if(c=='D')
					crab();
				else if(c=='E')
					exit(0);
				else
					cout<<"输入不合法,请重新输入\n";
			}
		}
		else{
			Sleep(2500);
			system("cls");
		}
	}
}
void crab(){
	oe=jsj=0;
	Sleep(1500);
	system("cls");
	cout<<"你好,我是石头剪刀布机器螃蟹模式,快来和我对战吧!\n";
	Sleep(3000);
	system("cls");
	cout<<"玩几胜制?(1表示一局定胜负)\n";
	cin>>jishengzhi;
	Sleep(1000);
	system("cls");
	while(1){
		jsj1=2;
		while(1){
			cout<<"【1.出石头 2.出剪刀 3.出布】\n";
			cin>>oe1;
			if(oe1<=0||oe1>=4)
				cout<<"输入无效,请重新输入\n"; 
			else
				break;
		}
		if(jsj1==1)
			cout<<"计算机出石头\n";
		else if(jsj1==2)
			cout<<"计算机出剪刀\n";
		else
			cout<<"计算机出布\n";
		if(jsj1-oe1==1||jsj1-oe1==-2){
			pre=1;
			oe++;
			cout<<"你赢了\n";
			jsj2=jsj1;
			oe2=oe1;
		}
		else if(jsj1==oe1){
			pre=0;
			cout<<"平局\n";
			jsj2=jsj1;
			oe2=oe1;
		}
		else{
			pre=2;
			jsj++;
			cout<<"你输了\n";
			jsj2=jsj1;
			oe2=oe1; 
		}
		cout<<"比分"<<oe<<":"<<jsj;
		if(oe==jsj&&oe+1==jishengzhi)
			cout<<",双方拿到赛点";
		else if(jsj!=jishengzhi&&oe+1==jishengzhi)
			cout<<",你拿到赛点";
		else if(oe!=jishengzhi&&jsj+1==jishengzhi)
			cout<<",计算机拿到赛点";
		cout<<"\n";
		if(oe==jishengzhi||jsj==jishengzhi){
			if(oe==jishengzhi)
				cout<<"你获胜!\n";
			else
				cout<<"计算机获胜!\n";
			cout<<"A.换1.0试试。\nB.换2.0试试。\nC.换2.1试试。\nD.退出。\n";
			while(1){
				cin>>c;
				if(c=='A')
					Rps_bot_1();
				else if(c=='B')
					Rps_bot_2();
				else if(c=='C')
					Rps_bot_2_1;
				else if(c=='D')
					exit(0);
				else
					cout<<"输入不合法,请重新输入\n";
			}
		}
		else{
			Sleep(2500);
			system("cls");
		}
	}
}
void Rps_bot_2_1(){
	oe=jsj=0;
	pre=-1;
	Sleep(1500);
	system("cls");
	cout<<"你好,我是石头剪刀布机器2.1!和上一个版本(石头剪刀布机器2.0,仅采用必胜策略)不同,这个版本的我又加入了“以其人之道还治其人之身”。快去试试吧!\n";
	Sleep(3500);
	system("cls");
	cout<<"玩几胜制?(1表示一局定胜负)\n";
	cin>>jishengzhi;
	Sleep(1000);
	system("cls");
	while(1){
		if(oe+jsj==0)
			jsj1=3;
		else if(pre==1||pre==2){
			if(jsj2==3)
				jsj1=1;
			else
				jsj1=jsj2+1;
		}
		else{
			if(jsj2==1)
				jsj1=3;
			else
				jsj1=jsj2-1;
		}
		f=rand()%100+1;
		if(f>=85){
			if(pre==-1)
				jsj1=2;
			else if(pre==0||pre==2){
				if(jsj2==3)
					jsj1=1;
				else
					jsj1=jsj2+1;
			}
			else{
				if(jsj2==1)
					jsj1=3;
				else
					jsj1=jsj2-1;
			}
		}
		while(1){
			cout<<"【1.出石头 2.出剪刀 3.出布】\n";
			cin>>oe1;
			if(oe1<=0||oe1>=4)
				cout<<"输入无效,请重新输入\n"; 
			else
				break;
		}
		if(jsj1==1)
			cout<<"计算机出石头\n";
		else if(jsj1==2)
			cout<<"计算机出剪刀\n";
		else
			cout<<"计算机出布\n";
		if(jsj1-oe1==1||jsj1-oe1==-2){
			pre=1;
			oe++;
			cout<<"你赢了\n";
			jsj2=jsj1;
			oe2=oe1;
		}
		else if(jsj1==oe1){
			pre=0;
			cout<<"平局\n";
			jsj2=jsj1;
			oe2=oe1;
		}
		else{
			pre=2;
			jsj++;
			cout<<"你输了\n";
			jsj2=jsj1;
			oe2=oe1; 
		}
		cout<<"比分"<<oe<<":"<<jsj;
		if(oe==jsj&&oe+1==jishengzhi)
			cout<<",双方拿到赛点";
		else if(jsj!=jishengzhi&&oe+1==jishengzhi)
			cout<<",你拿到赛点";
		else if(oe!=jishengzhi&&jsj+1==jishengzhi)
			cout<<",计算机拿到赛点";
		cout<<"\n";
		if(oe==jishengzhi||jsj==jishengzhi){
			if(oe==jishengzhi)
				cout<<"你获胜!\n";
			else
				cout<<"计算机获胜!\n";
			cout<<"A.查看猜拳原理。\nB.换1.0试试。\nC.换2.0试试。\nD.换螃蟹模式试试。\nE.退出。\n";
			while(1){
				cin>>c;
				if(c=='A')
					yuanli();
				else if(c=='B')
					Rps_bot_1();
				else if(c=='C')
					Rps_bot_2();
				else if(c=='D')
					crab();
				else if(c=='E')
					exit(0);
				else
					cout<<"输入不合法,请重新输入\n";
			}
		}
		else{
			Sleep(2500);
			system("cls");
		}
	}
}
int main(){
	srand(time(NULL));
	cout<<"请选择对战模式:\nA.石头剪刀布机器1.0\nB.石头剪刀布机器2.0\nC.石头剪刀布机器2.1\nD.螃蟹模式\n";
	while(1){
		cin>>jq;
		if(jq=='A')
			Rps_bot_1();
		else if(jq=='B')
			Rps_bot_2();
		else if(jq=='C')
			Rps_bot_2_1();
		else if(jq=='D')
			crab();
		else
			cout<<"输入不合法,请重新输入\n";
	}
}
原文
存档评论1 条抓取于