5D Library › 双人相位耦合、双线性相容张量与时空网格博弈 · English

第六章 转动的网格上何时何方行事

把择时择向写成决策问题

第五章的置换描述了九宫如何转动,但没有说一个人应该怎样利用它。择时择向的问题可以写成一个标准的动态规划:状态是(所在宫位,时段),每个时段可以停留、走到相邻的宫,或者就地「行事」,得到该宫此刻的数值。时间有周期——八门转一圈回到原位——所以状态空间是一个空间网格与一个时间环的乘积,最优策略用逆向归纳求出 (Bellman 1957)。

推导

模型的输入是一个假设。 依照传统的读法,开、休、生三门记为 +1,杜、景两门记为 0,伤、死、惊三门记为 −1,中宫记为 0;每走一步或等一个时段代价 0.1,必须在八个时段之内行事。这些数值不是测量,而是输入:本章的每一个结论都以它们为前提。

第十二段程序比较三种情形:方向与时间都自由;只有方向自由(必须在第一步行事);只有时间自由(必须去某一个指定的外宫)。

推导

# Chapter 6. Where and when to act on a turning grid.
# The eight doors stand on the outer palaces in the ring order of p11:
#   Xiu Sheng Shang Du Jing Si Jing' Kai  (rest, life, harm, block, view,
#   death, fright, open), and turn one palace per time slot.
# By the conventional reading Kai, Xiu, Sheng are good (+1), Du and Jing
# ("view") are neutral (0), Shang, Si and Jing' ("fright") bad (-1); the
# centre counts 0. These values are an assumption fed into the model.
# A person starts in the centre at slot t0. Each slot they may stay or
# step to an orthogonal neighbour (cost 0.1 per slot), or act where they
# stand and collect that palace's current value; they must act within
# H = 8 slots. Backward induction over (cell, slot) gives the best plan,
# (a) when both direction and time are free, (b) when the direction is
# fixed (one given outer palace) and only the time is free, and (c) when
# the time is fixed (the first step) and only the direction is free.
import math

L = (4, 9, 2, 3, 5, 7, 8, 1, 6)
RING = [L.index(n) for n in (1, 8, 3, 4, 9, 2, 7, 6)]
DOOR_VALUE = [1, 1, -1, 0, 0, -1, -1, 1]   # Xiu .. Kai
H, COST, CENTRE = 8, 0.1, 4

def nbrs(c):
    r, k = divmod(c, 3)
    out = [c]
    for dr, dk in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        if 0 <= r + dr < 3 and 0 <= k + dk < 3:
            out.append((r + dr) * 3 + k + dk)
    return out

def value_at(cell, t):
    if cell == CENTRE:
        return 0.0
    return float(DOOR_VALUE[(RING.index(cell) - t) % 8])

def best(t0, allowed):
    v = {}
    for step in range(H, -1, -1):
        for c in range(9):
            act = value_at(c, t0 + step) if c in allowed else -9.0
            if step < H:
                act = max(act, max(v[(n, step + 1)] - COST
                                   for n in nbrs(c)))
            v[(c, step)] = act
    return v[(CENTRE, 0)]

if __name__ == "__main__":
    outer = [c for c in range(9) if c != CENTRE]
    free = [best(t, set(range(9))) for t in range(8)]
    fixed_dir = [best(t, {c}) for t in range(8) for c in outer]
    go_now = []
    for t in range(8):
        for c in outer:
            steps = 1 if c in nbrs(CENTRE) else 2
            go_now.append(value_at(c, t + steps) - COST * steps)
    fixed_time = [max(value_at(n, t + 1) for n in nbrs(CENTRE)
                      if n != CENTRE) - COST for t in range(8)]
    rows = (("(a) direction and time free:     ", free),
            ("(c) time fixed, direction free:  ", fixed_time),
            ("(b) direction fixed, time free:  ", fixed_dir),
            ("    same, but going at once:     ", go_now))
    for label, vals in rows:
        print("   {} mean value {:+.4f}, lowest {:+.3f}".format(
            label, math.fsum(vals) / len(vals), min(vals)))
    print("\nReading: the three good doors stand side by side, and the four")
    print("palaces next to the centre alternate around the ring, so a good")
    print("door is always one step from the centre: when the direction is")
    print("free, timing adds nothing. Timing matters only when the direction")
    print("is fixed; then waiting for a good door lifts the mean from below")
    print("zero to a clearly positive value. All of it rests on the values")
    print("put in.")
