skip to content

How should a stealth guard hear a thrown bottle, remember where it last saw the player, and let that memory decay?

level: middleimportance: must knowfreq 55%

answer

  1. noise as an event with a reach
  2. where it happened, not who did it
  3. path distance, not through walls
  4. one record per sensed thing
  5. confidence fades, then forget

basics

~20 s

A noise is a stimulus event with a position, a reach and a time; guards within reach register it. Each sighting or sound updates a memory record holding a last known position and a confidence that decays until the guard gives up.

solid answer

~50 s

The bottle's impact, not the throw, emits a **sound stimulus**: a position, a loudness expressed as a reach, a type, the object that made it and a timestamp. The perception system finds guards within that reach, ideally measured along walkable space rather than straight through walls, scales it by each guard's hearing, and writes it into the guard's **memory**. Memory is one record per sensed thing: **last known position**, last time sensed, which sense, and a confidence. When sight is lost the record keeps the last known position, not the player's true one. Confidence decays with time; the guard investigates that point, searches around it, and eventually forgets the record and returns to its routine, often a more watchful one. Decision code reads this memory, never the live world, which keeps the guard honest and debuggable.

code

pseudocode · 18 lines
pseudocode
function onSound(guard, s):        // s: position, reach, sourceId, strength, time
    if pathDistance(s.position, guard.position) > s.reach * guard.hearingScale:
        return                          // out of earshot
    rec = guard.memory.findOrCreate(s.sourceId)   // new: strength 0, time s.time, hearing half-life
    if s.strength >= currentConfidence(rec, s.time):
        rec.lastKnownPos = s.position   // where the noise happened, not where its maker is now
        rec.sensedStrength = s.strength
        rec.lastSensedTime = s.time
        rec.halfLife = HEARING_HALF_LIFE

function currentConfidence(rec, now):
    age = now - rec.lastSensedTime
    return rec.sensedStrength * 0.5 ^ (age / rec.halfLife)

function forgetStale(guard, now):
    for rec in copy(guard.memory):
        if currentConfidence(rec, now) < guard.forgetThreshold:
            guard.memory.remove(rec)

go deeper

for a junior

Recall what a stimulus carries (position, reach, type, source, time) and what a memory record holds, above all the last known position.

for a middle

Explain listener selection, why the impact point and not the thrower is stored, how records merge, and how a half-life and forget threshold end a search.

for a senior

Diagnose telepathic or deaf guards from playtest reports: path versus straight-line hearing, a record that tracks the true position, stale or duplicate records.

for a principal

Decide whether decision code may ever read the world directly, and make the memory layer the one place where the AI's knowledge is visible and reviewable.

## Stimuli as events A **stimulus** is a short-lived fact that something sensable happened. For sound it typically carries: - **position**: where the noise happened, such as where the bottle shattered; - **reach**: how far it can be heard, standing in for loudness; - **type**: footstep, gunshot, breaking glass, an ally's shout; - **source**: the object that made the noise; - **time**: when it happened, so later code can judge its age. Delivery can ride on the game's general messaging, but what matters here is the content of the stimulus and which guards receive it. The thrown bottle is the canonical stealth test: the noise belongs to the impact point, so the guard learns "something broke over there", not where the player is standing. If the stimulus carried the thrower's position, the distraction mechanic would collapse. ## Who hears it Finding listeners starts with a cheap spatial cull: only guards within the stimulus reach in straight-line distance are candidates. How the final distance is measured is a design choice: | Measure | Behaviour | Cost | |---|---|---| | Straight-line distance | Guards hear through thick walls and floors | Cheapest | | Path distance through walkable space | Sound wraps round corners and through doorways | A path query per candidate | | Room and doorway graph | Sound loses strength at each closed door | A small graph walk; needs authored rooms | Each guard then scales the reach by its own **hearing**: a sleeping guard hears less, an alerted one more. ## The memory record Perception writes into a per-guard **memory**, one record per sensed thing: - **last known position** and, for moving targets, last known velocity; - **last sensed time** and **which sense** produced it; - **confidence**: how sure the guard is that the record is still true; - a flag for whether the target is visible right now. New stimuli update an existing record instead of creating duplicates: ten footsteps from one source refresh one record, and anonymous noises close together in space and time, such as several thrown objects, can merge into one record of a disturbance. A strong fresh sighting should not be overwritten by a faint later sound. ## Decay and forgetting Confidence falls with age. Exponential decay with a half-life `h` gives `confidence = initial * 0.5^(age / h)`. With a 5-second half-life, chosen here only as an example, a record is at one half after 5 seconds, one quarter after 10 and one eighth after 15. Exponential decay never reaches zero, so a **forget threshold** removes the record. A typical lifecycle: 1. **Fresh**: the guard turns towards the last known position. 2. **Investigating**: it moves to that position. 3. **Searching**: finding nothing there, it checks nearby hiding spots. 4. **Forgotten**: confidence falls below the threshold and the record is dropped. 5. **Watchful routine**: the guard resumes patrol, often with keener senses than before. How the guard acts at each step belongs to its decision model; perception supplies the records and their confidence. ## Sight and sound in one memory Sight and hearing feed the same records, which keeps the guard's behaviour coherent: - A **sighting** refreshes the player's record with high confidence and, while the player stays visible, keeps its position current. - When sight is lost, the record freezes at the **last known position** and starts to decay; some designs extrapolate along the last seen velocity for a moment. - A later sound made by the player, such as a footstep, refreshes that record with the footstep's position, giving the guard a new point to check without revealing where the player really is. - An ally's shout is just another stimulus: the shouting guard passes on its own record, not the truth. Different senses usually get different half-lives, so a clear sighting is remembered longer than a faint scuff. ## Common defects - **Telepathic guards**: after losing sight, the record keeps following the player's real position, so the guard walks straight to every hiding spot. - **Hearing through walls**: straight-line distance across a thick wall sends a guard towards a room it cannot reach. - **Records that never expire**: guards keep reacting to noises minutes old. - **Duplicate records**: every footstep is a new record, and the guard thrashes between them. - **Decision code that reads the world**: one shortcut that peeks at the player's true position undoes the whole system.

  • Why judge a noise heard through a wall by path distance rather than straight-line distance?
    Straight-line distance ignores walls, so a guard on the far side of a thick wall hears clearly and heads for a spot it cannot reach. Path distance through walkable space approximates sound wrapping round corners and through doorways, and gives a reachable point to investigate. It costs a path query per listener, so cull candidates by straight-line reach first.
  • How do you stop a guard hunting the player perfectly after losing sight?
    The record stops updating when sensing stops: it holds the last known position and perhaps the last velocity. The guard may extrapolate along that velocity for a second or two, then search around the end point. Without a new sighting or sound, nothing tells it where the player went, so a player who changes direction escapes.
  • A player throws ten bottles in quick succession; what should the guard's memory do?
    Merge rather than multiply. Noises close together in space and time refresh one record of a disturbance instead of adding ten, matched by position because each bottle is a different source. Many games also let repeated harmless noises lower the guard's reaction, so the trick works once or twice but not forever, which is a design decision made explicit in the perception data.

A witness to a crash: they can tell you where they heard glass break and roughly when, not where the culprit is standing now, and their account gets vaguer the longer you wait to ask.

  • When the guard hears the bottle, store the player's actual position.
  • Straight-line distance is fine for hearing; walls do not matter.
  • After losing sight, keep updating the record with the player's real position.
  • Memory records never need to expire once created.
  • Every footstep heard should create a new memory record.
  • Decision code can read the world directly when memory is inconvenient.