[Reprint] Summary of Game Theory

Reprinted from: https://blog.csdn.net/riba2534/article/details/78483578

Tribute to the big guy

What is Game Theory

      That is, if there are multiple people playing the game, assuming that they are all smart enough (the ability is equivalent to a computer), after they have made no mistakes and adopted the optimal strategy, one person must win. Knowing the initial state and rules, Theories and methods for solving a class of problems in the initial state of final victory (that is, who wins).

Theoretical foreshadowing

1. Define P-position and N-position: where P stands for Previous, and N stands for Next. Intuitively, the last time the mover had a winning strategy was P-position, that is, "the first mover will lose" (a strange situation). It is "first mover guarantees victory" (non-exotic situation).

(1). The situation where no movement can be made (that is, the terminal position) is the P-position;

(2). The situation that can be moved to P-position is N-position;

(3). A situation in which all moves result in an N-position is a P-position.

2. The P/N state has the following properties:

(1) If the person facing the final state is the winner, the final state is the winning state, otherwise the final state is the sure-defeat state.
(2) A necessary and sufficient condition for a situation to be a winning state is that the situation will become an inevitable losing state after a certain decision is made.
(3) A necessary and sufficient condition for a situation to be a losing state is that the situation will become a winning state no matter what decision is made.

Fair Combination Game (ICG)

1. Definition:

(1) Only two people participate.

(2) The state set of the game situation is limited.

(3) For the same situation, the operable sets of the two players are exactly the same

(4) Players take turns playing the game.

(5) The game ends when the operation cannot be performed, and the player who cannot perform the operation at this time loses.

(6) No matter how the game is played, it can always end within a limited number of moves.

2. Model: Given a directed acyclic graph and a chess piece on a starting vertex, two players alternately move the chess piece along the directed edge, and the one who cannot move is judged to lose. This game can be thought of as an abstract model for all fair combination games. In fact, any ICG can be abstracted into this "directed graph game" by treating each situation as a vertex and connecting a directed edge to each situation and its sub-situations.

3. Solutions:

Now, suppose we are given two games G1 and G2 or even multiple games. If we only know the P-states and N-states of a single game can we play games and G1+G2 correctly? the answer is negative. It is not difficult to see that the sum of two P-states is always a P-state, and the sum of a P-state and an N-state is always an N-state. But the sum of two N-states can be either a P-state or an N-state. Therefore, it is not enough to know the P-state and N-state of a single game.

In order to know whether the superposition of several states is an N or P state, we need to first understand the Sprague-Grudy function.

4, Sprague-Grudy theorem:

Let N = {0, 1, 2, 3, ...} be the set of natural numbers. The Sprague-Grundy function assigns a natural number to each state in the game. The Grundy value of a node v is equal to the smallest natural number that does not appear in the Grundy value of v's successor.

Formally: Given a finite subset S ⊂ N, let mex S be the smallest natural number that does not appear in S. Defines the mex (minimal excludant) operation, which is an operation applied to a set that represents the smallest non-negative integer that does not belong to the set. For example mex{0,1,2,4}=3, mex{2,3,5}=0, mex{}=0.

For a given directed acyclic graph, define the Sprague-Garundy function g about each vertex of the graph as follows: g(x)=mex{ g(y) | y is the successor of x }.

5. Sprague-Grudy function properties:

(1) For the vertices corresponding to all terminal points, the SG value is 0, because its successor set is an empty set - all terminal points are inevitable points (P points).

(2) For a vertex x with SG(x)=0, all its successors y satisfy g(y)!=0 - no matter what the operation, from the must-defeat point (P point) can only enter the must-win point (N points)//The opponent can leave N to us when he finishes walking.

(3) For a vertex with SG(x)!=0, there must be a successor point y that satisfies g(y)=0 - from any must-win point (N point) operation, there is at least one way to enter the must-defeat point (Point P) //That's the way we're going.

