(Shallow) Game Theory Study Notes

 

Two weeks ago to learn nim and sg function, however, and they have forgotten the QAQ

 

 A, nim games

0, the definition of nim games are: two, there are a number of heap of stones, the number of each pile of stones is limited (a1, a2, ..., an), when a legal move: Choose a pile of stones and took several pieces (can-take-all, can not fail to take). If you turn someone is no longer advisable son, was defeated, another person wins.

 

1, the upper hand for the P-position disposed losing (losing the current state is state) / FLAC guaranteed win;

2, the upper hand can be provided to ensure the N-position winning (win the current state is state);

3, the game can not be provided to any mobile situation (terminal position) for the P-position;

4, may be moved to the P-position situation is N-position (properties);

5, were all mobile situation leads N-position is P-position (properties);

 

6, the conclusions of nim: nim for a game situation (a1, a2, ..., an ), which is the P-position if and only if a1 ^ a2 ^ ... ^ an == 0 ( i.e., A1 ! ^ a2 ^ ... ^ an = 0 to N-position);

 

7, determine the correctness of 6:

  (1), for the terminal position, a1 = a2 = ... = an = 0, there is a1 ^ a2 ^ ... ^ an = 0, and for the terminal potion is defined as the P-position, is established.

  (2), hypothesis 6 established , need to meet certain N-position can be moved to the P-position (point 4),

      N-position of a1 ^ a2 ^ ... ^ an! = 0, set a1 ^ a2 ^ ... ^ an! = K (k! = 0), then there exists a ai, its binary representation of the highest k is 1 bit and the most significant bit hexadecimal 1, at this time, the current AI (by taking stones) values, is converted into ai` = ai ^ k, there are: a1 ^ a2 ^ ... ^ an ^ k = k ^ k = 0, under the assumption of 6 properties meet established.

  (3), H6 established , need not necessarily meet the P-position so that the next state is a P-position (point 5),

      P-position is a1 ^ a2 ^ ... ^ ai ^ ... ^ an == 0, then, obviously a1 ^ a2 ^ ... ^ ai` ^ ... ^ an! = 0 (ai` <ai ).

  So clearly the correctness of 6.

 

8. Further, assume that the game has nim: only take a maximum of k, limit, then: the number of stones per stack mod (k + 1) ;.

 

9, SG function : Sprague-Grundy function: See this blog

  First define MEX (outliers minimum ordinal) calculating, for a set S, MEX (S), for a minimum number of elements in the sequence S is not a (non-negative). Such as: mex {0,1,2,4} = 3, mex {2,3,5} = 0, mex {} = 0.

  Given a directed acyclic graph and a pawn on the starting vertex, the two players alternately While this piece has moved along the edge can not be moved by forfeit.

 

  There for a given directed acyclic graph, Sprague-Garundy function g is defined for each vertex in the graph is: g (x) = mex { g (y) | y x is the successor }.

  And is defined: (1) the leaf node (terminal potsition) SG value of 0.

   Then: (2) for a g (x) == x 0 of the apex, it satisfies all subsequent y g (y) = 0!.

      (3) for a g (x)! = X 0 of the vertex, it must satisfy a subsequent y g (y) == 0.

  Then, by the above three points, known, position x represented by the vertices of P-position if and only if g (x) == 0 (i.e., g (x)! = 0 to N-position)

 

  See blog = =

 

  When faced with a combination of n game as a game, only to find a method which SG value for each position of each game, the SG value can be seen all the stones nim stack must then by nim win win situation policy decisions.

  The function determination mex SG value, specific methods play table orDFS.

 

10, the original link: https: //blog.csdn.net/strangedbly/article/details/51137432

  Problem-solving model :

  (1) the original game into a plurality of independent sub-game, SG function value of the original game SG XOR function values ​​of all its sub-game. I.e. sg (G) = sg (G1) ^ sg (G2) ^ ... ^ sg (Gn).

  (2) a sub-game not considered separately calculate the SG value.

   SG values ​​calculated :( focus)

   1, optional step number consecutive integers 1 ~ m, and can be directly modulo, SG (x) = x% (m + 1);

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

   3, optional number of steps as a series of discrete numbers, calculated using a template.

        Template 1: playing table

// F []: the number of stones can be removed
 // SG []: 0 ~ SG function of the value of n
 // the hash []: MEX {} 
int F [N], SG [N], the hash [N] ;     
 void getSG ( int n-) 
{ 
    int I, J; 
    Memset (SG, 0 , the sizeof (SG));
     for (I = . 1 ; I <= n-; I ++ ) 
    { 
        Memset (the hash, 0 , the sizeof (the hash)) ;
         for (J = . 1 ; F [J] <= I; J ++ ) 
            the hash [SG [I -f [J]]] = . 1 ;
         for (J = 0 ; J <= n-; J ++)    // find the smallest non-negative integer mes {} do not appear 
        {
             IF (the hash [J] == 0 ) 
            { 
                SG [I] = J;
                 BREAK ; 
            } 
        } 
    } 
}

  Template 2: DFS

// Note array Yaoan S SG function of small to large to be initialized to -1 for each set only 1 pass initialization
 // n-s is a set size S [i] is an array of special rules defined emulated 
int s [ 110 ], SG [ 10010 ], n-;
 int SG_dfs ( int X) 
{ 
    int I;
     IF (SG [X] = -! . 1 )
         return SG [X];
     BOOL VIS [ 110 ]; 
    Memset (VIS, 0 , the sizeof (VIS));
     for (I = 0 ; I <n-; I ++ ) 
    { 
        IF (X> = S [I]) 
        { 
            SG_dfs (X -s[i]);
            vis[sg[x-s[i]]]=1;
        }
    }
    int e;
    for(i=0;;i++)
        if(!vis[i])
        {
            e=i;
            break;
        }
    return sg[x]=e;
}

 

Second, Weizuo Fu Game

 

0, games: two piles each of a plurality of articles, two turns taken from a stack wherein the at least one article, not up, or from the same piles of items simultaneously, by taking a predetermined final finish victory.

1, the direct conclusion:

  Suppose piles of stones (X, Y) ( X , Y ) (where X <Y X < Y)

  So losing the upper hand, if and only if:

  (y-x)*(√5+1)/2==x

  Where \ √5 + 1/2 is actually 1.618 , the golden number of divisions.

 

Guess you like

Origin www.cnblogs.com/kkkek/p/11619165.html
Recommended