Game (part of the aid in the understanding of the reproduced content + partial self-described)

First, the definition of the usual game of Nim is this: There are several heap of stones, the number of each pile of stones is limited, the legal move is "a pile of stones and took some choice pieces (can not fail to take)," if the turn when someone heap all the stones have been to take the empty, the penalty negative (because he has no legal move at the moment).

We know that for the most common most common NIM take stones, all together, if the number of stones XOR is 0, then losing the upper hand, if not zero then the upper hand to win.

Concrete evidence of the following:

1, the final status of the game must be the number of all the stones is 0, can also be seen that all stones XOR to zero.
2, if it is now the exclusive OR of all the stones is J, their we Ai represents i-th stack number of stones, a total of n stack. Then there A1 ^ A2 ^ A3 ...... ^ An = j, j we have binary representation, then A must be the highest level in a number of the most significant bit is 1 and j is the same (the same number of digits), or that 1 j come from? Then we make this number is Am, So Am ^ j must be smaller than Am, apparently eliminate the most significant bit is smaller. We can take the stones to become Am Am ^ j, then for the original formula is A2 ^ ...... ^ ^ A1 An ^ J ^ J = J = 0;
3, if it is exclusive or 0, so if any of the stones removed, the new XOR certainly is not 0, the proof is very simple for the reader to solve. (Lazy ~)

So when XOR is not 0, can make it through the operation becomes 0, it is clear that there will be a conclusion on it.

So now we have a heavy head.

For a big game, we see it as a number of small game, such as this take the stones, we see it as n small game.
Now we consider a single game, that is, how to solve a pile of stones.
We mex operation for a predetermined set, it indicates the smallest integer not belong to the set of non-negative.
Few chestnut: mex {0,1,2} = 3, mex {1,2,3} = 0, mex {0,1,3} = 2;

We then define a function SG: SG (x) = mex { SG (y) | y } is the successor of x.
What is the successor x of y? We give chestnuts with ordinary NIM game. If a pile of stones is the number of x, the normal game NIM may take any number, but can not take a, so that the successor x 0 ~ x-1, so the value of y 0 ~ x-1.
There is a general conclusion is taken stones SG (x) = x.

We consider the nature of SG function, we put the game as a map, it is actually a point running in this picture above, when the point when it went 0 walk. SG value of 0 indicates that the current point of losing point because it SG following values are greater than 0. SG value is greater than 0, the current point is a win point, because it can come a point value SG 0.
Therefore, the conclusion is losing SG is 0, SG is greater than 0 win.
----------------
Original link: https: //blog.csdn.net/Kamisama123/article/details/776491189118

Third, the combination of the game state
  that some readers may have found, first proposed in three games, there are many states are equivalent. For example, in Flip Game, two plus sign ( "+") and three plus signs ( "+++") is equivalent to the state, because after all they step on the way out; grab votes in game, a rectangle and a rectangle 3x2 2x3 is equivalent to the state. Equivalent state for many reasons, one of which is the same as some combination of the two states are mutually independent sub-state. Here, the "independent" is meant any further action the player can only affect a sub-state. For example, in the Flip Game, "+++ ± + ± -" and "- + ± - ++++" is equivalent to a state that they are "2 plus" and "four plus" combination of two sub-states. The natural state of Nim game is a combination of a number of sub-states, each heap of stones is a sub-state. Can be inferred if the outcome of a combination thereof (hereinafter referred to as "parent state") by the outcome of the sub-state, then the state can significantly reduce the number of memory needs to be considered during the search, to improve search efficiency.

Before discussing the method of inferring from the sub-state outcome of the outcome of the mother state, I would like to point out three other common features in the first three games. They are exactly Sprague-Grundy theorem conditions, but also the premise of all discussed below.

