On the algorithm--game theory

Source: Internet
Author: User

Reprinted from Https://www.cnblogs.com/Wolfycz/p/8430991.html

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 There is no 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 state , while the other state is the winning state of the initiator, therefore, we now introduce some of the game of the terms and concepts 1, the equal combination game two games. 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 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 two states: all terminating states are P-states for any n state, and at least one path exists that can be transferred to P-State for any P-state and can only be transferred to N states

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={p1,p2,..., pk} (k∈z∗)s={p1,p2,...,pk}(k ∈ Z ∗) s=\{{p_{1},p_{2},..., p_{k}}\} (k \in z^*), A, B must be the number of stones in the collection when the game is taken, and the other conditions will not change.
So, a is there 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 is the successor State of V} f (v) = m E x {f (U) | U is the successor State of V} f (v) =mex\{f (U) |u is the successor 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∈∁na} m e x (a) = M i n {k | k∈∁n A} 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.

Similar code see Pku2960 S-nim Example 3: Take the stone game three

There are n stones, A, b two people take the stone, rule that they can only take the current total number of stones at a time ⌈s2⌉⌈s 2⌉\lceil \dfrac{s}{2}\rceil a stone, ask a to win 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)

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.