This note is based on a number-guessing game strategy I implemented. The game looks simple from the outside, but its structure is closer to a partially observed search problem than a normal binary-search exercise. It is single-player, stochastic, and imperfect-information: the player does not know the current hidden number N, and also does not know the movement parameter P.
The key rule is asymmetric. If a guess is too high, N does not change and the search range can be reduced safely. If a guess is too low, however, the server adds P to N, so the target moves upward. That means a wrong low guess is not only an information signal; it also changes the state of the game.
Our first baseline was a Greedy Search with a 60% heuristic. Instead of choosing the midpoint of the current range, it guesses around the 60% position. The reason is practical: guessing slightly higher than the median reduces the chance of undershooting and pushing N forward. This baseline is better aligned with the game rule than ordinary binary search, but it still tracks only a rough low-high interval. It does not know which (N, P) combinations are still possible.
In the current implementation, the initial belief set is:
The improved strategy is Possible State Greedy Search. It stores every candidate state at the beginning, then removes impossible states after each server response. After a guess g, if the guess is too large, every state with N >= g is removed. If the guess is too small, every state with N <= g is removed, and the remaining states are advanced:
After the update, the algorithm extracts the remaining possible N values, sorts them, and chooses the 60% position as the next guess. This preserves the intuition of the baseline while making it state-aware. The guess is no longer selected from a rough interval; it is selected from the actual surviving state set.
When the possible range becomes small, the strategy switches to a high-to-low scan. This is important because, in a narrow range, a too-high guess is safer than a too-low guess: it narrows the possibilities without moving N. The algorithm therefore becomes more conservative near the end, avoiding repeated undershoots that would make the hidden value drift.
In a 10-round evaluation, the result had a maximum of 63 attempts, a minimum of 5 attempts, and an average of 29 attempts. The variability is still visible because the game can produce difficult hidden (N, P) combinations, but the method is more controlled than the simple baseline because it explicitly models how the game state evolves.
A natural next improvement would be to score each candidate guess by posterior uncertainty and transition cost:
This would turn the heuristic into a transition-aware policy. The goal would not only be to reduce the number of possible states, but also to avoid guesses that are likely to trigger upward movement. In this sense, the algorithm is a small example of a broader AI idea: when an action changes the hidden state, search should optimize both information gain and state-transition risk.
My main takeaway is that this problem rewards thinking beyond a fixed formula. The 60% greedy rule is a useful prior, but the stronger idea is to maintain a belief state and update it faithfully. Once the environment moves in response to mistakes, the search strategy has to become a model of the game, not only a sequence of guesses.
这篇笔记基于我实现的一种猜数游戏策略。游戏表面简单,结构却更接近部分可观测搜索,而不是普通二分查找。它是单人、随机、不完全信息游戏:玩家既不知道当前隐藏数 N,也不知道移动参数 P。
关键规则是不对称的。猜高时,N 不变,搜索范围可以安全缩小;猜低时,服务器会将 P 加到 N 上,让目标上移。因此,一次猜低不仅提供信息,还改变了游戏状态。
最初的基线是带 60% 启发式的贪心搜索。它不选当前区间中点,而选择约 60% 的位置。这样略高于中位数的猜测可降低猜低、推动 N 上移的概率。它比普通二分查找更符合规则,但仍只维护粗略的上下界,不知道哪些 (N, P) 组合仍可能成立。
当前实现的初始信念集合为:
改进策略称为 Possible State Greedy Search。它一开始存储所有候选状态,每次收到服务器反馈后删除不可能的状态。猜测为 g 时,若猜大了,删除所有 N >= g 的状态;若猜小了,删除所有 N <= g 的状态,并推进剩余状态:
更新后,算法提取剩余可能的 N,排序并选择 60% 分位作为下一次猜测。它保留基线直觉,但显式感知状态:猜测不再来自粗略区间,而是来自实际存活的状态集合。
当可能范围变小时,策略切换为从高到低扫描。因为在窄区间中,猜高比猜低更安全:它缩小候选范围,却不移动 N。算法因此在接近结束时更加保守,避免反复猜低导致隐藏值持续漂移。
在一次 10 局评估中,最多尝试 63 次,最少 5 次,平均 29 次。不同隐藏 (N, P) 组合仍会带来明显波动,但显式建模状态演化,让方法比简单基线更可控。
一个自然的后续改进,是同时按后验不确定性与转移代价评价候选猜测:
这会将启发式提升为转移感知策略。目标不只是减少可能状态,还要避免容易引起目标上移的猜测。它体现了一个更一般的 AI 思想:当动作会改变隐藏状态时,搜索应同时优化信息增益与状态转移风险。
我的主要体会是,这个问题鼓励我们超越固定公式。60% 贪心规则是有用的先验,更重要的思想却是维护并忠实更新信念状态。环境会因错误而移动时,搜索策略必须成为游戏的模型,而不仅是一串猜测。