The bean game is played like this, there is a number of beans (more than 100 capsules), then stipulate that the two people take some number of beans in turn, each time the number of takes away (more than 3 pieces), And at least one piece is taken. Finally, who takes the last pile of beans to lose (of course, you can set the last wins).
This is actually a mathematical question. When you are in high school, you can't get it, but now you think about it, it is easy to get it, it seems to be progress.
Assume that the game is the last pile of beans, who will lose (will analyze this, who takes the last pile of beans, if you win, the gameplay will be easy to get it), I will analyze the mystery of this game. Quit Easy! FOLLOW ME: Analyze individual situations first, (and then promoted to the general situation) Assume that the number of people can be 3 capsules, who takes the last pile of beans to lose. First, the first hand, and the first hand will lose 1 "(you will understand why you have to do this) attention: We only want to win the situation or defeated, because when the first hand will win, Be defeated; vice versa to take three capsules each time.
1 capsule: Are you a first one? Oh, very unfortunate, you will lose. 1 2 capsules: Are you ahead? Oh, take a piece, face a cap, you will win, and he will defeat. 03 capsules: There is a former car, you should be smart, right, take two capsules, you will be 0 wins. 4 tablets: see you, three, opponents must lose. 05 capsule: Oh, it is miserable, when taken 1, 2, 3 pieces, the number of questions from the opponent is 4, 3, 2, and you will win 1 hand, you will lose. 6 capsules: Just take one, let the opponent get 5 capsules, the opponent will defend. 07 capsules: 2 capsules, the reason is the same. 08 capsules: 3 capsules, the reason is the same. 09 capsules: After the opponent gets 6, 7, and then the opponent will win, you will lose. 110 capsules: 1 capsule, let the opponent take 10 capsules. 011 tablets: Did you see the law, right, take 2 capsules. 0. . .
In summary, the winning algorithm for this small game: Who took the last bunch of who lost: When the child encountered is 1 k * (n 1) (where K is an integer, N is Every time you can take the maximum number of children), the first hand is defeated, and the rest will win first, so there is only one purpose of the game, and the child is giving the opponent to 1 k * (n 1) OK is OK.
Further push again, the opponent will win, for you, you will lose, return to the return. 1:12: For the results of 1 to reverse, it is 0.3: reflects on the above two results, and then take the intersection. (1 && 0) = 04: Inverted the above three results, then take the set. (0 && 1 && 1) = 05: Reverse the three results above, and then take the intersection. (1 && 1 && 1) = 1 must lose. . . . GOT IT? Who took the last bunch of who wins: The method of the analysis (omitted) is the same (omitted) above, the summary is the first person to meet K * (n 1) when it is defeated. The following is a AI class (C language description) of this effect (Int Winmode, int NetNum, Int LimitNum); int it netnum, int limited; int Aithinking (int Winmode, int NetNum , int LimitNum, int ailevel
}; intloy :: HIGHAI (int WINMODE, INTNUM, INT LIMITNUM) {Int Outnum = 0; int T = 0; switch (Winmode) {// 1 Who takes the last most lost, 0 who takes the last Who wins Case 1: IF ((t = (NetNum-1)) == 0) {// helpless, this is the defeated situation, I have to wait for an error. OUTNUM = lowai (NetNum, LimitNum);} else {// One hit Outnum = T;} Break; case 0: IF ((t = (NetNum% (LimitNum 1)) == 0) {// Helpless, this is the defeated situation, I have to wait for an opponent to go wrong. Outnum = lowai (NetNum, LimitNum);} else {OUTNUM = T;} Break;} Return Outnum;} intloy: {Int outnum = 0; randomize (); do {Outnum = Random (LimitNum) 1;} while (Outnum> NetNum); Return Outnum;} intloy :: Aithinking (int WinMode, int NetNum, int Limitnum, int ailevel) {int outnu = 0; switch (ailevel) {//// Behind the adjustable Ailevel, do Case 0: OUTNUM = Lowai (NetNum, LimitNum); Break; Case 1: Outnum = HIGHAI (WINMODE, NETNUM, LIMITNUM); BREAK;} Return Outnum;}