公平组合游戏、SG定理和SG函数

Sprague-Grundy 理论:精简版定义、引理与定理

全域公理:所有博弈均建立在有限有向无环图(Finite DAG)上,即有限步内终止,无循环。


符号

符号 LaTeX 含义
\(G,H,A,B,X\) \(G,H,A,B,X\) 任意公平组合游戏状态
\(0\) \(0\) 零游戏(终止态,空集)
\(\varnothing\) \(\varnothing\) 空集,与 \(0\) 等价
\(*n\) \(*n\) 单堆尼姆游戏,大小为 \(n\)
\(g,h,x\) \(g,h,x\) 游戏 \(G\) 的选项(后继状态)
\(G \to H\) \(G \to H\) \(G\) 可一步到 \(H\)
\(\in,\notin\) \(\in,\notin\) 属于 / 不属于
\(\subseteq\) \(\subseteq\) 子集
\(\cup\) \(\cup\) 并集
\(\{\dots\}\) \(\{\dots\}\) 集合构造器
\(\mathbb{N}\) \(\mathbb{N}\) 非负整数集
\(\forall,\exists\) \(\forall,\exists\) 全称 / 存在量词
\(\iff,\implies\) \(\iff,\implies\) 当且仅当 / 推出
\(G+H\) \(G+H\) 析取和(组合游戏)
\(G\approx H\) \(G\approx H\) 游戏等价关系
\(G\in\mathcal P\) \(G\in\mathcal P\) 必败态(P-position)
\(G\in\mathcal N\) \(G\in\mathcal N\) 必胜态(N-position)
\(\text{mex}(S)\) \(\text{mex}(S)\) 最小排除值
\(\mathcal S(G)\) \(\mathcal S(G)\) SG 值
\(\oplus\) \(\oplus\) 按位异或(Nim-sum)
\(\square\) \(\square\) 证明结束
\(\blacksquare\) \(\blacksquare\) 全部证明完毕

定义

定义 1(游戏)

\[G = \{ G_1, G_2, \dots, G_k \} \]

递归定义,\(G_i\) 为一步可达的后继状态。

定义 2(零游戏)

\[0 = \varnothing = \{\} \]

定义 3(选项)

\(H \in G\)\(H\)\(G\) 的选项,记 \(G \to H\)

定义 4(公平组合游戏 ICG)

满足:双人、完全信息、无随机、正常规则(无法行动者负)、公平性(双方走法集合相同)。

定义 5(析取和)

\[G + H = \{ g + H \mid g \in G \} \cup \{ G + h \mid h \in H \} \]

定义 6(P-position 与 N-position)

\[G \in \mathcal P \iff \forall g \in G,\ g \in \mathcal N \]

\[G \in \mathcal N \iff \exists g \in G,\ g \in \mathcal P \]

基础:\(0 \in \mathcal P\)

定义 7(等价)

\[G_1 \approx G_2 \iff \forall X,\ \big( (G_1+X) \in \mathcal P \iff (G_2+X) \in \mathcal P \big) \]

