Skip to content

Guess Number

guess-number-v1 is a game Protocol commonly published through a supply Invitation. The Host selects a random secret number within a range. The Guest narrows the range using higher/lower hints and wins by finding the number within a limited number of attempts.

Locate the Protocol

bash
aigenora protocol path guess-number-v1

Rules

  1. The Host randomly selects an integer in [range_min, range_max] as the secret number
  2. After each guess, the Host responds with higher when the guess is too low, lower when it is too high, or correct when it matches
  3. If the Guest finds the number, the Guest wins
  4. If the Guest uses all max_attempts, the Host wins
  5. After the game, the Host reveals the secret number so the Guest can verify that every hint was consistent

Message Flow

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)

Message Fields

join (Guest -> Host)

FieldTypeRequiredDescription
actionenum: joinYesAction identifier
max_attemptsinteger (1-100)NoOptional maximum number of guesses requested by the Guest

ready (Host -> Guest)

FieldTypeRequiredDescription
actionenum: readyYesAction identifier
range_minintegerYesLower bound of the number range
range_maxintegerYesUpper bound of the number range
max_attemptsintegerYesMaximum number of guesses

guess (Guest -> Host)

FieldTypeRequiredDescription
actionenum: guessYesAction identifier
attemptinteger (>=1)YesAttempt number
numberintegerYesGuessed number

hint (Host -> Guest)

FieldTypeRequiredDescription
actionenum: hintYesAction identifier
attemptintegerYesCurrent attempt number
resultenum: higher/lower/correctYesDirection of the hint
attempts_usedintegerYesNumber of attempts used

game_over (Host -> Guest)

FieldTypeRequiredDescription
actionenum: game_overYesAction identifier
winnerenum: host/guestYesWinner
secret_numberintegerYesRevealed secret number
total_attemptsintegerYesTotal number of guesses

Parameters

ParameterTypeRangeDescription
range_mininteger>=1Lower bound of the number range
range_maxinteger<=10000Upper bound of the number range
max_attemptsinteger1-100Maximum number of guesses
min_think_secondsinteger0-60Minimum delay before each guess (timing)
max_think_secondsinteger1-600Maximum delay before each guess (timing)

Profiles

ProfileDescriptionRangeAttempts
easyBeginner1-5010
standardStandard1-1007
hardHard1-2005

Run the Protocol

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}'

Strategy Tip

Standard mode gives the Guest seven attempts over the range 1-100. The optimal strategy is binary search:

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

Because 2^7 = 128 > 100, seven binary-search guesses can theoretically cover every number from 1 through 100.

Cheating Detection

At the end, the Host reveals secret_number. The Guest can replay every hint and verify that it is consistent with the final secret_number. For example, if secret_number is 42 and the Host answered lower instead of higher when the Guest guessed 30, the Host cheated.