Given the position of the queen (qX, qY) and the opponent (oX, oY) on a chessboard. The task is to determine whether the queen can attack the opponent or not. Note that the queen can attack in the same row, same column and diagonally.
Input: qX = 4, qY = 5, oX = 6, oY = 7
The queen can attack diagonally.
Input: qX = 1, qY = 1, oX = 3, oY = 2
- If qR = oR, it means that both the queen and the opponent are in the same row and the queen can attack the opponent.
- Similarly, if qC = oC then also the queen can attack the opponent as they both are in the same column.
- And for diagonals, if abs(qR – oR) = abs(qC – oC) i.e. queen can attack the opponent diagonally.
If all of the above conditions fail then the opponent is safe from the queen.
Below is the implementation of the above approach:
- Count positions in a chessboard that can be visited by the Queen which are not visited by the King
- Maximum of all distances to the nearest 1 cell from any 0 cell in a Binary matrix
- Number of cells a queen can move with obstacles on the chessborad
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- Check if any square (with one colored cell) can be divided into two equal parts
- Check if a cell can be visited more than once in a String
- Check if cells numbered 1 to K in a grid can be connected after removal of atmost one blocked cell
- Maximum bishops that can be placed on N*N chessboard
- Number of blocks in a chessboard a knight can move to in exactly k moves
- Total position where king can reach on a chessboard in exactly M moves
- Total position where king can reach on a chessboard in exactly M moves | Set 2
- Maximum non-attacking Knights that can be placed on an N*M Chessboard
- Maximum non-attacking Rooks that can be placed on an N*N Chessboard
- Find position of non-attacking Rooks in lexicographic order that can be placed on N*N chessboard
- Check if the given chessboard is valid or not
- 8 queen problem
- N Queen Problem | Backtracking-3
- Printing all solutions in N-Queen Problem
- N Queen in O(n) space
- N-Queen Problem | Local Search using Hill climbing with random neighbour
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.