Minimap and Fog of War
Fog of war hides the map until the player sees it. Every cell is never seen, in sight or remembered. Sight reaches a set distance and stops at walls. A remembered cell shows what it looked like when last seen, even if it has changed. The minimap is a window around the player that draws each cell by its fog.

Paste this to your AI
Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.
Add "Minimap and Fog of War" to my game.
What it should do: Exploring means not knowing. Fog keeps the world unknown until the player has been there, remembers what they found, and gives the minimap something honest to draw: only what the player knows, as they last saw it.
Build it exactly as this state machine. First check that it fits my game, then build it like this:
```mermaid
stateDiagram-v2
[*] --> unseen
unseen: Never seen
visible: In sight
remembered: Remembered
unseen --> visible: comes into sight
unseen --> remembered: a map scroll
visible --> remembered: goes out of sight
visible --> unseen: a new run starts
remembered --> unseen: a new run starts
remembered --> visible: comes back into sight
```
Use these starting values:
- sightRadius: 5 cells
- mapRadius: 8 cells
- scoutRadius: 12 cells
Watch out for these common mistakes:
- A map that shows the present: Tell your AI: draw a remembered cell from the memory, which holds what was last seen, and only update the memory for cells in sight.
- Seeing one way only: Tell your AI: always draw the line from the same end, so sight is the same in both directions.
- Light through a diagonal gap: Tell your AI: when the line steps diagonally and both cells beside the step are walls, the view is blocked.
- A door that opens out of sight: Tell your AI: recompute sight after every change in the world, and write into the memory only the cells in sight.
- Walls that look transparent: Tell your AI: the first wall on the line is part of what is seen. Only what lies behind it stays hidden.
- A map scroll that spoils too much: Tell your AI: a scroll fills the memory only. It does not change what is in sight.
- The edge of the world: Tell your AI: always draw a square of the same size and mark cells beyond the edge as outside.
Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
What it does
Exploring means not knowing. Fog keeps the world unknown until the player has been there, remembers what they found, and gives the minimap something honest to draw: only what the player knows, as they last saw it.
How it runs, as a diagram
Everything it can be in, and what moves it on. Your AI builds from exactly this.
How it runs, as a diagram
- Never seen → In sight: comes into sight
- Never seen → Remembered: a map scroll
- In sight → Remembered: goes out of sight
- In sight → Never seen: a new run starts
- Remembered → Never seen: a new run starts
- Remembered → In sight: comes back into sight
Good starting values
| Value | Start with | What it changes |
|---|---|---|
| sightRadius | 5 cells | How far the player sees. Five cells shows the room they stand in and a little of the next, so a corridor still hides what is round the corner. |
| mapRadius | 8 cells | How many cells the minimap shows on each side of the player. A bit more than the sight radius lets the player see what they remember around them. |
| scoutRadius | 12 cells | How far a map scroll uncovers around the player. Zero turns scrolls off. |
What usually goes wrong
A map that shows the present
If the minimap draws what is really there, it shows a door that was shut behind the player as it is now, and the player learns things they did not see.
Fix: Tell your AI: draw a remembered cell from the memory, which holds what was last seen, and only update the memory for cells in sight.
Seeing one way only
If the line from A to B is drawn differently than from B to A, the player sees a guard that cannot see them, or the other way round.
Fix: Tell your AI: always draw the line from the same end, so sight is the same in both directions.
Light through a diagonal gap
A line that squeezes between two walls touching at the corners lets the player see through a solid corner.
Fix: Tell your AI: when the line steps diagonally and both cells beside the step are walls, the view is blocked.
A door that opens out of sight
When something changes in a cell the player is not looking at, the memory should keep the old look until they see it again. When it changes in sight, it should update at once.
Fix: Tell your AI: recompute sight after every change in the world, and write into the memory only the cells in sight.
Walls that look transparent
If the wall that blocks the view is not itself seen, the player stands in front of a gap in the map.
Fix: Tell your AI: the first wall on the line is part of what is seen. Only what lies behind it stays hidden.
A map scroll that spoils too much
A scroll that puts cells in sight lets the player see monsters through walls, and one that wipes memory clears their own notes.
Fix: Tell your AI: a scroll fills the memory only. It does not change what is in sight.
The edge of the world
A minimap near an edge that simply gets smaller changes size and jumps around as the player walks.
Fix: Tell your AI: always draw a square of the same size and mark cells beyond the edge as outside.
How to check it works
- A new game with a sight radius of 5. You look at the cells around the player: The nearby cells are in sight and a far corner of the map has never been seen.
- An open room and a sight radius of 2. You look at a cell 2 steps away and one 3 steps away in a straight line: The first is in sight, the second is not.
- A wall 4 steps away with more room behind it. You look at the wall and the cell right behind it: The wall is in sight and the cell behind it is not.
- A player next to a closed door. You look at the door and the cell behind it: The door is in sight and the cell behind it is not.
- A player who walks 3 cells away with a sight radius of 2. You look at the cell they started on: It is remembered, not in sight.
- A player who walks around a room. You check every cell they have seen after each step: None of them has gone back to never seen.
- Any two cells on the map. You ask whether the first sees the second and the second sees the first: The two answers are the same.
- A cell that was seen as floor and then became a door while out of sight. You look at the minimap: It still shows floor.
- A cell that became a door while out of sight. The player walks back until it is in sight: The memory shows the door.
- A new game and a scroll with a radius of 12. The player reads it: Far cells and cells behind walls are remembered, and none of them is in sight.
- A player who has explored and read a scroll. A new run starts: The player is back at the start, only the cells around them are in sight and everything else has never been seen.
- A player in a corner of the map and a minimap radius of 2. You read the minimap: It is 5 by 5 with the player in the middle, and cells beyond the edge are marked outside.
Works well with
- Room Camera: A room camera shows a whole room at once. Lift the fog for the whole room when the player enters it, or the picture and the map disagree. Decide which room the camera shows first, then lift the fog for that room as the camera arrives.
- Enemy Patrol and Chase: If both use one line-of-sight check, a guard sees the player exactly when the player sees the guard, which feels fair. Use the same sight rule for the player's view and the guard's view.
- Ability Gates: A remembered closed gate is a useful reminder of where to come back to once the player has the right ability. Show a gate on the map as soon as it is seen, whether or not it can be opened yet.
Common questions
how do i add fog of war and a minimap to my game
Give every cell three conditions: never seen, in sight and remembered. Work out what is in sight from the player's position after every move, and copy it into a memory. Draw the minimap from the memory, not from the real world.
why does my minimap show things the player has not seen
It is drawing the real world instead of the memory. Draw a cell in sight from the real world, a remembered cell from what was last seen there, and leave every other cell blank.
how do i stop the player seeing through walls
Draw a line from the player to each cell in range and stop at the first wall or closed door. Show that wall, hide what is behind it, and block diagonal gaps between two walls. Always draw the line from the same end so sight works both ways.
what do i tell my ai to add a minimap with fog of war
Paste this: Add fog of war and a minimap. The player sees 5 cells, stopped by walls and closed doors, and sees the face of the wall. Every cell is never seen, in sight or remembered, and fog never comes back. A remembered cell shows what was last seen. Draw a minimap of 8 cells each side of the player from that memory, and mark cells beyond the edge as outside.
Where it comes from
We could not find a reliable origin for this one yet.
What was checked
- 25 tests pass on the reference code.
- The state diagram was checked against the code, at the default values and at every listed low and high value.
Your AI gets the code
Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it