文档库 最新最全的文档下载
当前位置:文档库 › 石子小游戏

石子小游戏

#include
#include
#include
#include
#include
using namespace std;
void rand_seed()
{
int seed=static_cast(time(0));
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<<"两名游戏者分别从一堆石子中取出一定的石子。每次移动,一名游戏者选取多个石子。最少取一个石子,最多取剩余石子数目的一半,然后轮到下一位,取到最后一颗石子的算输"<string start;cout<<"please enter the /start/"<cin>>start;

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<if(the_first==0)
{

cout<<"please choose the model hard or easy(h/e):";
cout<string the_choice;
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<string the_choice;
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"<int your_turn;
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;
}

相关文档