定义 8(尼姆堆 \(*n\)

\[*n = \{ *0, *1, \dots, *(n-1) \},\quad *0 = 0 \]

定义 9(mex)

\[\text{mex}(S) = \min\{ k \in \mathbb N \mid k \notin S \} \]

定义 10(SG 函数)

\[\mathcal S(G) = \text{mex}\big( \{ \mathcal S(g) \mid g \in G \} \big) \]


引理与定理

引理 1:\(\mathcal S(*n) = n\)

证明:对 \(n\) 归纳。\(n=0\)\(\mathcal S(*0)=\text{mex}(\varnothing)=0\)。若 \(k<n\)\(\mathcal S(*k)=k\),则 \(\mathcal S(*n)=\text{mex}(\{0,\dots,n-1\})=n\)\(\square\)


引理 2(核心构造引理):\(G + *\mathcal S(G)\) 为 P

证明:对游戏 \(G\)结构深度(最长路径长度)\(d\) 进行强归纳。

定义命题 \(P(H):\ H + *\mathcal S(H) \in \mathcal P\)

  • 基础情况(\(d=0\):此时 \(G\) 无后继,所以 \(G = 0\)。由定义 10 得 \(\mathcal S(0) = \text{mex}(\varnothing) = 0\)。令 \(g = \mathcal S(G) = 0\),则 \(G + *g = 0 + *0 = 0\)。由定义 6 的基础情况,\(0 \in \mathcal P\)。故 \(P(G)\) 成立。

  • 归纳步骤:假设对于所有深度小于 \(d\) 的游戏 \(H\)\(P(H)\) 都已成立。现在考虑深度为 \(d\)\(G\)。令 \(g = \mathcal S(G)\),我们要证 \(P(G)\),即 \(G + *g \in \mathcal P\)。根据定义 6,只需证明 \(G + *g\) 的所有后继均为 N-position。

    • 情况一:玩家在 \(G\) 中走一步,到达 \(G'\)(即 \(G \to G'\))。
      \(a = \mathcal S(G')\)。由 SG 定义(mex 不可达性),\(a \neq g\)
      我们分两种子情况证明 \(G' + *g\) 是 N-position:

      • 子情况 1.1:\(a < g\)
        根据尼姆堆定义(定义 8),\(*g \to *a\),所以从 \(G' + *g\) 可以一步走到 \(G' + *a\)
        由于 \(G'\) 的深度小于 \(G\),由归纳假设 \(P(G')\) 成立,即 \(G' + *\mathcal S(G') = G' + *a \in \mathcal P\)
        因此 \(G' + *g\) 存在一步到 P-position,由定义 6 可知 \(G' + *g \in \mathcal N\)

      • 子情况 1.2:\(a > g\)
        因为 \(a = \mathcal S(G') = \text{mex}\{\mathcal S(u) \mid u \in G'\}\),且 \(g < a\),根据 mex 定义(全覆盖性),\(g\) 必然出现在 \(G'\) 的后继 SG 值集合中。
        因此存在 \(G' \to G''\) 使得 \(\mathcal S(G'') = g\)
        于是从 \(G' + *g\) 可以一步走到 \(G'' + *g\)
        由于 \(G''\) 的深度小于 \(G'\),进而小于 \(G\),由归纳假设 \(P(G'')\) 成立,即 \(G'' + *\mathcal S(G'') = G'' + *g \in \mathcal P\)
        因此 \(G' + *g\) 存在一步到 P-position,由定义 6 可知 \(G' + *g \in \mathcal N\)

    • 情况二:玩家在尼姆堆 \(*g\) 中走一步,到达 \(*k\)\(0 \le k < g\))。
      根据 mex 定义(全覆盖性),因为 \(g = \text{mex}\{\mathcal S(t) \mid t \in G\}\),且 \(k < g\),所以 \(k\) 必然出现在 \(G\) 的后继 SG 值集合中。
      因此存在 \(G \to G_k\) 使得 \(\mathcal S(G_k) = k\)
      \(G + *k\) 可以一步走到 \(G_k + *k\)
      由于 \(G_k\) 的深度小于 \(G\),由归纳假设 \(P(G_k)\) 成立,即 \(G_k + *\mathcal S(G_k) = G_k + *k \in \mathcal P\)
      因此 \(G + *k\) 存在一步到 P-position,由定义 6 可知 \(G + *k \in \mathcal N\)

综合\(G + *g\) 的所有后继均为 N-position,故由定义 6 可知 \(G + *g \in \mathcal P\)。即 \(P(G)\) 成立,归纳完成。\(\square\)


引理 2.5(镜像策略与吸收引理)

命题 (a)(镜像策略):对于任意游戏 \(G\)\(G + G \in \mathcal P\)

证明:后手采用“镜像策略”——无论先手在其中一个 \(G\) 中如何走,后手在另一个 \(G\) 中完全模仿同样的走法。这样始终保持两个 \(G\) 的状态完全相同,且后手总有回应,最终先手无路可走。故 \(G+G\) 为必败态。\(\square\)

命题 (b)(吸收引理):若 \(A \in \mathcal P\),则对于任意游戏 \(G\),都有 \(G \approx G + A\)

证明:需证对任意 \(X\)\(G+X\)\(G+A+X\) 同胜同负。

  • \(G+X\) 为必胜态,则先手可按其必胜策略移动。若对手在子游戏 \(A\) 中行动,由于 \(A\) 是必败态,后手总能将 \(A\) 恢复到必败状态(即在 \(A\) 中采取相应应对),其余时刻沿用 \(G+X\) 的策略。最终先手获胜。
  • \(G+X\) 为必败态,则无论先手在 \(G+X\) 还是在 \(A\) 中行动,后手都能分别应对:在 \(G+X\) 中执行该子游戏的必败策略,在 \(A\) 中恢复其必败性。因此先手无法获胜,\(G+A+X\) 也为必败。

故二者同为必胜或同为必败,由定义 7 得 \(G \approx G+A\)\(\square\)


引理 3(等价判定)

命题\(A \approx B\) 当且仅当 \(A+B \in \mathcal P\)

证明

  • 充分性(若 \(A+B \in \mathcal P\),则 \(A \approx B\)):
    由引理 2.5 (b)(吸收引理),取 \(G = A\)\(A_{\text{abs}} = A+B\)(因 \(A+B\in\mathcal P\)),得

    \[A \approx A + (A+B) = (A+A) + B. \]

    由引理 2.5 (a)(镜像策略),\(A+A \in \mathcal P\)。再用吸收引理(取 \(G = B\),吸收 \(A+A\)),得

    \[B \approx B + (A+A) = (A+A) + B. \]

    因此 \(A \approx (A+A)+B \approx B\),传递性得 \(A \approx B\)

  • 必要性(若 \(A \approx B\),则 \(A+B \in \mathcal P\)):
    \(A \approx B\),取环境 \(X = B\),根据定义 7 有

    \[A+B \in \mathcal P \iff B+B \in \mathcal P. \]

    由引理 2.5 (a),\(B+B \in \mathcal P\),故 \(A+B \in \mathcal P\)

综上,命题得证。\(\square\)


定理 4(SG 定理——等价性)

\[G \approx *\mathcal S(G) \]

证明:由引理 2,\(G+*\mathcal S(G) \in \mathcal P\)。在引理 3 中令 \(A=G\)\(B=*\mathcal S(G)\),即得 \(G \approx *\mathcal S(G)\)\(\square\)


引理 5(Nim 异或判定)

\[*a_1+\cdots+*a_n \in \mathcal P \iff a_1\oplus\cdots\oplus a_n = 0 \]

证明:设 \(X = a_1 \oplus \cdots \oplus a_n\)

  • \(X=0\):任取一步将某个 \(a_i\) 改为 \(a_i'\),其中 \(0 \le a_i' < a_i\)(由定义 8)。新的异或和 $ X' = X \oplus a_i \oplus a_i' = a_i \oplus a_i' \neq 0 $(因为 \(a_i \neq a_i'\))。所有后继均为异或非零的状态。根据本引理即将证明的另一个方向(异或非零为 N),这些后继均为 N。因此当前状态为 P。

  • \(X \neq 0\):取 \(X\) 的二进制最高位 \(k\),必然存在某个 \(a_j\) 其第 \(k\) 位为 1。令 \(a_j' = a_j \oplus X\),则 \(a_j' < a_j\)。由定义 8,从 \(*a_j\) 可合法走到 \(*a_j'\)。移动后新的异或和为 \(X \oplus a_j \oplus a_j' = 0\),即存在一步到达 P-position。因此当前状态为 N。

综合两方向,引理得证。\(\square\)


引理 5.5(等价关系在析取和下的相容性)

命题:若 \(A \approx A'\)\(B \approx B'\),则 \(A+B \approx A'+B'\)
证明:对任意游戏 \(X\),由 \(A \approx A'\),取环境为 \(B+X\),根据定义 7 有:

\[(A+B+X) \in \mathcal P \iff (A'+B+X) \in \mathcal P. \]

又由 \(B \approx B'\),取环境为 \(A'+X\),有:

\[(B+A'+X) \in \mathcal P \iff (B'+A'+X) \in \mathcal P. \]

利用析取和的交换律与结合律(由定义 5 保证),将上述两式传递,得:

\[(A+B+X) \in \mathcal P \iff (A'+B'+X) \in \mathcal P. \]

由于 \(X\) 的任意性,由定义 7 可知 \(A+B \approx A'+B'\)\(\square\)


定理 6(SG 定理——异或和)

\[\mathcal S(G_1 + G_2 + \cdots + G_n) = \mathcal S(G_1) \oplus \mathcal S(G_2) \oplus \cdots \oplus \mathcal S(G_n) \]

证明

\(a_i = \mathcal S(G_i)\),记 \(X = a_1 \oplus a_2 \oplus \cdots \oplus a_n\)

第一步:先证明纯 Nim 堆的组合 \(*a_1 + *a_2 + \cdots + *a_n\) 等价于单个 Nim 堆 \(*X\)

考虑组合游戏 \(*a_1 + *a_2 + \cdots + *a_n + *X\),其对应的 Nim 堆大小为 \((a_1, a_2, \dots, a_n, X)\)。由引理 5(Nim 异或判定),该组合的异或和为

\[a_1 \oplus a_2 \oplus \cdots \oplus a_n \oplus X = X \oplus X = 0, \]

因此 \(*a_1 + *a_2 + \cdots + *a_n + *X \in \mathcal P\)。由引理 3 得

\[*a_1 + *a_2 + \cdots + *a_n \approx *X. \]

第二步:由定理 4,每个 \(G_i \approx *a_i\)。反复应用引理 5.5(等价相容性),得

\[G_1 + G_2 + \cdots + G_n \approx *a_1 + *a_2 + \cdots + *a_n. \]

由第一步已证 \(*a_1 + *a_2 + \cdots + *a_n \approx *X\),结合等价关系的传递性,有

\[G_1 + G_2 + \cdots + G_n \approx *X. \]

由于等价关系保持 SG 值不变(由定理 4 可知 SG 值是等价类的唯一标签),且由引理 1 知 \(\mathcal S(*X)=X\),因此

\[\mathcal S(G_1 + G_2 + \cdots + G_n) = X = a_1 \oplus a_2 \oplus \cdots \oplus a_n. \]

代入 \(a_i = \mathcal S(G_i)\),得

\[\mathcal S(G_1 + G_2 + \cdots + G_n) = \mathcal S(G_1) \oplus \mathcal S(G_2) \oplus \cdots \oplus \mathcal S(G_n). \]

\(\square\)


系定理 7(最终胜负判定)

\[G\in\mathcal P \iff \mathcal S(G)=0 \]

证明:由定理 4,\(G \approx *\mathcal S(G)\)。若 \(\mathcal S(G)=0\),则 \(G \approx *0 = 0\),而 \(0 \in \mathcal P\),故 \(G \in \mathcal P\)。若 \(\mathcal S(G)=n \neq 0\),则 \(G \approx *n\)。由于 \(n>0\),由定义 8 得 \(0 \in *n\),即 \(*n\) 存在一步到 P-position,所以 \(*n \in \mathcal N\)。等价保持胜负性质,故 \(G \in \mathcal N\)。综上,\(G\in\mathcal P \iff \mathcal S(G)=0\)\(\square\)


逻辑依赖链(最终完善版)

  1. 定义 1–10(公理基础)
  2. 引理 1(\(\mathcal S(*n)=n\))← 独立归纳
  3. 引理 2(\(G+*g\in\mathcal P\))← 结构归纳法(含基础情况、明确的 \(P(H)\) 命题、\(g\) 使用前定义)
  4. 引理 2.5(镜像策略与吸收引理)← 策略复制与定义 7
  5. 引理 3(\(A\approx B \iff A+B\in\mathcal P\))← 引理 2.5 + 定义 7
  6. 定理 4(\(G\approx *\mathcal S(G)\))← 引理 2 + 引理 3
  7. 引理 5(Nim 异或判定)← 定义 8 + 异或性质
  8. 引理 5.5(等价关系与加法相容性)← 定义 7 + 定义 5
  9. 定理 6(异或和 SG 定理)← 定理 4 + 引理 5.5 + 引理 5
  10. 系定理 7(胜负判定)← 定理 4

\(\blacksquare\)

posted @ 2026-07-08 21:55  H_Fx  阅读(15)  评论(0)    收藏  举报