Given four integers sourceX, sourceY, destinationX and destinationY which represent the source and destination coordinates on a chessboard. The task is to find the minimum number of moves required by the king to reach from source to destination.
A king can move to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
Print path using L, R, U, D, LU, LD, RU and RD where L, R, U and D represent left, right, up and down repectively.
Input: sourceX = 4, sourceY = 4, destinationX = 3, destinationY = 5
Input: sourceX = 4, sourceY = 4, destinationX = 7, destinationY = 0
Approach: Move in the diagonal direction towards the destination until the king reaches same column or same row as the destination, then move towards the destination in a straight line.
Below is the implementation of the above approach:
4 UL UL UL L
- 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
- Number of ways to place two queens on a N*N chess-board
- Expected number of moves to reach the end of a board | Dynamic programming
- Expected number of moves to reach the end of a board | Matrix Exponentiation
- Draw a Chess Board using Graphics Programming in C
- Minimize steps defined by a string required to reach the destination from a given source
- Minimum possible modifications in the matrix to reach destination
- Minimum number of moves to reach N starting from (1, 1)
- Find minimum moves to reach target on an infinite line
- Minimum time to reach a point with +t and -t moves at time t
- Minimum moves to reach target on a infinite line | Set 2
- Minimum number of given moves required to make N divisible by 25
- Find the minimum number of preprocess moves required to make two strings equal
- Check if a king can move a valid move or not when N nights are there in a modified chessboard
- Check if any King is unsafe on the Chessboard or not
- Count positions in a chessboard that can be visited by the Queen which are not visited by the King
- Count minimum moves required to convert A to B
- Number of moves required to guess a permutation.
- Minimum broadcast range required by M towers to reach N houses
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.