On the algorithm--game

Source: Internet
Author: User

There are a lot of online game blogs and papers, but some don't have a detailed proof, just a conclusion. Today, the author brings together some common game theory templates to introduce the decision of some single games in game theory and the common Nim templates and proofs.

Note: The following games are based on the optimal strategy of both parties, if not stated, each person will take at least one stone at a time.

Example 1: Take one of the Stones game
There are two players: A and B. There are n stones.
Convention: The two take the stones in turn, each with 1, 2 or 3 capsules. A first take, take the last stone of the man wins.
Question: A is there a winning strategy?

Analysis: This is one of the Essential Olympiad in primary school, we can easily know, when n is 0,4,8,12 ... , a must lose, because no matter how much a, B as long as and a together take away 4 can, when n is not 0,4,8,12 ... , a only need to take N to a multiple of 4, so it becomes B first fetch, B must lose, so a will win.

After our analysis, we found that for this game, 0,4,8,12 ... These states are for the initiator of the losing state , while the other state is the winning state of the initiator, so we now introduce some of the game of the terms and concepts
1. Equal combination Game

    • Two-person game.
    • The two men took turns walking.
    • There is a set of States, and it is usually limited.
    • There is a termination status, and the game ends when the termination status is reached.
    • The game can end within a limited number of steps.
    • It is legal to specify which state transfers are valid.
    • All the rules are the same for two people.

So our example 1 refers to the game is an equal combination game, but our life common board games, such as chess, go, etc., are not equal to the combination of games, because the two can move different pieces, do not meet the last condition, and we follow the game, as well as other games in the game, Basically belong to the equal combination game

2, N State (Win state), p status (must be defeated state)
Like the analysis of Example 1, 0,4,8,12 ... The status is the P state for the initiator (must fail), the other is the N state of the initiator (winning state).

Then we define a transition between the two states:

    • All termination states are P-states
    • For any n state, there is at least one path that can be transferred to the P-state
    • For any P-state, it can only be transferred to the N state

Prove too simple, here no longer repeat, we just need to understand a little, everyone will choose the most strategy.

Of course, this is the last person to walk the game of winning, as for those who went to the final failure of the game, we finally made a simple explanation (Anti Nim).

Example 2: Take the second of the stone game
To extend the game of Example 1, we define a collection \ (s=\{{p_{1},p_{2},..., p_{k}}\} (k \in z^*) \), and a, B must be the number of stones in the collection when the game is taken, and the other conditions will not change.
So, does a still have a winning strategy?

There is no winning strategy, our key is to find which state is the P state, which state is n state, however, the subject does not have an example 1 so easy to judge, so we need to introduce a new thing--SG function, it is defined as follows:
\[f (v) =mex\{f (U) |u for the subsequent state of V \}\]
Where MEX (minimal excludant) is defined as an operation on an integer collection. Its arguments are any set of integers, and the function value is the minimum natural number that is not part of the collection.
\[mex (A) =min\{k|k \in \complement_{n}a\}\]
Then, the SG value of the terminating state is obviously 0, and the status of the SG value is 0 is the P state, the state of the SG value is not 0 is the N state.
It is clear that the SG value is 0, indicating that all its subsequent states are not 0, that is, it can only be transferred to a non-0 state, and the SG value is not a state of 0. Then the status of the SG value is 0 is the definition of the state, the SG value is not 0 of the state is the definition of the winning state, so we only need to use the set S to find the SG value of each state.

Example 3: Take a stone game three
There are n stones, A, b two people take the stone, the rule that they can only take the current total number of stones at a time \ (\lceil \dfrac{s}{2}\rceil\) a stone, ask a initiator whether there is a winning strategy

The problem is mainly to enhance the understanding of the SG function, we consider starting from 0
\ (SG (0) =0,SG (1) =1,SG (2) =0,SG (3) =MEX\{SG (3-1), SG (3-2) \}=2\)
\ (SG (4) =MEX\{SG (4-1), SG (4-2) \}=1...\)
We list them to find the rules:
0,1
0,2,1,3
0,4,2,5,1,6,3,7
0,8,4,9,2,10 ...
There seems to be a very strange rule: the sequence is incremented at intervals, the number of the previous line is spaced in the middle of the next line. Yes, this is the law of the SG function, the initiator will fail when and only if the SG value is 0.

