Chess attack X79963


Statement
 

pdf   zip

You are given pairs of chess pieces with locations; for each pair, you are to output true if the first piece can attack the second, and false otherwise.

Input

A number n1n \geq 1, followed by nn pairs of pieces.

Each piece is specified in the following format: type xx yy. Type is a character: K for king, Q for queen, R for rook, B for bishop, and N for knight. xx and yy are ints such that 0x70 \leq x \leq 7 and 0y70 \leq y \leq 7; they specify the xx and yy coordinates of the piece’s position on the chessboard.

In each pair, the two pieces are guaranteed to be in different positions.

Output

For each pair, output true if the first piece can attack the second, and false otherwise. Refer to Wikipedia (or another internet source) for information on how each of the pieces behave.

Observation

Public test cases
  • Input

    4
    Q 2 3 Q 3 5
    Q 2 3 Q 4 5
    B 1 1 K 2 3
    N 1 1 K 2 3
    
    
    

    Output

    false
    true
    false
    true
    
  • Information
    Author
    Hubie Chen
    Language
    English
    Official solutions
    Java
    User solutions