石子小游戏
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include
#include
#include
#include
using namespace std;
void rand_seed()
{
int seed=static_cast
srand(seed);
}
int rand_int(int a,int b)
{
return a+rand()%(b-a+1);
}
int main()
{string a="++++++++++";string b="|you win!|";string c="|youlose!|";
cout<<"两名游戏者分别从一堆石子中取出一定的石子。每次移动,一名游戏者选取多个石子。最少取一个石子,最多取剩余石子数目的一半,然后轮到下一位,取到最后一颗石子的算输"<
rand_seed();
int the_number=rand_int(10,100);
int the_first=rand_int(-1,1);
string the_formal;
switch(the_first)
{case 0:the_formal="sorry,the computer is the first";break;
case 1:the_formal="you are lucky,you are the first";break;
default:the_formal=" ";break;
}
cout<
{
cout<<"please choose the model hard or easy(h/e):";
cout<
cin>>the_choice;
cout<<"the number of the stones is:"<
if(the_choice=="e")
{ while(the_number!=1)
{ int s=rand_int(1,the_number/2);
int the_left=the_number-s;
the_number=the_left;
if(the_number==1){cout<cout<<"the computer get "<int your_turn;
cin>>your_turn;
the_number=the_number-your_turn;
if(the_number==1)
{cout<}
}
if(the_choice=="h")
{int s;
while(the_number!=1)
{
int n=the_number/2;
for(s=n+1;s>=2;s--)
{int j=the_number-s;
if(j==3||j==7||j==15||j==31||j==63)
{break;}
}
int the_left=the_number-s;
the_number=the_left;
if(the_number==1){cout<cout<<"the computer get "<int your_turn;
cin>>your_turn;
the_number=the_number-your_turn;
if(the_number==1){cout<}
if(the_choice!="h"||the_choice!="e")
{cout<<"you are as foolish as the computer!byebye!";
return 1;
}
}
}
if(the_first==1)
{
cout<<"please choose the model hard or easy(h/e):";
cout<
cin>>the_choice;
cout<<"the number of the stones is:"<
if(the_choice=="e")
{
while(the_numbe
r!=1)
{cout<<"it is your turn,please get some"<
cin>>your_turn;
int the_number=the_number-your_turn;
if(the_number==1){cout<int s=rand_int(1,the_number/2);
int the_left=the_number-s;
the_number=the_left;
if(the_number==1){cout<cout<<"the computer get "<
}
}
if(the_choice=="h")
{ cout<<"now,it is your turn ,please choose a number:";
while(the_number!=1)
{
int your_turn;
cin>>your_turn;
the_number=the_number-your_turn;
if(the_number=1){cout<int n=the_number/2;
for(int s=n+1;s>=2;s--)
{int j=the_number-s;
if(j==3||j==7||j==15||j==31||j==63)
{break;}
}
int the_left=the_number-s;
the_number=the_left;
if(the_number==1){cout<cout<<"the computer get "<
}
}
if(the_choice!="h"||the_choice!="e")
{cout<<"you are as foolish as the computer!byebye!";
return 1;
}
}
return 0;
}