Chess Battles
InterviewTime limit2sMemory limit1024 MB
Given one white and one black chess piece on distinct squares, decide whether each attacks the other and report NONE, WHITE, BLACK, or BOTH.
- Level
Medium4 of 10
- Topics
- Implementation, Math, Geometry, Simulation
- Solved
- No attempts yet
Problem
Petya recently started playing chess.
Recall that chess is played by two players, each of whom initially has 8 pieces and 8 pawns. In this problem we do not consider pawns.
No piece except the knight can jump over its own or the opponent's pieces. A piece cannot move to a square occupied by a piece of its own color. When a piece moves to a square occupied by an opponent's piece, that piece is removed from the board.
The pieces move as follows:
- king --- to any adjacent square vertically, horizontally, or diagonally;
- queen --- to any distance vertically, horizontally, or diagonally;
- rook --- to any distance vertically or horizontally;
- bishop --- to any distance diagonally;
- knight --- in the shape of the letter <<Г>>: 1 square horizontally and 2 vertically, or vice versa, 1 square vertically and 2 horizontally.
You are given the positions of one white piece and one black piece. Determine whether the pieces attack each other, and if they do, output which one attacks which.
Input
The first line of the input file contains the type and position of the white piece. The second line contains the type and position of the black piece.
Each piece is given as a string of three characters. The first character denotes the type of the piece: <<B>> --- bishop, <<N>> --- knight, <<R>> --- rook, <<Q>> --- queen, <<K>> --- king. The second character denotes the horizontal (from <<a>> to <<h>>). The third character denotes the vertical (from <<1>> to <<8>>).
It is guaranteed that the pieces are on different squares of the chessboard.
Output
Output one word to the output file --- the answer to the problem.
If neither piece attacks the other, output <<NONE>>.
If both pieces attack each other, output <<BOTH>>.
If the white piece attacks the black piece and the black piece does not attack the white piece, output <<WHITE>>.
If the black piece attacks the white piece and the white piece does not attack the black piece, output <<BLACK>>.