#    (a) direction and time free:      mean value +0.9000, lowest +0.900
#    (c) time fixed, direction free:   mean value +0.9000, lowest +0.900
#    (b) direction fixed, time free:   mean value +0.6625, lowest +0.300
#        same, but going at once:      mean value -0.1500, lowest -1.200
#
# Reading: the three good doors stand side by side, and the four
# palaces next to the centre alternate around the ring, so a good
# door is always one step from the centre: when the direction is
# free, timing adds nothing. Timing matters only when the direction
# is fixed; then waiting for a good door lifts the mean from below
# zero to a clearly positive value. All of it rests on the values
# put in.

结果中最重要的是前两行:方向与时间都自由时,均值为 0.900;只有方向自由、必须立即行事时,均值同样是 0.900,而且每个起始时段都一样。也就是说,只要方向可以选,择时不增加任何价值。

原因是一个组合事实。三个吉门在八门的环序中相邻(开、休、生);中宫的四个邻宫(坎、震、离、兑)在环上隔一个排一个。任何三个相邻的环位都至少包含一个隔位排列的位置,所以无论门转到哪里,中宫一步之内总有一个吉门。

只有当方向被固定——比如出行的目的地已经定了——时间才有意义。这时立即出发的均值是 −0.1500,最差的情形是 −1.200;而等待吉门转到那个方向再行事,均值是 +0.6625,最差也有 +0.300。择时的价值,完全来自方向不能选。

有对手时的网格博弈

第二种问题是对抗性的:A 选一个宫位行事,对手 B 选一个宫位封锁;被封锁时 A 得 0,否则得该宫的数值。为了让数值为正,把吉门、中平之门与凶门分别记为 3、2、1,中宫记为 2。这是一个「封锁一格」的二人零和博弈,有闭式解:B 只封锁数值最高的若干宫,A 在这些宫上以与数值成反比的概率混合,博弈的值为 V=(k−1)/∑i(1/vi)V = (k-1)\big/\sum_i (1/v_i),其中求和取遍这 kk 个宫 (Alpern and Gal 2003)。第十三段程序在八个时段上求解这个博弈,并用虚拟对策(fictitious play)独立地验证第一个时段 (Brown 1951; Robinson 1951)。

推导

# Chapter 6. A two-person game on the turning grid.
# A chooses a palace to act in; a rival B chooses a palace to block. If B
# blocks A's palace A gets 0, otherwise A gets the palace's current value
# v: good door 3, neutral 2, bad 1, centre 2 (positive values, assumed).
# For this "block one cell" game the solution is known in closed form:
# B blocks only the k best cells, A mixes over them with p_i proportional
# to 1 / v_i, and the value is V = (k - 1) / sum(1 / v_i) over those
# cells, with k the largest support for which every blocking probability
# q_i = 1 - V / v_i is non-negative. The program solves the game at all 8
# slots of the door cycle and checks slot 0 by fictitious play.
from fractions import Fraction

L = (4, 9, 2, 3, 5, 7, 8, 1, 6)
RING = [L.index(n) for n in (1, 8, 3, 4, 9, 2, 7, 6)]
DOOR = [3, 3, 1, 2, 2, 1, 1, 3]            # Xiu .. Kai, as in p12 + 2

def values(t):
    v = [2] * 9
    for i, c in enumerate(RING):
        v[c] = DOOR[(i - t) % 8]
    return v

def solve(v):
    order = sorted(range(9), key=lambda c: -v[c])
    best = None
    for k in range(2, 10):
        s = order[:k]
        val = Fraction(k - 1) / sum(Fraction(1, v[c]) for c in s)
        if all(v[c] >= val for c in s):
            best = (val, s)
    val, s = best
    z = sum(Fraction(1, v[c]) for c in s)
    p = {c: Fraction(1, v[c]) / z for c in s}
    return val, p

def fictitious(v, rounds=20000):
    ca, cb = [0] * 9, [0] * 9
    a = b = 0
    for _ in range(rounds):
        ca[a] += 1
        cb[b] += 1
        a = max(range(9), key=lambda i: v[i] * (sum(cb) - cb[i]))
        b = max(range(9), key=lambda j: ca[j] * v[j])
    na, nb = sum(ca), sum(cb)
    upper = max(v[i] * (1 - cb[i] / nb) for i in range(9))
    lower = min(sum(ca[i] * v[i] for i in range(9) if i != j) / na
                for j in range(9))
    return lower, upper