The above two conditions are met game called impartial game, otherwise known as partisan game. status impartial game board contains only the information, partisan game of the state need to include "Whose turn is next." Because of this, partisan game state can not be split into "independent" sub-state, because the player's every move will affect the information "under whose turn" of all sub-states.
Specifically, both the winning goal, to reach a final state of their own hands, or take the last step of the winner (termed normal play). Section three of the games can also be slightly modified rules were changed to take the final step in a negative situation (termed misère play), but the following discussion applies only to the normal play.
  Effect on the outcome of the combined state are discussed below. Please brush up victory and defeat state key state nature: After further action, defeated state can only become a state wins, it wins state may (but need not) become lost state.

Look at the combination of two defeated states. Or a combination of two defeated states defeated state. From a player's point of view FLAC, first player actions can only be a change in the state lost two wins state, then flip the player can win again this state become lost state, so that the two defeated states combination throw back to the first player. Since the final state is defeated state, the final first player will face two final states consisting of the state of failure, so the flip win.

A combination of a win and defeat look two states. A combination of state and victory or defeat state wins state - as long as the first player to win state to become lost state, you can defeat the two states combined into a defeated state of the players flip throw.

Finally, look at a combination of two wins state. This combination is more complicated: first player should not win a state wherein the state becomes lost, as this would defeat a win a victory combined into two state state leave each other. Therefore, the first player to be put into a state where a win new victory condition. FLAC players face new combination wins state + win state, should adopt the same strategy. However, because the game is limited, sooner or later there will be a player can only win the state becomes a failed state, and thus lose the game, but we did not know what would happen in one step. That is to say, only know two sub-states are state wins, the outcome is not sufficient to launch the parent state; we need to tap the nature wins state.

Four, Sprague-Grundy put forward a number of
  our Flip Game, for example, more in-depth look at what the nature wins state.

State "++" is the easiest wins state, it is only one moves, the result is lost state. State "+++" with "++" at this point is the same, so they are in fact equivalent status. Status "++++" there are two different moves (moves symmetrically the same operator): First, the intermediate plus a minus two, thus obtained sub-state "± - +" is lost state; a second is the end plus a minus two, thus obtained sub-state "- ++" or "+ ± -" (equivalent to "+") is a winning states.

So we found two different wins state. Like "++", "+++" This can only become a state wins and defeated state, which we call "a win state." Like "++++" Thus, the state can become lost, can also become a win state wins state we call "wins two states." Similarly, if a winning state may become lost state wins all states can become stages 1 to n-1, then we call "n-level wins state." Defeated states can be referred to as "zero-order."

We look at whether the combination of state and wins series related. A combination of two wins and a state is defeated state, because the first player to any further action which would be a win state to defeat state, leaving FLAC player is to win state and state combined to defeat the state wins. A combination of a two-state wins a win state and is the winner state, since first player to win two states may be changed to a state wins, the player is left flip wins two states are combined into a defeat state. Two wins and two states combined to win state also defeated state, because the first player whether it will become one of two wins and defeated state or a state wins state, leaving all the other combinations wins state.

We seem to have found a pattern: a combination of two wins and the same level of state is defeated state, a combination of two different state-level victory is to win state. Yes! Investigate two similar wins and a combination of state, no matter how to reduce the first player to win a state in which the number of levels (even turning it into a zero level of failure state), FLAC player can always win another state down to the same level, the first player will eventually lose face two states combined to defeat state. And if the first player faced with two different levels of state wins, he will always be one of the more senior wins state to a state with lower-level wins at the same level, so the player is left to flip defeated state.

For the above definitions wins state level there is a loophole: If a state wins A defeat can be turned into state or two states to win, but you can not become a state wins, then it should be considered one or three it? Proof the law also has a loophole: we default action can only make a step of reducing the number of stages to win state, then the state can not let the series victory elevated it? Key noted that the law certification process, is that if you want to reduce the number of stages in a state wins, you can either reduce the level. So we know, the above should be defined as a state A win state. This led to series wins state can be raised, but that's okay, so you can make up for the loopholes to prove the law: under the combination of the two states at the same level wins, if the first player raised a series in which a state wins, then flip players can drop it back to the original level, such a combination of two sibling wins state still defeated state.

