Scent Maps: How Monsters Track the Player

In many roguelikes, monsters do not have perfect information about the player’s location. Instead, they rely on indirect clues from the environment. One elegant technique used to simulate this behavior is the scent map.

Scent maps allow monsters to track the player’s recent movement, even when the player is no longer visible. This helps create believable pursuit behavior without giving monsters unrealistic omniscience.

Games like Brogue use this technique to make dungeon exploration feel tense and dynamic.


The Basic Idea

Every time the player moves, the game leaves a “scent trace” on the tile they occupied.

Think of it like footprints that gradually fade over time.

Each tile stores a numeric scent value representing how recently the player was there. Newer scents are stronger, while older scents slowly decay.

For example:

10  9  8  7
11  P  .  6
12 13 14  5

Here, P marks the player’s current position. Nearby tiles contain slightly older scent values. Tiles farther along the path contain older traces.

Monsters can follow the gradient of scent values to track the player’s route through the dungeon.


Why This Works So Well

Scent maps provide several advantages for roguelike AI.

Realistic Tracking

Monsters can pursue the player even after losing sight of them, creating tension and believable behavior.

Imperfect Information

Because scents fade and can be disrupted by obstacles or time, monsters can lose the trail.

Cheap Computation

Unlike complex planning systems, scent maps require only simple grid updates.

Emergent Behavior

Multiple monsters using the same scent field naturally coordinate pursuit without explicit communication.


Updating the Scent Map

In the Swift reimplementation, the scent map is implemented as a grid parallel to the dungeon map.

Each tile stores an integer value representing scent strength.

Whenever the player moves:

  1. A global scent counter increases.
  2. The current tile records the new scent value.

Conceptually:

scentMap[player.x, player.y] = currentScentValue

Over time, older scent values naturally become less relevant.

Monsters simply move toward higher scent values, which correspond to newer player positions.


Combining Scent with Pathfinding

A scent map by itself is not enough. Monsters must still consider dungeon obstacles such as walls and doors.

To solve this, scent values are combined with pathfinding or distance calculations.

The general rule is simple:

Move toward the neighboring tile that leads to the freshest scent.

This produces surprisingly intelligent behavior:

All of this emerges from a very simple system.


Losing the Trail

A good tracking system should not be perfect.

Several factors can cause monsters to lose the scent:

When the scent becomes too weak, monsters typically revert to idle behavior or random exploration.

This keeps the AI believable and prevents the player from being relentlessly hunted across the entire dungeon.


Interaction with Field of View

Scent maps work closely with the Field of View (FOV) system.

Typical monster behavior looks like this:

  1. If the monster sees the player, it moves directly toward them.
  2. If the monster loses sight, it begins following the scent trail.
  3. If the scent fades completely, it resumes wandering.

This layered approach makes monster behavior feel intelligent without requiring complex AI logic.


Efficient Grid Updates

The scent map grid is very cheap to maintain.

Each turn:

Because the dungeon grid is small, the entire system has negligible performance cost.

In Swift, it fits naturally into the same grid structure used by other systems such as pathfinding and lighting.


Emergent Gameplay Effects

Although simple, scent maps produce several interesting gameplay outcomes.

For example:

Stealth Opportunities

A clever player can break pursuit by taking a winding path or hiding behind obstacles.

Ambush Scenarios

Monsters may follow the scent into a room where the player is waiting.

Group Pursuit

Multiple monsters can independently follow the same scent trail, appearing to coordinate.

These behaviors arise naturally from the mechanics without requiring scripted AI.


Reimplementing the System in Swift

The scent map system was rebuilt from scratch during the engine reimplementing.

Instead of using raw arrays and procedural logic, the Swift version integrates scent tracking into the same grid-based infrastructure used by other systems.

This makes the code easier to reason about and allows scent behavior to interact cleanly with pathfinding, AI, and environmental effects.

The underlying concept remains simple, but the implementation is clearer and more maintainable.


Final Thoughts

Scent maps are one of the subtle systems that give roguelikes their distinctive feel. They allow monsters to track the player realistically without giving them perfect information.

Combined with field-of-view and pathfinding systems, scent maps help create the cat-and-mouse tension that defines dungeon exploration.

Rebuilding this mechanic in Swift ensures that the new engine retains the clever AI behavior that makes classic roguelikes so engaging.