Please compute the minimum number of movements to checkmate the black king of a given (simplified) chess position, with the following properties:
It is white’s turn.
White has no king: only queens, rooks and bishops.
Black only has a king.
Input consists of several cases. Each case begins with the position of the black king, followed by a number between 2 and 4, followed by the position of white pieces. Every given position is legal (except for the missing white king). It is always possible to checkmate the black king in at most 4 movements.
For every position, print the minimum number of movements to checkmate the black king.
Salvador Roura
© Jutge.org, 2006–2025.
Input
Ka4 2 Rb7 Rg1 Kh1 2 Qf8 Qe7 Ka8 3 Ba7 Bb8 Bf1 Ke3 3 Qd5 Rd4 Be5 Kf1 3 Rd2 Be3 Re8 Kd4 4 Ra5 Rh5 Bc8 Bf8
Output
1 2 1 3 2 4