Defined by the series win state, we address the outcome of the parent state two states win combination determined problem. In fact, our definition of "series" is the Sprague-Grundy number of legendary (abbreviated number SG). SG is a mapping from the number of state functions to a non-negative integer, and its formal definition is as follows:

★ SG (x) = mex {SG (y) | y} is the successor of x.

Wherein A, B represent states, [Equation] B represents a state A of times. mex is a function defined on a set, it indicates not belong to the set of the smallest non-negative integer, which is an abbreviation of minimum excludant. This definition in plain language, that is a state number SG, SG equal to the minimum number of times fail to get its state.
Transfer from https://zhuanlan.zhihu.com/p/20611132
------------------------------

Self-described

Known general nim game for the other double game problems most of which can be converted to the form of nim games.
1, a game of winning or losing status can be obtained by sub-state. We will issue a multi-stack, split into sub-problems.
Suppose n number of different pile of stones, in the case of fixed borrowing rules, taking n different, SG value: for SG value. SG [n] when the upper hand losing value of n 0 represents the stone, it is doomed to failure point. For other values the representative can win points, there must be victory or defeat strategy to make the next step.
SG (x) = mex {SG (y) | y } is the successor of x.

Here Insert Picture DescriptionWith the above diagram for SG-depth understanding, a 1,2,3 fact, two, three wins state, an arrow pointing to successor is, three cases may be regarded as corresponding to this layer, so the figure is not in an arrow pointed 1,2,3 have no real contact. The figure represented a "pile of stones," the SG value of the case. If the SG value is 0, it may be the case successor states 1, 2, or corresponding series win state. SG 0 losing the upper hand, because the inevitable flip wins in the state (corresponding to step through the action, defeated state can only become a state wins, it wins state there must be strategies to make the next step to become state failure or state wins.), After hand then select this case converted to failure state 0 to the upper hand, the upper hand will always fail. Similarly, a non-start SG 0, then, the upper hand can win, it can be converted to the inevitable failure state 0 threw FLAC. When a bunch of SG value is 0, the state of the outcome of the pile has been known.
After further action, defeated state can only become a state wins, wins state there must be strategies to make the next step to become state failure or state wins. 0 state is lost, the non-winning state 0 corresponding stages, so we adopted mex {} function to derive the current state by the successor state, which is a push down process. Losing successor state 0 wins series must be greater than the 0 state (failure state can only change to win state), there is a successor state 2 to state 0 (there must win policy states that the next step to become lost state or win state), note that there may be 3 exist. But subsequent represent nothing more than a few cases, state.
A series victory can be turned into low-level state, also may become high order. However, if the higher order flip taking situation, such as where 2-> 3, the upper hand can then 3-> 2, no effect on the results. And we are here to launch the SG state based on the current number of stones, could not have been 2-> 3-> 2 cycle continues, will not necessarily last 2-> 3, change back to normal.
The above process the successor state to the high-order situation, can be ignored. Also shows that when SG is 0 can also be seen as this "pile of rocks" has been taken after completion, because FLAC and then take it you will take into SG 0, which he does not take a bunch, not just get this heap rock act, can these stones to heap SG 0 heap, as 0 stone heap of stones.
In this case we can think SG value after processing the above two cases, can be seen in the SG value can be increasingly smaller, from n becomes 0 ~ n-1, which can be like a game nim heap stone, is more of a slightly different variation of the number of stones SG value changes the outcome of the case, fortunately SG value after processing both cases, the number of stone can be seen as ever fewer, in line with definition of nim games.
SG [n] value represents a "heap of stones" stones number n corresponding to the state corresponding to the outcome of the game rules given situation.
In the case of understanding the game nim correctness (for example, why use mex) in the case of how the value of nim games into SG, the basic no problem.

Published 52 original articles · won praise 2 · Views 889

Guess you like

Origin blog.csdn.net/qq_44714572/article/details/99684853
Aid