简单的石头剪刀布(机器胜率略高)
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int a,b,c;
cout<<"人机剪刀石头布游戏现在开始:"<<endl;
cout<<"1表石头,2表布,3表剪刀,0退出游戏"<<endl<<"请输入:"<<endl;
while(scanf("%d",&a)!=EOF)
{
if(a==0) break;
int n=rand()%4;
if(a==1)
{
cout<<"人类出石头"<<" ";
if(n>a) cout<<"电脑出布"<<endl<<"电脑胜"<<endl;
if(n==a) cout<<"电脑出石头"<<endl<<"平局"<<endl;
if(n<a) cout<<"电脑出剪刀"<<endl<<"人类胜"<<endl;
}
else if(a==2)
{
cout<<"人类出布"<<" ";
if(n>a) cout<<"电脑出剪刀"<<endl<<"电脑胜"<<endl;
if(n==a) cout<<"电脑出布"<<endl<<"平局"<<endl;
if(n<a) cout<<"电脑出石头"<<endl<<"人类胜"<<endl;
}
else if(a==3)
{
cout<<"人类出剪刀"<<" ";
if(n>a) cout<<"电脑出石头"<<endl<<"电脑胜"<<endl;
if(n==a) cout<<"电脑出剪刀"<<endl<<"平局"<<endl;
if(n<a) cout<<"电脑出布"<<endl<<"人类胜"<<endl;
}
else cout<<"出错,请输入1-3的数"<<endl;
getchar();
}
cout<<"退出游戏"<<endl;
return 0;
}
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int a,b,c;
cout<<"人机剪刀石头布游戏现在开始:"<<endl;
cout<<"1表石头,2表布,3表剪刀,0退出游戏"<<endl<<"请输入:"<<endl;
while(scanf("%d",&a)!=EOF)
{
if(a==0) break;
int n=rand()%4;
if(a==1)
{
cout<<"人类出石头"<<" ";
if(n>a) cout<<"电脑出布"<<endl<<"电脑胜"<<endl;
if(n==a) cout<<"电脑出石头"<<endl<<"平局"<<endl;
if(n<a) cout<<"电脑出剪刀"<<endl<<"人类胜"<<endl;
}
else if(a==2)
{
cout<<"人类出布"<<" ";
if(n>a) cout<<"电脑出剪刀"<<endl<<"电脑胜"<<endl;
if(n==a) cout<<"电脑出布"<<endl<<"平局"<<endl;
if(n<a) cout<<"电脑出石头"<<endl<<"人类胜"<<endl;
}
else if(a==3)
{
cout<<"人类出剪刀"<<" ";
if(n>a) cout<<"电脑出石头"<<endl<<"电脑胜"<<endl;
if(n==a) cout<<"电脑出剪刀"<<endl<<"平局"<<endl;
if(n<a) cout<<"电脑出布"<<endl<<"人类胜"<<endl;
}
else cout<<"出错,请输入1-3的数"<<endl;
getchar();
}
cout<<"退出游戏"<<endl;
return 0;
}