在上一个Part部分,我们介绍了Bash game、Nim game、Misere Nim game 这三个游戏的玩法、必胜策略,以及必胜策略的证明,并介绍了有关必胜态以及必败态的两条定理,接下来我们会以Part1为基础,深挖其中的理论。
文章目录
1、Grundy Numbers/Numbers and Mex的引入
G r u n d y N u m b e r s Grundy Numbers GrundyNumbers 是一种在组合游戏理论中用来分析游戏局势的数学概念。
它主要用于判断在一些特定游戏中,当前局面对先手玩家是有利的还是不利的。
具体地说,给定一个游戏状态或局面, G r u n d y Grundy Grundy数能表示这个局面的胜负情况。
定义如下:
1、如果一个局面是终止局面,其 G r u n d y Grundy Grundy数为 0 0 0。
2、对于非终止局面,其 G r u n d y Grundy Grundy数定义为所有可能的下一步局面的 G r u n d y Grundy Grundy数中最小未出现的非负整数。
设当前状态为 S S S,其进行一次合法操作后的可能状态集合为: { S 1 , S 2 , . . . S k } \lbrace S_1,S_2,...S_k\rbrace { S1,S2,...Sk}
则有: G r u n d y ( S ) = M e x ( { G r u n d y ( S 1 ) , G r u n d y ( S 2 ) , . . . , G r u n d y ( S k ) } ) Grundy(S)=Mex(\lbrace Grundy(S_1),Grundy(S_2),...,Grundy(S_k)\rbrace) Grundy(S)=Mex({ Grundy(S1),Grundy(S2),...,Grundy(Sk)})
定义Mex
集合中未出现的最小非负整数。
定义运算Mex(set)
求出集合中未出现的最小非负整数。
列表观察:
Mex(set) | 结果 |
---|---|
Mex( ∅ \emptyset ∅) | 0 |
Mex({1,2,3}) | 0 |
Mex({0,2,3,4}) | 1 |
Mex({0,1,2,3,4,…, w w w}) | w + 1 w+1 w+1 |
下面用几个简单的游戏来验证 G r u n d y Grundy Grundy数:
Game1
题目:
有一堆数量为 n n n的石子,两个人轮流操作,每次操作可以取走任意数量的石子(不能不取)。
取走最后一个石子的玩家获胜。
列表观察 0 ∼ 10 0\sim10 0∼10的Grundy Numbers:
G r u n d y ( 0 ) = M e x ( ∅ ) = 0 Grundy(0)=Mex(\empty)=0 Grundy(0)=Mex(∅)=0
G r u n d y ( 1 ) = M e x ( { G r u n d y ( 0 ) } ) = 1 Grundy(1)=Mex(\lbrace Grundy(0)\rbrace)=1 Grundy(1)=Mex({ Grundy(0)})=1
G r u n d y ( 2 ) = M e x ( { G r u n d y ( 0 ) , G r u n d y ( 1 ) } ) = 2 Grundy(2)=Mex(\lbrace Grundy(0),Grundy(1)\rbrace)=2 Grundy(2)=Mex({ Grundy(0),Grundy(1)})=2
. . . ... ...
G r u n d y ( n ) = M e x ( { G r u n d y ( n − 1 ) , . . . , G r u n d y ( 0 ) } ) = n Grundy(n)=Mex(\lbrace Grundy(n-1),...,Grundy(0)\rbrace)=n Grundy(n)=Mex({ Grundy(n−1),...,Grundy(0)})=n
N | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
---|---|---|---|---|---|---|---|---|---|---|
Grundy(N) | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
观察到,只有 n = 0 n=0 n=