SG functions and Nim Problems

Source: Internet
Author: User

"SD-Grundy function"

We will face more variants related to the NIM game, and we will also seeA1 ^ A2 ^... ^This value is more extensive.

In the above article, we carefully studied the NIM game and learned how to find a winning strategy. But if you add or change the NIM rules, can you quickly find a winning strategy? For example, if there are n piles of stones, one, two, or three of the 1st piles of stones can be taken each time, and an odd number of stones can be taken from the 2nd piles, you can get any stone from 3rd piles or later ...... This may seem complicated, but I believe that if you have mastered the content of this section, similar ever-changing problems will not be a problem.

Now let's look at a game that looks more general:Given a directed acyclic graph and a pawn on a starting vertex,The two players move the piece along a directed edge in turn, and those who cannot move the piece are judged to be negative. In fact, this game can be thought of as allImpartial combinatorial games. That is to say, any ICG can regard every situationA vertexTo abstract each situation and its sub-situation into a directed graph game ". The following is defined on the vertex of a directed acyclic graph.SD-garundyFunction.

First define the Mex (minimal excludant) operation, which is applied to a set operation,The smallest non-negative integer that does not belong to this set. For example, Mex {0, 1, 2, 4} = 3, Mex {2, 3, 5} = 0, and Mex {} = 0.

For a givenDirected acyclic graph,The following figure shows the description of the SD-garundy function g for each vertex in the graph.: G (x) = Mex {G (y) | Y is the successor of x }.

Let's take a look at the nature of SG functions. First, allTerminal positionThe corresponding vertex, that is, the vertex without an outbound edge,The SG value is 0.Because its successor set is an empty set. Then for a vertex x whose g (x) = 0,All its successor y satisfies g (y )! = 0. For a G (x )! = 0 vertex, mustExist 1G (y) = 0.

The above three statements indicate that,The Postion represented by vertex x is P-position when and only when g (x) = 0(With p-The three sentences defined by positioin/n-position are exactly the same.). We calculateSGValue, you can find a winning strategy for each situation. However, the usage of SG functions is far less simple. If we make directed graph games more complex, for example, a directed graph does not have only one piece, but has n pieces. You can choose one to move each time, how can we find a winning strategy?

Let's take another look at the significance of the SG value of the vertex. WhenG (x) = KIndicates that0 <= I <K, there is a successor y of X that satisfies g (y) = I. That is to say, when the SG value of a piece is K, we can change it to 0, to 1 ,...... , Into K-1,However, K cannot be kept unchanged. I don't know if you can think of the NIM game based on this. The rule of the NIM game is: each time you select a pile of K stones, you can change it to 0, to 1 ,...... , Into the K-1, but never keep K unchanged. This indicates that if the vertex where n pieces are located isThe SG value is considered as the corresponding number of stones in N heaps.So this Nim gameEach winning strategy of the play corresponds to the winning strategy of the original n pieces!

For N pawns, set the SG values of the corresponding vertex to (A1, A2 ,..., an), set up another situation (A1, A2 ,..., an) when a winning strategy for a nim game is to turn AI into K, then a winning strategy for the original gameMove the I-th piece to a vertex with a SG value of K.. This sounds a little amazing-how can I go back to the NIM game after a lap.

In fact, we only need to prove that the digraph game with multiple pawns is P-position.The SG function of the sub-location is 0 or different.This proves that it is almost identical to the Bouton's theorem in the previous section. You just need to change a few nouns as appropriate.

Just now, in order to make the problem look easier, I thought that N pieces were moving on a directed graph. However, if it is not on a directed graph, but on a directed graph, each piece can be moved by a piece (that is, a directed graph), which will not bring any changes to the conclusion.

So we can define sum of graph games: Set G1, G2 ,...... And GN are N directed graph games. The game G is defined as G1, G2 ,...... , GN sum, the movement rule of game G is: select a sub-game GI and move the Above pawn. SD-Grundy theorem is: G (G) = g (G1) ^ g (G2) ^... ^ g (GN ). That is to say,The sum of the game's SG function values is the exclusive or of the SG function values of all its sub-games.

Consider one sentence at the beginning of this article: AnyICG can be abstracted into a directed graph game.. Therefore, the concepts of "SG function" and "game sum" are not limited to directed graph games. We define the SG value for each position of each ICG, or the sum of n icg. So when we face a game that is composed of N game groupsYou need to find the SG value for each game in every situation, and you can regard all these SG values as Nim stone heaps, then follow the method of finding the winning strategy of Nim to find the winning strategy of the game!

Go back to the question at the beginning of this article. There are n piles of stones, each time you can get 1, 2 or 3 from 1st piles of stones, you can get an odd number from 2nd piles of stones, you can get any stone from 3rd piles or later ...... We can think of it as three sub-games, with 1st sub-games containing only one pile of stones. Each time we get one, two, three, it is easy to see that the SG value of X stones is X % 4. The 2nd sub-game also has only one pile of stones. Each time an odd number of stones can be obtained,After simple drawing, we can know that the SG value of X stones in this game is X % 2.. 3rd games with N-2 heap stones, is a nim game. For each situation of the original game, the SG value of the three sub-games is different or the SG value of the entire game is obtained, then you can determine whether there is a winning strategy and make a decision based on the SG value. In fact, three sub-games are more conservative, and n sub-games are simply considered. Among them, 1st and 2 sub-games are described above, and 3rd and later sub-games are all "1 pile of stones, each time a few pieces can be retrieved, it is called "any stone game". In this super simple game, the SG value of X stones is obviously X. In fact, isn't the NIM game of N heap stones itself the sum of N "any stone games?

So,

For us, the concept of SG functions and "game's sum" is not to let us combine and create strange games, but to try to divide the seemingly complex gamesSeveral sub-GamesFind out its SG function for each sub-game, which is much simpler than the original game, and then obtain the SG function of the original game after all the differences or exceptions, so that the original game can be solved.

(The above are all from the Internet for personal appreciation only)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.