Back
Close

Is the King in Check?

Statement

 Goal

Input is 8 rows of 8 space-separated characters representing a chessboard with only two pieces on the board: your King and some enemy piece. Print "X Check" or "No Check" depending on whether the enemy piece X is able to attack your king on the next turn. (Where X is the character representing the enemy piece)

The King will be a K character. The enemy piece will be Bishop (B), Rook (R) or Queen (Q). The empty positions will be _ in the input. The only two non-_ characters will be K and one of either B/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.

If a King is directly along any of the 'attack lines' of the enemy piece, then he is in check.

Print "B Check" if in check by a Bishop, "R Check" if in check by a rook, "Q Check" if in check by a Queen or "No Check" if the King is not in check.
Input
8 lines of : 8 space-separated characters, mostly underscores with exactly one K and one of B/R/Q.
Output
1 line : "X Check" if the King is in check (replacing 'X' with Q/B/R if in check by a Queen/Bishop/Rook) or "No Check" if not.
Constraints
Only two pieces on the board. Only non-space characters in input are _, one K and one of B/R/Q. Always an 8x8 size board, always two pieces.
Example
Input
_ _ R _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ K _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
Output
R Check

Game modes
Fastest, Shortest

Test cases
R vs K Test
Input
_ _ R _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ K _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Output
R Check

Validator 1 Validator
Input
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ K _ _ _ _ _ _ _ _ R _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Output
No Check

B vs K Test
Input
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ K _ _ _ _ _ _ _ B _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Output
No Check

Validator 2 Validator
Input
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ K _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ B _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Output
B Check

Q vs K Test
Input
Q _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ K _ _ _ _ _ _ _ _ _
Output
Q Check

Validator 3 Validator
Input
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ K _ _ _ _ _ _ _ _ _ _ _ _ _ _ Q _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Output
No Check

K vs R Test
Input
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ K _ _ _ _ _ _ _ _ R _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Output
No Check

Validator 4 Validator
Input
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ K _ _ _ R _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Output
R Check

K vs B Test
Input
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ B _ _ _ _ _ _ _ _ K _ _ _ _ _ _
Output
B Check

Validator 5 Validator
Input
_ _ _ _ _ _ _ Q _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ K
Output
Q Check

Solution language

Solution

Stub generator input