Nimm Game

 1.nim simple case:

    There are 3 piles of several items, and two people take turns to take as many items from a certain pile, and it is stipulated that at least one item is taken at a time.

    This is the simplest case of the nim game. We use (a, b, c) to represent a certain situation. First of all, (0, 0, 0) is obviously a singular situation. No matter who faces the singular situation, it will inevitably fail. The second singular situation is (0, n, n), as long as the opponent takes as many items, it will eventually lead to (0, 0, 0). After careful analysis, (1, 2, 3) is also a strange situation. No matter how the opponent takes it, it can become a situation of (0, n, n).

    So how can we judge whether a situation is a strange situation? The answer is OR. This is also one of the principles of the fair combination game. Since it is the basis of the Nimes game, it is included in this section.

2. Or the processing and principle of Nim game by OR operation:

  For the P/N state, there are the following three definitions: (that is, the three definitions laid out by the previous theory)

 (1). The situation where no movement can be made (that is, the terminal position) is the P-position;

 (2). The situation that can be moved to P-position is N-position;

 (3). A situation in which all moves result in an N-position is a P-position.

 Assuming that the number of stones in each pile is a1, a2, a3...an, first the P state corresponds to a1^a2^a3...^an=0, and the N state corresponds to a1^a2^a3...^an! =0;

  For (1), the inoperable situation corresponds to the case where ai is all 0, or is 0, which is proved.

  For (2), for any a1^a2^a3...^an! In the case of =0, change the largest number ai into a1^a2^a3...^a(i-1)^a(i+1)^an, according to or reflexivity (ie a^a= 0) It is known that this transformation should be done! =0 N state transforms to =0 P state;

  For (3), it can be proved that (3) can also be proved by proving that the P state must not be the P state after the transition. For the P state of a1^a2^a3^...^ai^...^an=0, take a bunch of ai, that is, subtract a number to become ai`, and still be in the P state, that is, a1^a2^a3 ^...^ai^...^an=0=a1^a2^a3^...^ai^...^an, since the operation satisfies the cutting rate, the final result is ai`=ai, so the P state It is impossible to pass through any transition to make it still in the P state, (3) holds.

  Therefore, in the simple nim game, the number of 3 piles of stones is repeated once, and whether it is zero can be determined to determine whether it is a must-win state.

  Generalized to n heaps, the principle is similar.

ICG, NIM game and SG function synthesis

  For the problem of taking stones that can be turned into n piles, if the number of stones to be taken is limited (the number of stones that can be obtained is given n), so first find the SG value of each pile (that is, the state corresponding to a single game) , and then proceed to or, the obtained answer is judged whether it is a sure-win or a sure-defeat state according to whether it is 0.

  For the problem that will become multi-state after one fetch, since one person must win according to the optimal strategy, the results obtained from each state after the fetch are consistent, and all the states after the fetch only need to be repeated once. The answer obtained is to take the previous state, which can be calculated recursively.

Bash Game

1. QUESTION 

    There are only a pile of n items, and two people take turns to take items from the pile, and it is stipulated that at least one item is taken at a time, and at most m items are taken. The one who takes the light in the end wins.

2. Analysis:

    In the game, take a pile for two people, and simply expand to take n piles. Since the number of objects to be taken is limited, it happens to be the first situation in the synthesis.

    When looking for the SG value, you can always find that the SG value is the result of %(m+1), so you can give each pile of %(m+1) or once again without proof. The answer is the following. The principle of greedy algorithm:
    Obviously, if n=m+1, then only m items can be taken at most at a time, so no matter how many items are taken by the first taker, the second taker can take the remaining items at one time, and the latter wins. So we found the rule of how to win: if n=(m+1)r+s, (r is any natural number, s≤m), then the first taker will take s items, if the second taker takes k ( ≤m), then the first taker then takes m+1-k, resulting in (m+1)(r-1) remaining. If this method is maintained in the future, then the first taker will definitely win. In short, to keep the multiple of (m+1) left for the opponent, you can finally win.

