user26846: Given a position, is there a way we can classify a it, such as if whether there is a pin, fork, or trap, or a mate a mate in 2 or 3? If it is possible, what would be a better approach, an algorithmic way or a machine learning/reinforcement learning? Or are there any other alternatives ways?

user825: Yes. Let's break it down.
Pin, fork
This is easily done by bitboard operations. I'm not aware of an independent package that can do that, but it's not hard to do it yourself. You just need to work out all the attackers (White and Black), where your pieces are, do some bitwise AND XOR operations. Please take a look at Stockfish's evaluate.cpp.
mate a mate in 2 or 3
Easy! Just run Stockfish or even better a mate tactics solver such as Crystal!
trap
This is going to be very challenging if possible with our current technology. Chess engine doesn't really understand the moves, they assume best play. Computers doesn't understand human-imperfect-level dirty plays. You can work out some simple traps by passing the move to the other colour (e.g. lichess, chess.com etc), but you're not going to get perfect results.

26846: <p>Given a position, is there a way we can classify a it, such as if whether there is a pin, fork, or trap, or a mate a mate in 2 or 3? If it is possible, what would be a better approach, an algorithmic way or a machine learning/reinforcement learning? Or are there any other alternatives ways?</p>
 825: <p>Yes. Let's break it down.</p>
<p><code>Pin, fork</code></p>
<p>This is easily done by bitboard operations. I'm not aware of an independent package that can do that, but it's not hard to do it yourself. You just need to work out all the attackers (White and Black), where your pieces are, do some bitwise AND XOR operations. Please take a look at Stockfish's <code>evaluate.cpp</code>.</p>
<p><code>mate a mate in 2 or 3</code></p>
<p>Easy! Just run Stockfish or even better a mate tactics solver such as <code>Crystal</code>!</p>
<p><code>trap</code></p>
<p>This is going to be very challenging if possible with our current technology. Chess engine doesn't really understand the moves, they assume best play. Computers doesn't understand human-imperfect-level dirty plays. You can work out some simple traps by passing the move to the other colour (e.g. lichess, chess.com etc), but you're not going to get perfect results.</p>
