How Koga decides
- After our move, an enemy piece (never a king or pawn) is attacked and has no safe square to run to. Every legal retreat either walks into a profitable capture or there are no legal moves at all.
- The attack must be one our move just created — a piece that could already legally capture the target before we moved does not count as a fresh trap on its own.
- Finally, the engine's main line must actually cash the piece in: a few moves deep, we capture the trapped piece (or it after it shuffles) and the capture wins material.
- For each square the trapped piece could legally move to, we ask: once it lands there, can we still win it for profit?
- If even one destination is safe — no profitable capture follows — the piece is not trapped and we say nothing.
- If the attack already existed before our move, we additionally require that the piece had no safe escape beforehand either, so we are not taking credit for a trap that was already complete.
- During check — if our move gives check, we skip trapped-piece entirely; the opponent's reply is forced by the check, not by any trap.
- Safe on its own square — if the attacker cannot profitably capture the target where it stands (a defender makes the capture a losing trade), the piece is not trapped even if its flight squares are all bad.
- Already pinned — if the very same target is being reported as pinned, the pin tells the story and trapped-piece is suppressed.
- Slid along an old line — if our piece was already attacking the target from its previous square, simply sliding to a new square on the same attack does not count as a newly created attacker.
- Forced trade — if the only way to win the piece is to recapture it on the attacker's own square for an equal-or-worse exchange, that reads as a trade, not a trap.
- Trapped Piece is a supporting label. When a richer tactic (a pin, a fork, a clean win of material) already explains the move, that takes the spotlight.
- When the engine line is too short to show the piece being collected, we still flag a trap if the piece has exactly one flight square and we can profitably take it there — but only if no other tactic was found (or only a counter-threat). If something better is present, the fallback stays silent.
Test positions (the examples that guard against regressions)
Queen trapped in the corner of the board
Lichess 00BM8. After Nb1, the knight attacks the black queen on a3, and every queen retreat runs into a profitable capture. The main line wins her with Qa4 (...Qxa4) the following move.
Queen trapped against the edge file
Lichess 00DdW. After Rb1 the rook attacks the black queen on b2. The queen has no safe square; she is herded to b3, where Rxb3 wins her. The square where she is finally taken (b3) is different from where the rook first attacked.
Rook with no moves at all
Lichess 06cqX. After Qxf3 the queen eyes the a8 rook, which is hemmed in by its own pieces and has no legal move whatsoever. With no flight squares to check, the rook is simply collected by Qxa8.
Trap revealed by a discovered attack
A constructed position. The pawn push c4 unmasks the bishop on d2, whose diagonal now hits the knight on a5. Every knight retreat loses it, and the line wins it on b7. Here the attacker (the bishop on d2) is a different piece from the one that moved.
Short line — the one-escape fallback
A constructed position where the engine line ends right after e4. The pawn push e4 attacks the bishop on d5, which has only a single legal retreat, and that square loses it too. Because nothing richer than a counter-threat was found, the supporting trapped-piece label is allowed.
Not trapped — the queen has a safe escape
A constructed position. The bishop moves to g5 and attacks the queen on d8, but the queen has plenty of safe squares to run to. A newly attacked piece is only trapped when every retreat fails.
Not trapped — already explained by a pin
A constructed position. The knight on d5 is attacked and short of squares, but it is already being reported as pinned. The pin tells the fuller story, so trapped-piece is suppressed on that same piece.
Not trapped — safe where it stands
A constructed position. The queen swings to g4 and eyes the knight on h3, whose only flight square loses it. But the knight is defended where it sits — Qxh3 Rxh3 just loses the queen — so the piece is not actually trapped.