Chess attack X90222


Statement
 

pdf   zip

html

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 n ≥ 1, followed by n pairs of pieces.

Each piece is specified in the following format: type x y. Type is a character: K for king, Q for queen, R for rook, B for bishop, and N for knight. x and y are ints such that 0 ≤ x ≤ 7 and 0 ≤ y ≤ 7; they specify the x and y 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