That is, if n=k*(m+1), the last one wins, otherwise, the first one wins. n%(m+1)==0. The first taker will lose.

    Multiple heaps are similar.


Wythoff Game

1.QUESTION

    There are two piles of several items each, and two people take turns to take the same number of items from a certain pile or from both piles at the same time. It is stipulated that at least one item is taken at a time, and there is no limit to the number of items. The last one who takes all of them wins.

2. Analysis

    This case is quite complicated. We use (ak, bk) (ak ≤ bk , k=0, 1, 2, ..., n) to denote the number of two piles of items and call it a situation, if A faces (0, 0), then A Already lost, we call this situation a bizarre situation. The first few strange situations are: (0, 0), (1, 2), (3, 5), (4, 7), (6, 10), (8, 13), (9, 15), ( 11, 18), (12, 20).
    It can be seen that a0=b0=0, ak is the smallest natural number that has not appeared before, and bk=ak + k, the singular situation has the
following three properties:
    1. Any natural number is contained in one and only one singular situation.
    Since ak is the smallest natural number that has not appeared before, there is ak > ak-1 , and bk = ak + k > ak-1 + k-1 = bk-1 > ak-1 . So property 1. established.
    2. Any action can turn a singular situation into a non-exotic situation.
    In fact, if only one component of the singular situation (ak, bk) is changed, then the other component cannot be in other singular situations, so it must be a non-singular situation. If the two components of (ak, bk) are reduced at the same time, since their difference is unchanged and cannot be the difference of other singular situations, it is also a non-singular situation.
    3. With proper methods, a non-singular situation can be turned into a singular situation.

    Assuming that the situation facing is (a, b), if b = a, then taking a objects from the two piles at the same time, it becomes a singular situation (0, 0); if a = ak, b > bk, then , take b - bk objects, that is, become a singular situation; if a = ak , b < bk , then take ak - ab - ak objects from the two piles at the same time, and become a singular situation ( ab - ak , ab - ak + b - ak); if a > ak , b = ak + k, just take the extra amount a - ak from the first pile; if a < ak , b = ak + k, there are two cases , the first type, a=aj (j < k), take b - bj from the second pile; the second type, a=bj (j < k), take b - aj from the second pile That's it.

    It can be seen from the above properties that if both people operate correctly, then in the face of a non-singular situation, the one who takes the first will win; otherwise, the one who takes the second will win.

    Then given a situation (a, b), how to judge whether it is a strange situation? We have the following formula:
    ak =[k(1+√5)/2], bk= ak + k (k=0, 1, 2, ..., n square brackets indicate the rounding function)
The strange thing is that there is The golden ratio (1+√5)/2 = 1. 618..., therefore, the rectangle composed of ak, bk is approximately the golden rectangle, since 2/(1+√5)=(√5-1) /2, you can first find j=[a(√5-1)/2], if a=[j(1+√5)/2], then a = aj, bj = aj + j, if not equal to , then a = aj+1, bj+1 = aj+1+ j + 1, if they are not, then it is not a singular situation. Then follow the above rules, and you will encounter a strange situation.
3. Principle:

  For each pair of numbers corresponding to the inevitable losing situation, sort them according to the first number from small to large. It can be seen that if ai in (ai,bi) forms a sequence, and bi forms a sequence, these two sequences just satisfy Beatty For the definition of the sequence, the general term of each term can be solved by applying Beatty's theorem, and the answer is the above formula for judging singular situations.

【Supplement】EP6: Wythoff's Game

Copyright statement : When reprinting, please indicate the original source and author information of the article and this statement in the form of a hyperlink
http://yjq24.blogbus.com/logs/42826226.html

Roughly like this: there are two piles of stones, you might as well think that one pile has 10, and the other pile has 15. The two sides take turns to take some stones. There are two legal ways to take them:

1) Take any number of stones from a pile of stones;

2) Take the same number of random stones from the two piles of stones;