if __name__ == "__main__":
    print("   slot   value V   cells A uses (palace numbers)")
    for t in range(8):
        val, p = solve(values(t))
        cells = " ".join(str(L[c]) for c in sorted(p, key=lambda c: L[c]))
        print("     {}    {:6.4f}   {}".format(t, float(val), cells))
    lower, upper = fictitious(values(0))
    print("\n   fictitious play, slot 0, 20,000 rounds: value between"
          " {:.4f} and {:.4f}".format(lower, upper))
    val, p = solve(values(0))
    v0 = values(0)
    good = [float(p[c]) for c in p if v0[c] == 3]
    neutral = [float(p[c]) for c in p if v0[c] == 2]
    print("   exact: V = {}; A plays each good palace with {:.3f} and each"
          .format(val, good[0]))
    print("   neutral palace with {:.3f}; B blocks only good palaces"
          .format(neutral[0]))
    print("\nReading: the door cycle only permutes the values over the")
    print("palaces, so the value of the game is the same in every slot. What")
    print("changes from slot to slot is where to stand, not how much there")
    print("is to win. A plays the neutral palaces MORE often than the good")
    print("ones: a predictable 'best direction' is exactly what a rival")
    print("would block.")
#    slot   value V   cells A uses (palace numbers)
#      0    2.0000   1 4 5 6 8 9
#      1    2.0000   1 2 3 5 8 9
#      2    2.0000   2 3 4 5 7 8
#      3    2.0000   3 4 5 6 7 9
#      4    2.0000   1 2 4 5 6 9
#      5    2.0000   1 2 5 7 8 9
#      6    2.0000   2 3 5 6 7 8
#      7    2.0000   1 3 4 5 6 7
#
#    fictitious play, slot 0, 20,000 rounds: value between 1.9879 and 2.0111
#    exact: V = 2; A plays each good palace with 0.133 and each
#    neutral palace with 0.200; B blocks only good palaces
#
# Reading: the door cycle only permutes the values over the
# palaces, so the value of the game is the same in every slot. What
# changes from slot to slot is where to stand, not how much there
# is to win. A plays the neutral palaces MORE often than the good
# ones: a predictable 'best direction' is exactly what a rival
# would block.

两个结论都与直觉相反。第一,博弈的值在每个时段都是 2。门的轮转只是把同一组数值在宫位之间置换,而博弈的值只依赖于数值的多重集合,不依赖于它们在哪里;随时段改变的只是「站在哪里」,而不是「能赢多少」。虚拟对策在 20,000 轮后把值夹在 1.9879 与 2.0111 之间,与精确解一致。

第二,A 用中平之门比用吉门更多:每个中平之宫的概率是 0.200,每个吉宫只有 0.133;B 则只封锁吉宫。一个人人都知道的「最佳方向」,恰好是对手最先封锁的方向。在有对手的环境里,可以预测本身就是代价。

注

对「方位与时机最优策略」功能的含义。 本章的两个模型给出的最优策略完全由输入的门值决定:换一组数值,最优方向与时间随之改变。模型能保证的只是:在给定数值的前提下,策略是最优的。数值本身是否对应现实中的任何东西,模型既不能证明,也没有检验。

假说 · 尚未验证

作者的假说(尚未验证): 在一个事先登记、按本章规则为参与者随机指定「吉时吉向」或「凶时凶向」的双盲实验中,两组在预先定义的结局(例如谈判成交率)上没有可区分的差别。什么结果会证明它错:预先登记的主要结局在两个独立样本中都显示吉组显著优于凶组。

小结

把择时择向写成转动网格上的动态规划后,一个组合事实决定了结果:三个吉门相邻、中宫的四个邻宫在环上交错,所以方向自由时一步之内总有吉门,择时不增加任何价值(两种情形的均值都是 0.900)。择时只在方向固定时才有价值,此时等待把均值从 −0.1500 提高到 +0.6625。有对手时,门的轮转只是置换数值,博弈的值在每个时段都相同;均衡中 A 更多地使用中平之门,因为可以预测的最佳方向正是对手封锁的方向。所有结论都以输入的门值为前提。

参考文献

Alpern, Steve, and Shmuel Gal. 2003. The Theory of Search Games and Rendezvous. Kluwer Academic Publishers.
Bellman, Richard. 1957. Dynamic Programming. Princeton University Press.
Brown, George W. 1951. “Iterative Solution of Games by Fictitious Play.” In Activity Analysis of Production and Allocation, edited by Tjalling C. Koopmans. Wiley.
Robinson, Julia. 1951. “An Iterative Method of Solving a Game.” Annals of Mathematics 54 (2): 296–301.

Fan, Y. (2026). Dyadic Phase Coupling, Bilinear Compatibility Tensors and Spatiotemporal Grid Games: Asymmetric Kuramoto Locking, Stopping-Time Separation Hazards and Magic-Square Permutation Operators [双人相位耦合、双线性相容张量与时空网格博弈] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090172 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).