Back
Close
  • 259

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

8 x 8 space-separated character rows of a chessboard with only two pieces on the board: your King and one enemy piece. Print Check or No Check depending on whether the enemy piece is able to attack your king on the next turn.

The King will be a K character. The enemy piece will be Bishop (B), Knight (N), Rook (R) or Queen (Q). The empty positions will be _ in the input. There are exactly two non-_ characters: one K and one of either B/N/R/Q.

Bishops (B): Attack diagonally in all four directions.
Rooks (R): Attack horizontally/verically in all four directions (can attack along same row or column)
Queens (Q): Attack in all eight of the above directions.

Knights (N): Attack in L-shapes - squares that are two rows and one column away (L), or one row and two columns away (∟). (These happen to be the only eight squares in a 5x5 sub-grid that a Queen can't attack from the same spot).

Diagram for the squares a Knight can attack (x is used here to indicate these squares):


_ _ _ _ _ _ _ _
_ _ x _ x _ _ _
_ x _ _ _ x _ _
_ _ _ N _ _ _ _
_ x _ _ _ x _ _
_ _ x _ x _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _


If a King is in any of those x positions relative to the Knight on the input diagram, then the answer is Check, otherwise No Check.
Input
8 lines of : 8 space-separated characters, mostly underscores with exactly one K and one of B/N/R/Q.
Output
1 line : Check if the King is in check or No Check if not.
Constraints
Example
Input
_ _ R _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ K _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
Output
Check

A higher resolution is required to access the IDE