It is agreed that the person who takes the last stone is the winner, and seeks a sure-beating attitude (win-win strategy).

 

This can be said to be the entire contribution of MR. Wythoff (Wythoff proposed this game in 1907). This question seems to be used as the subject of programming competition. There are many labels on the Internet as POJ1067, but if people who learn programming don't know the Beatty theorem and Beatty sequence  , all they can do is to find the rules. Unfamiliar people can play a few games here first~

Simple analysis, it is easy to know that the status of the two piles of stones is the same, we use the remaining stones (a, b) to represent the status, and draw it on the plane rectangular coordinate system.

Use the method described in the previous theorem:  A loop-free directed graph with a finite number of nodes has a unique kernel   to find the must-fail state. Mark (0,0) first, then cross out all the grid points of (0,k), (k,0), (k,k); then find the uncrossed grid points above y=x, mark (1,2), then cross out (1,k), (k,2), (1+k,2+k), at the same time mark the symmetry point (2,1), cross out (2,k), (1,k),(2+k,1+k); then find (3,5) above y=x in the points that have not been crossed out. . . In this way, if only the must-fail states of a<=b are listed, the first ones are (0,0),(1,2),(3,5),(4,7),( 6,10),…

 

 

 

The next step is to find the regular process, ignore (0,0), record the nth group must fail state as (a[n],b[n])

Proposition 1: a[n+1]=the smallest positive integer that has not appeared in the first n groups of must-fail states

[Analysis]: If a[n+1] is not the smallest of the numbers that do not appear, then we can go from the state of a[n+1] to a state that makes a[n+1] smaller, and our search method conflict.

Proposition 2: b[n]=a[n]+n

[Analysis]: Induction: If the first k must-fail states are respectively  , the following proof: the k+1 must-fail state is

Starting from the k+1 must-fail state, there are three possible states, taking some from the left pile, some from the right pile, or some from the two piles. The following shows that these three categories are all winning states.

Situation 1: From Proposition 1, any number smaller than a[k+1] has appeared in the previous must-fail state. Once the left heap is less, we only need to take that number into the corresponding must-fail state. That's it.

Case 2 (do not take too much from the right pile): This makes the difference between the two piles smaller, for example, if you get it  , you can get it again  ;

