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.
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.
Scent maps provide several advantages for roguelike AI.
Monsters can pursue the player even after losing sight of them, creating tension and believable behavior.
Because scents fade and can be disrupted by obstacles or time, monsters can lose the trail.
Unlike complex planning systems, scent maps require only simple grid updates.
Multiple monsters using the same scent field naturally coordinate pursuit without explicit communication.
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:
Conceptually:
scentMap[player.x, player.y] = currentScentValueOver time, older scent values naturally become less relevant.
Monsters simply move toward higher scent values, which correspond to newer player positions.
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.
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.
Scent maps work closely with the Field of View (FOV) system.
Typical monster behavior looks like this:
This layered approach makes monster behavior feel intelligent without requiring complex AI logic.
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.
Although simple, scent maps produce several interesting gameplay outcomes.
For example:
A clever player can break pursuit by taking a winding path or hiding behind obstacles.
Monsters may follow the scent into a room where the player is waiting.
Multiple monsters can independently follow the same scent trail, appearing to coordinate.
These behaviors arise naturally from the mechanics without requiring scripted AI.
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.
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.