Increasing the number of random games

"23" game is a game where props 23 toothpicks, players take turns 1, 2 or 3 toothpicks.
Finally got a toothpick is the loser. Write a computer program and play "23."
Players always go first, turn to the computer, which act in accordance with the following rules:
. A toothpick If the remaining more than four, the computer will take away 4 - x root, x is the number of players the last removal of a toothpick
. B if the remaining 2--4 toothpicks, toothpick computer removed enough to ensure that only one
. c If the remaining a toothpick, the computer can only take it away and throw in the towel
when the players enter the number of toothpicks to be removed, the procedure to deal with input validity check.
To determine the number of players entered in between 1-3, and trying to take away not exceed the current remaining.
Here is the rule when toothpick more than 4, the computer 4 is removed by subtracting the number of the last players to take away, which often leads to a fixed input when the player is worth some time. Computer output will follow the same value, the player often lead to victory. (The results shown below)
Here Insert Picture Description
Here Insert Picture Description
so I will increase the difficulty of the game to upgrade a little randomness, so that we can improve the degree of difficulty of the game. So that the user at the time of extraction toothpick added difficulty. (As shown below)
Here Insert Picture Description
Here Insert Picture Description

这个我是在剩余数量大于4时才抽取随机1-3的牙签数,此处用到了#include <stdlib.h>和#include <time.h> 这两个头文件,#include <stdlib.h>的这个头文件里面包含了rand(),srand()函数这两个我们要使用的函数,rand()函数是用来生成一个随机数,srand()函数我们是用来生成一个种子在这里我们用来把time()函数嵌进去来生成当前时间的随机数。而#include <time.h>这个头文件里面我们所使用的是time()函数,time()这个函数我们主要用来获取当前时间:time(0)或者time(Null);然后把它调用在玩家抽取之后剩余数量大于4时使用。这样会提高游戏的随机发生可能性。增加了游戏的乐趣。

关键代码如下:

#include
#include <stdlib.h>//rand(),srand()函数在这个头文件中
#include <time.h> //time(0)在这个头文件中

?????
int lianxi_23deGame (int K, int G) {// K is a fixed value 23, G is a game mode
srand ((unsigned) time (NULL )); // call to the current call of this time is called seeds added
· ··
IF (K>. 4) // where K is the number of players to remove the remaining toothpicks
{
IF (G ==. 1). 4 {m = - n-;} // here performed according to the rules subject
else if ( g == 2) {m = ( rand ()% 3) + 1;} // rand ()% 3 0 In order to ensure that it is less than 3 value +1, because results
}
the else IF (K <= K. 4 && > = 2) {m = k - 1;} // when the value is equal to or less than 4 and greater than or equal to 2 when performing
?????
K = K - m; // remove the remaining number of the computer
cout << "computer Remove "<< m <<" root, the remaining "<< k <<" root "<< endl;
?????
}
}
?????
lianxi_23deGame (K, G); // this function is called again
}

Guess you like

Origin blog.csdn.net/qq_39686486/article/details/89609169