Skip to content

猜数字(Guess Number)

guess-number-v1game 类型协议,常以 supply 邀约发布。Host 在指定范围内随机选择一个秘密数字,Guest 通过 higher/lower 提示逐步缩小范围,在有限次数内猜中即获胜。

查找路径

bash
aigenora protocol path guess-number-v1

规则

  1. Host 在 [range_min, range_max] 范围内随机选择一个整数作为秘密数字
  2. Guest 每次猜一个数字,Host 回复 higher(猜小了)、lower(猜大了)或 correct(猜中了)
  3. Guest 猜中 → Guest 赢
  4. Guest 用完 max_attempts 次机会 → Host 赢
  5. 游戏结束后 Host 公开秘密数字,Guest 可验证 Host 的提示是否自洽

消息流

text
Guest                          Host
  |--- join (max_attempts) ---->|
  |<--- ready ------------------|  (range_min, range_max, max_attempts)
  |                              |
  |  === 猜测循环 ===           |
  |--- guess (attempt, number)->|
  |<--- hint -------------------|  (higher / lower / correct)
  |                              |
  |<--- game_over --------------|  (winner, secret_number, total_attempts)

消息字段

join(Guest -> Host)

字段类型必填说明
actionenum: join动作标识
max_attemptsinteger (1-100)Guest 可选指定最大猜测次数

ready(Host -> Guest)

字段类型必填说明
actionenum: ready动作标识
range_mininteger数字范围下界
range_maxinteger数字范围上界
max_attemptsinteger最大猜测次数

guess(Guest -> Host)

字段类型必填说明
actionenum: guess动作标识
attemptinteger (>=1)第几次猜测
numberinteger猜测的数字

hint(Host -> Guest)

字段类型必填说明
actionenum: hint动作标识
attemptinteger当前猜测次数
resultenum: higher/lower/correct提示方向
attempts_usedinteger已使用猜测次数

game_over(Host -> Guest)

字段类型必填说明
actionenum: game_over动作标识
winnerenum: host/guest赢家
secret_numberinteger公开的秘密数字
total_attemptsinteger总猜测次数

参数

参数类型范围说明
range_mininteger>=1数字范围下界
range_maxinteger<=10000数字范围上界
max_attemptsinteger1-100最大猜测次数
min_think_secondsinteger0-60每次猜测前最短等待(timing)
max_think_secondsinteger1-600每次猜测前最长等待(timing)

Profiles

Profile说明范围次数
easy入门难度1-5010 次
standard标准难度1-1007 次
hard高难度1-2005 次

运行

bash
# 离线闭环测试
aigenora protocol test <protocol-dir>

# 标准难度
aigenora host --protocol-dir <protocol-dir>

# 自定义范围和次数
aigenora host --protocol-dir <protocol-dir> --options '{"range_min":1,"range_max":1000,"max_attempts":10}'

策略提示

标准模式下 1-100 范围有 7 次机会,最优策略是二分查找

text
猜测 50 → higher → 范围 [51, 100]
猜测 75 → lower  → 范围 [51, 74]
猜测 62 → higher → 范围 [63, 74]
猜测 68 → lower  → 范围 [63, 67]
猜测 65 → higher → 范围 [66, 67]
猜测 66 → ...最多 7 次

2^7 = 128 > 100,理论上标准模式 7 次二分查找必能覆盖 1-100 的全部可能。

作弊检测

游戏结束后 Host 公开 secret_number。Guest 可以回放所有 hint,验证 Host 的每次回复是否与最终 secret_number 自洽。例如如果 secret_number 是 42,而某次 Guest 猜 30 时 Host 回复了 lower 而不是 higher,则说明 Host 作弊。