Case 2 (take a lot from the right pile): make the right pile less than the left pile, which is similar to case 1, such as taking  (where a[m];

Case 3: For example, if you get it  , you can get it again  .

To sum up, any  state that goes from departure can go back into the nucleus. So the original proposition is established.

The above two propositions are complete to determine (a[n], b[n]), given (0,0) and then according to these two propositions, you can write (1,2), (3,5 ),(4,7),…

In this way, we get the recursion formula of this sequence. Below we regard these two propositions as the definition of (a[n], b[n]).

First prove two properties:

Property 1: a[n], b[n] in the kernel traverse all positive integers.

[Analysis]: From propositions 1 and 2, it can be obtained that a[n], b[n] are increasing, and the definition of a[n] is obvious.

Property 2: A={a[n]:n=1,2,3,…},B={b[n]:n=1,2,3,…}, then the sets A and B do not intersect.

[Analysis]: By the kernel is the inner solid set, obviously.

Did you think of the Beatty sequence here? In fact, a[n] and b[n] are a Beatty sequence.

 , yes   , solve the equation 

Well   , at this point, we have found the general term formula for this must-fail state.

In fact, this group of Beatty sequences has some other properties. For example, when one number is a Fibonacci number, the other number is also a Fibonacci number; and the ratio of the two is getting closer and closer to the golden ratio. These properties are obtained in the general term formula It's not hard to prove later.

Overall, what does this question teach us? First find the kernel by the method described in the theorem, then give the law of the kernel (recursion, or general term) and prove it. Finally, a corresponding must-fail state map is attached.

 

 

 Supplement: Beatty's theorem proves Wizoff's theorem:

 A certain state is represented by an ordered number pair (that is, the number of two piles containing stones, the first number is not greater than the second number), obviously (0,0) is a must-fail state. The following proves that all must-fail states can be constructed according to the following method:

    1° (0,0) is a must-fail state;

    2° The difference between the two numbers in the kth must-fail state is k (remember (0,0) as the 0th must-fail state);

    3° If the first k must-fail states are known, the smallest positive integer that has not appeared is the first number of the k+1-th must-fail state.

    It is easy to make this matter clear by discussing the situation, and the following paragraphs prove that it can be skipped...

 

    Proof: According to the above construction method, there is an obvious fact that the first number of each state is smaller than the first number of the state following it, and the same is true for the second number [1] . If the first number of the latter state (denoted as A) is smaller than that of the former state, then the first number of the former state has already chosen A, and the latter state will definitely not turn, which contradicts 3°. The value of the second number minus the first number in the previous state is smaller than the latter (by 2°), so the second number in the former state is of course smaller than the latter.

    At the same time, it is also known that there will be no repeated positive integers [2] , because if there are repeated positive integers, the second number of the previous state must be equal to the first number of the following state (otherwise, from [1], it will be Strict inequality occurs). The first number of the latter state cannot be repeated with the former, which contradicts 3°.

 

    Now, consider the constructed nth state. When n=0, it is obviously a must-fail state. When n=0,1,2,...,k-1, the k states are already a must-fail state. The following proves that the kth state is also a must-fail state.

    Note this state as (A, A+k). It is impossible for the one who takes the first to change to the previous inevitable state, because if only one pile of stones is moved and then one of the previous must-lose states is changed, the two must-lose states have repeated positive integers, which is contradictory; if two piles of stones are moved, then The difference remains unchanged, and it is also impossible to become a certain defeat state in front of it.

    The following proves that no matter how the first taker takes the stone, the second taker can become a certain failure state in front, thus proving that (A, A+k) is also a certain failure state.

    (1) If the first taker moves the first pile of stones, this number must have appeared in the previous must-fail state (from 3°), and the number of the second pile of stones must be larger than the two in the previous must-fail state. The number must be large (from [1]), so the one who takes the last one must be able to take the second pile of stones and become the one who will lose the previous one.

    (2) If the first taker moves the second pile of stones:

         i. If the second pile is still not smaller than the first pile after taking it, the difference between the two piles of stones is reduced, which just matches the previous certain failure state, and the number of the first pile of stones must be larger than the previous certain failure state. The first number is larger (from [1]), and the last player can take two piles of stones at the same time to become the first one who must lose.

         ii. If it is less than the first pile, this number has appeared in the previous must-fail state (by 3°), if this number is the second number of the previous must-fail state, then the latter only needs to move the first pile. But; if it is unfortunate that this number is the first number in the previous state of failure, and the number of the first pile of stones is not greater than the second number in the previous state of failure, then the difference between the two piles of stones is It must be smaller than the previous must-fail state, which is consistent with the previous must-fail state. The latter can move two piles at the same time.

    (3) If the first taker moves two piles of stones at the same time, the number of the first pile of stones has appeared in the previous must-defeat state (from 3°), and the latter taker can move the second pile.

    This is the proof.

 

    According to the method of constructing the must-fail state just now, mark {a_n}, {b_n} as the sequence composed of the first number and the second number respectively (excluding the first pair (0,0)), n=1,2, 3, ... , first write the first few terms of the two sequences:

    {a_n}: 1,3,4,6,...

    {b_n}: 2,5,7,10,...

    According to the construction method just now, it is obvious that the two sequences are strictly increasing, and there are no repeated positive integers, and every positive integer will appear (from 3°, it is impossible to miss a positive integer), and b_n-a_n= n.

    Those familiar with Beatty's theorem will immediately see that the sequence constructed by Beatty's theorem exactly satisfies the first three!

 

    Let's first introduce Beatty's theorem.

    Take positive irrational numbers α, β such that

 

    Construct two sequence {a_n},{b_n}, their general terms are

 

    a_n is the largest integer less than or equal to αn, and that symbol is equivalent to the Gaussian function [ ].

    Sequences are obviously all sequences of positive integers, and Beatty's theorem states that both sequences are strictly increasing, and each positive integer appears in both sequences and only once.

    Strictly increasing is good proof, because 1/α<1,α>1, so the adjacent two items of {a_n} are subtracted by more than 1 before rounding, and the latter item is obviously larger than the former item after rounding. The same is true for {b_n}.

    For the latter proposition, we only need to prove that for any positive integer k, positive integers less than or equal to k appear exactly k times in the two sequences.

    Let the first p item of the sequence {a_n} be less than or equal to k (without p+1 item), and because each item is an irrational number before rounding, it is impossible to take an integer value, so there are

 

    Combining the two, there is an equation

 

    This is the number of times a positive integer less than or equal to k appears in the sequence {a_n}. The same is true for the sequence {b_n}. In this way, we get the total number of times that positive integers less than or equal to k appear in the two sequences

 

    Note that the numbers in the two round-down symbols are both irrational, so there is a strict inequality

 

    So there is

 

    This is the proof.

 

    Going back to the inevitable defeat state just now, the Beatty theorem is a very suitable theorem. Take any set of α and β that meet the requirements, and the constructed sequence satisfies most of the conditions. Only the last condition remains, that is, b_n-a_n= n, this only needs to take β-α=1.

    The values ​​of α and β are solved as follows:

 

    Therefore, we can directly write the formula for the nth must-fail state

 

    So far, the game of taking stones at the beginning has been solved perfectly, and the golden ratio has appeared in a seemingly unrelated problem.

Fibonacci game

1. Problem model:

 There is a pile of n stones, both players take turns taking stones, satisfying: 

(1) The first mover cannot take all the stones at the first time; 

(2) The number of stones that can be taken each time is between 1 and 2 times the number of stones the opponent just took (including 1 and 2 times the number of stones the opponent just took). The person who agreed to take the last stone was the winner.

2. Solutions:

  When n is the Fibonacci number, the first mover will lose. That is, there is a first mover's inevitable defeat state if and only if the number of stones is the Fibonacci number. 

    Proof: According to "Zeckendorf's theorem" (Zeckendorf's theorem): any positive integer can be expressed as the sum of several discontinuous Fibonacci numbers. For example, n=83 = 55+21+5+2, let's see what the guiding significance of this decomposition is: if the first hand takes 2, then the second hand cannot take 5 or more, and 5 is a Fibonacci number, then it must be Take the last one of the 5 stones first, and similarly, then take the last one of the next 21 stones first, and then take the last one of the last 55 stones, then the first player wins.

    Counter-evidence: If n is a Fibonacci number, such as n=89: remember the number of stones taken at the beginning of the first move as y

    (1) If y>=34 (that is, the first two items of 89), then the second hand must win, because 89-34=55=34+21<2*34.

    (2) When y<34, the number of remaining stones x is between 55 and 89. It must not be a Fibonacci number. Decompose x into a Fibonacci number: x=55+f[i]+…+f[j] , if f[j]<=2y, then B is the first mover facing the x position, so according to the previous analysis, the second mover only needs to take f[j] first, and then press the previous analysis to ensure that win.

 

 

 

6. Application:

(1) The optional number of steps is a continuous integer of 1-m, which can be directly taken modulo, SG(x) = x % (m+1); 

(2) The optional number of steps is any step, SG(x) = x; 

(3) The optional number of steps is a series of discontinuous numbers, use mex (calculate the value of each node) 

7. Practice: hdoj 1847 1536 3980

 

refer to:

http://blog.csdn.net/lgdblue/article/details/15809893

http://www.cnblogs.com/celia01/archive/2011/11/15/2250171.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325025856&siteId=291194637