I want to offer a semi-realistic example. I think I have seen something like this in a game by masters in some book, but of course I cannot recall where. But this is something that at least can be realistically missed in calculations from far away.
[FEN "6k1/5ppp/6r1/3b4/4r3/8/1Q5P/1R5K w - - 0 1"]
White just gives a back rank mate, right? :)
Sure it's possible, in fact it's possible that this kind of "inevitability" happens earlier in the game, with many more moves to go until mate.
See example here.
[FEN "K1k5/P1Pp4/1p1P4/8/p7/P2P4/8/8 w - - 0 1"]
[Event "White to play and win"]
1. d4 b5 2. d5 b4 3. axb4 a3 4. b5 a2 5. b6 a1=Q 6. b7#
Forced mate positions do occur in real games although it is pretty rare: such a mate is only delivered about once in 68,000 games on lichess.org. One example comes from this game with the penultimate position:
[FEN "KQ6/2k5/1qP5/N7/5p1p/8/6PP/8 b - - 0 51"]
[Event "Rated Blitz game"]
What I did in my program was to only look for checkmates if the king was in check. I only generate pseudo-legal moves in my move generation function so I simply play out all the moves generated and check if the king still is in check. If this is the case I undo that move and delete it from my list of moves. This is repeated until I find a legal move or the ...