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:
- Check if the given chessboard is valid or not
- Check if a cell can be visited more than once in a String
- Check if any square (with one colored cell) can be divided into two equal parts
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- N Queen in O(n) space
- 8 queen problem
- Place K-knights such that they do not attack each other
- N Queen Problem | Backtracking-3
- N Queen Problem using Branch And Bound
- Printing all solutions in N-Queen Problem
- Number of cells a queen can move with obstacles on the chessborad
- Maximum bishops that can be placed on N*N chessboard
- Probability of Knight to remain in the chessboard
- Count squares with odd side length in Chessboard
- Total position where king can reach on a chessboard in exactly M moves | Set 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.