Example 4: Take a stone game of four (NIM game)
There are n heap of stones, the number of stones are \ (x_{1},x_{2},..., x_{n}\), A, b two people can choose a heap of stones each time to take away any number of, ask a initiator whether there is a winning strategy.

This problem is equivalent to an extended version of Example 2, because there are a lot of stones, so we can get multiple SG values, and these SG values must be \ (x_{1},x_{2},..., x_{n}\), then how do we get the whole game of the SG value of these SG values?

The magic of the Nim game is that its SG value and the difference or the relationship, NIM game in the initiator will be defeated and only if \ (X_{1}\oplus x_{2}\oplus...\oplus x_{n}=0, (\oplus for XOR) \), then, Why is this set up?

First,\ (\oplus\) satisfies the following laws and properties

    • Exchange law:\ (x\oplus y=y\oplus x\)
    • Binding law:\ (X\oplus (y\oplus z) = (x\oplus y) \oplus z\)
    • Owning unit meta:\ (0\oplus x=x\)
    • The same two-number operation is 0:\ (x\oplus x=0\)
    • Elimination Law:\ (x\oplus y=x\oplus z\rightarrow y=z\)

When the SG value of the Nim game is 0 o'clock, we assume that we take some of the stones in \ (x_{k}\) and make it into a \ (x_{k} ' \), we assume \ (X_{1}\oplus x_{2}\oplus...\oplus X_{k}\oplus...\oplus x_{n}=0=x_{1}\oplus x_{2}\oplus...\oplus x_{k} ' \oplus...\oplus x_{n}\ ', according to the elimination law available,\ (x_{ K}=x_{k} ' \), which contradicts our conditions, so that after taking the stone, the SG must have changed;
So for a state with a SG value of not 0, we are bound to make the SG value 0 by one operation. We just need to find a column (binary) of the left 1 of the current SG, and arbitrarily find a heap of stones to make that column equally 1, taking a number of stones from the heap, making the SG ' value 0. This is obviously possible, because the column becomes 0, the number must be smaller, for the other columns only need to change 0 to 1, 1 becomes 0.

Therefore, we get, for the Nim game, the losing state when and only if \ (x_{1}\oplus x_{2}\oplus...\oplus x_{n}=0\), for other situations, the initiator will be able to make the current situation into a state of defeat.

Example 5: Take a pebble game of five (Wythoff ' s game)
There are two piles of stone, the number is \ (x_{1},x_{2}\), A, b take the stone, the rule is either to take a bunch of any number, or in two piles to take the same arbitrarily many, ask a initiator whether there is a winning strategy.

In this case it is quite complicated, and the ordinary SG function cannot solve the problem. We use \ ((A_{k},b_{k}), (A_{k} \le b_{k},k \in [0,n]) \) to represent the quantity of two piles of goods and call it the situation, if a face \ ((0,0) \), then A has been lost, This situation is what we call the singular situation. The first few strange situations are:\ ((0,0) , (3,5), (4,7), (6,10), (8,13), (9,15), (11,18), (12,20) \)

As can be seen,\ (a_{0}=b_{0}=0\),\ (a_{k}\) is not in the previous occurrence of the minimum natural number, and \ (b_{k}=a_{k}+k\), the singular situation has the following three properties:

    • 1. Any natural number is contained in one and only one singular situation.
    • 2. Any operation can transform a singular situation into a non-singular situation.
    • 3. The use of an appropriate approach could transform the non-singular situation into a singular situation.

Prove:

  • 1. Because \ (a_{k}\) is the minimum natural number that has not been seen before, there is \ (a_{k}>a_{k-1}\) , and \ (b_{k}=a_{k}+k>a_{k-1}+k-1=b_{ k-1}>a_{k-1}\) . So Nature 1, established.

  • 2. If only one component of the singular situation is changed ((A_{k},b_{k}) , then the other component cannot be in any other singular situation, so it must be a non-singular situation. If the two components of \ ((a_{k},b_{k}) \) are reduced at the same time, it is also a non-singular situation because of its difference and the impossibility of being the difference between other singular situations.

  • 3. Assume that the situation is \ ((A, b) \) , if \ (a=b\) , Then take the \ (a\) object from both piles, and it becomes a singular situation \ ((0,0) \) ; if \ (a=a_{k},b>b_{k}\) , then take \ (b–b_{k}\) object into a singular situation If \ (a=a_{k},b<b_{k}\) , remove \ (A_{k}–a_{b–ak} from both piles) \) objects into a singular situation \ ((a_{b–a_{k}},a_{b–a_{k}}+b–a_{k}); \) If \ (a>a_{k},b=a_{k}+k\) , take the extra quantity from the first heap \ (a–a_{k}\) , if \ (a<a_{k},b=a_{k}+k\) , in two cases: the first, \ (a= A_{j}, (j<k) \) , take \ (b–b_{j}\) from the second heap, and the second, \ (A=b_{j}, (j<k) \) , take \ (b–a_{j}\) from the second heap.

According to the nature of the above, two people if all use the correct operation, then face the non-singular situation, the first to win the winner;

And, by the nature of the above, we can find that\ (a_{n},b_{n}\) is much like the Beatty sequence . In fact,\ (a_{n},b_{n}\) is the Beatty series .

Below is a description of the following Beatty sequence and beatty theorem :
Take positive irrational number \ (\alpha,\beta\), make \ (\frac{1}{\alpha}+\frac{1}{\beta}=1\)
Constructs two series \ (a_{n},b_{n}\), their entries are \ (a_{n}=\lfloor{\alpha n}\rfloor,b_{n}=\lfloor{\beta n}\rfloor\)
Then the sequence is obviously a positive integer, and theBeatty theorem states that two sequences are strictly incremented, and that each positive integer appears only once in two series

Prove:

  • 1. monotonicity: Because \ (\frac{1}{\alpha}<1,\alpha>1\), so \ (\alpha n-1>\alpha (n-1) \), so \ (a_{n}-1 >a_{n-1}\), as well as\ (b_{n}\) .
  • 2. Completeness: We want to prove this proposition, only need to prove that for any one\ (k, (k \in z^*) \), less than or equal to\ (k\)The number in the sequence appears\ (k-1\)Times.
    Set series\ (a_{n}\)The former\ (p\)Item is less than or equal\ (k\)(Not including\ (p+1\)), and because each item is irrational before it can be taken to an integer value, then there is
    \ (\begin{cases}\alpha p<k+1\\\alpha (p+1) >k+1\end{cases}\)
    Combine two, get\ (p=\lfloor\frac{k+1}{\alpha}\rfloor\), which is less than or equal to\ (k\)The number in\ (a_{n}\)The number of occurrences in the same, we can get it in\ (b_{n}\)In the number of occurrences, then we have less than equals\ (k\)The number inBeatty SeriesThe total number of occurrences in\ (s=\lfloor\frac{k+1}{\alpha}\rfloor+\lfloor\frac{k+1}{\beta}\rfloor\)
    Notice that the numbers in the two rounding functions are irrational numbers, so we have strict inequalities.
    \ ((\frac{k+1}{\alpha}-1) + (\frac{k+1}{\beta}-1) <s<\frac{k+1}{\alpha}+\frac{k+1}{\beta}\)
    So there are\ (k-1<s<k+1\)So\ (s=k\), the certificate is completed.

We go back to the singular situation before, because the singular situation in the \ (a_{n},b_{n}\) sequence satisfies the Beatty series , then also satisfies its construction method, namely \ (A_{n}=\lfloor\alpha n\ Rfloor,b_{n}=\lfloor\beta n\rfloor\) and \ (\frac{1}{\alpha}+\frac{1}{\beta}=1\).
Because \ (a_{n}+n= (\alpha + 1) n=b_{n}\), so \ (\frac{1}{\alpha}+\frac{1}{\alpha +1}=1\), Solution \ (\alpha=\ frac{\sqrt{5}+1}{2}\)

So, we get the formula:\ (a_{k}=\lfloor{k*\frac{\sqrt{5}+1}{2}}\rfloor,b_{k}=a_{k}+k\)

Therefore, for any situation, the initiator will be defeated and only when the situation is a singular situation, we only need to use the general formula to determine whether it is a singular situation.

Example 5: Take the Stone game VI (Fibonacci Nim)
There are a number of stones of N, a, b take turns to fetch stones, meet:

    • The initiator cannot take all the stones for the first time;
    • The number of stones that can be taken each time is between 1 and twice times the number of stones the opponent has just taken (including 1 and twice times the number of stones the opponent has just taken).

Agreed to take the last stone man-made winner, asked whether a to win the strategy.

There is a big difference between this and the previous Wythoff ' s game and the stone-taking games, which is the dynamic of the game rules. In the previous rule, the strategy set for each pebble that can be taken is basically fixed, but this time there are rules: the number of stones each can take depends on the number of stones the opponent has just taken.

This game is called Fibonacci Nim, Affirmation and Fibonacci series : 1,2,3,5,8,13,21,34,55,89,... Have a close relationship. If you experiment, you can guess: the initiator wins when and only if n is not the Fibonacci number . In other words, a Fibonacci sequence is formed by a losing state.

Just like the Wythoff game requires the beatty theorem to help, it is necessary to use the Zeckendorf theorem (Ziekendorf theorem): Any positive integer can be expressed as a number of discontinuous the sum of the number of Fibonacci.

First we prove the Zeckendorf theorem (Ziekendorf theorem):
We use \ (fib_{n}\) to represent Fibnacci ( n\) of the series ,\ (M, (M \in z^*) \), easy to know when \ (m=1,2,3\) , the theorem is established, then we use the mathematical induction method: Assuming that the theorem for all the number of less than \ (m\) is set up, we just have to prove that the theorem on \ (m\) is established.

  • When \ (m\) is the number of \ (fib\) , the theorem is established
  • when \ (m\) is not \ (fib\) number, set \ (fib_{p_{1}}<m<fib_{p_{1}+1}\) .
    Set \ (M ' =m-fib_{p_{1}}<fib_{p_{1}+1}-fib_{p_{1}}=fib_{p_{1}-1}\) , which is \ (M ' <fib_{p-1}\)
    because \ (M ' <m\) , and because the inductive method assumes \ (M ' \) can be expressed as a discontinuous Fibnacci sequence , i.e. \ (M ' =fib_{p_ {2}} +fib_{p_{3}}+...+fib_{p_{t}}, (P_{2}>p_{3}>...>p_{t}) \) and not a sequential integer, and because \ ( M ' <fib_{p_{1}-1}\) , so \ (p_{2}<p_{1}-1\) , i.e. \ (p_{1},p_{2}\) is not a sequential integer.
    \ (M=m ' +fib_{p_{1}}=fib_{p_{1}}+fib_{p_{2}}+...+fib_{p_{t}}, (p_{1}>p_{2}> (... p_{t}) \) and not a sequential integer, so the theorem is set up

So the Zeckendorf theorem (Ziekendorf theorem) is set for all the \ (m, (M \in z^*) \)

Then let's look at the proof of the Fibnacci series :
The first three theorems are given, which are then proved to be used:
\ (fib_{n+1}<2*fib_{n}<fib_{n+2}\)
\ (fib_{n+2}<3*fib_{n}\)
\ (4*fib_{n}<3*fib_{n+1}, (4*fib_{n}<3* (fib_{n}+fib_{n-1}) \rightarrow fib_{n}<fib_{n+1}<3*fib_{n-1}) \ )

The same applies the mathematical induction method:

  • When \ (i=2\) , the initiator can only take 1, obviously will be defeated, the conclusion is established.
  • Assume that when\ (i \leqslant k\), the conclusion is established.
    Then when\ (i=k+1\)When\ (fib_{i}=fib_{k}+fib_{k-1}\)。
    Then we can think of this heap of stones as two piles, short\ (k\)Heap and\ (k-1\)Heap.
    (Must be seen as two piles, because if the first time the number of stones taken by the initiator is greater than or equal to\ (fib_{k-1}\), the hand can be taken out directly\ (fib_{k}\)Because\ (fib_{k}<2*fib_{k-1}\))
    For\ (k-1\)Heap, from the assumption that no matter how to take the first, the next can always take the last one. Let's analyze the number of stones that we took last.\ (x\)The situation.
    If the number of stones first taken by the initiator\ (y \geqslant \dfrac{fib_{k-1}}{3}\), the number of stones left in this small heap is less than\ (2y\), that is, the hand can be taken directly, at this time\ (x=fib_{k-1}-y\), you\ (x \leqslant \dfrac{2*fib_{k-1}}{3}\)。
    Let's compare it.\ (\dfrac{2*fib_{k-1}}{3}\)And\ (\dfrac{fib_{k}}{2}\)The size. That\ (4*fib_{k-1}\)And\ (3*fib_{k}\)Size, we have come to the latter large.
    So we get,\ (x<\dfrac{fib_{k}}{2}\)。
    That is the end of the\ (k-1\)After the heap, the initiator can not be taken out\ (k\)Heap, so the rules of the game do not change, then by the hypothesis, for\ (k\)Heap, the next can still take the last one, so the win.
    That\ (i=k+1\), the conclusion is still established.

For not Fibonacci series , first decomposition.
When decomposing, take as large a number of Fibonacci as possible .
such as decomposition 85:
85 between 55 and 89, so can be written 85=55+30, and then continue to decompose 30,30 between 21 and 34, so can be written 30=21+9, and so on, finally decomposed into 85=55+21+8+1.

Then we can write \ ( n\) as \ (N=fib_{p_{1}}+fib_{p_{2}}+......+fib_{p_{k}, (P_{1}>p_{2}>......>p_{k}) \)
We make the initiator first take out \ (fib_{p_{k}}\), that is, the smallest of the heap. \ ( p_{k-1}>p_{k}+1\), there is \ (fib_{p_{k-1}}>2*fib_{p_{k}}\)because the fib\ is not contiguous. That is, you can only take the heap (fib_{p_{k-1}}\) , and can not be taken out at once.

At this time, the equivalent of the next to face this sub-game (only \ (fib_{p_{k-1}}\) This heap of stones, and the first fetch), that the initiator will be able to take this heap of the last stone.

In the same vein, for each subsequent heap, the initiator can take this heap of the last stone, so as to win the game.

Example 7: Take a stone game of seven (staircase Nim)
There are n heap of stones, the number of stones per heap is \ (x_{1},x_{2},..., x_{n}\), A, b in turn operation, each time you can choose the K heap of any number of stones placed in the K-1 heap, the 1th heap of stones can be placed in the No. 0 heap, the last can not operate the man to lose. Ask a if there is a winning strategy.

This is a staircase nim, which can actually be transformed into our familiar Nim game, the initiator will be defeated and only if the number of stones on the odd ladder is different or 0, then why is this?

If we were the initiator, we would follow this method to move the extra stones from the odd pile to the even heap. After that, if the opponent moves an odd pile, we move the odd heap so that the SG value changes to 0, and if the opponent moves an even heap, we move the stone to the odd heap and continue to move down. This way, we can always keep the odd pile in a winning state after several operations, and finally we will be able to move the stone from the odd pile to the even heap after the opponent, and finally move to the No. 0 heap so that the opponent cannot move.

So through the entire process we can find that even the stones in the heap will not affect the entire game results, only the odd heap of stones will affect the game results.

So for this game, the initiator will fail and only if the number of stones in the odd heap is different or 0.

Example 8: Take the Stone game Eight (Anti Nim)
In the case of Example 4 (Nim game) in a disguised version, the other conditions are unchanged, but the definition: take the last stone to the man to lose. So is there a winning strategy for a initiator?

This is very similar to the Nim game, that is, winning and losing the conditions are different, but the game's victory state and Nim have some differences, the game's victory when and only if:

    • All heap stones are 1 and the SG value is 0
    • At least one heap of stones is greater than 1 and the SG value is not 0

We analyze this game and divide it into two situations:

    • The number of stones in all heaps is 1.
    • At least one heap of stones is more than 1.

For the first case, we can easily get when the heap number is odd, the initiator will be defeated, otherwise the initiator win.

In the second case, we discuss the following in two different situations:

    • When the SG value is not 0 o'clock:
      If there are more than two stones more than 1 o'clock, we will change the SG value to 0, if only a heap of stones more than 1 o'clock, we can always let the state into an odd number of 1. So when SG is not 0 o'clock, the initiator win.
    • When the SG value is 0 o'clock:
      In this case, there will be at least two piles of stones more than 1, then the decision after the initiator will make the situation of the SG value is not 0, so that the initiator will win. So when SG is 0 o'clock, the initiator will fail.

However, the above-mentioned deduction is only for Anti Nim, and Anti sg-combination game This inference is not tenable, so Anti sg-combination game inference we need to re-prove. However, this blog mainly discusses the single game decision-making problem, so for sg-combo game not to discuss, interested readers can refer to Jia Zhihao "combinatorial game--a brief discussion on the development and deformation of SG game"

On the algorithm--game

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.