Lonely knight
Posted by aleksin
You are given a standard chessboard consisting of 64 squares (eight rows and eight columns) arranged in two alternating colors. There are no pieces on the board except for one knight. The knight moves according to standard chess rules.
It can move two squares horizontally and one square vertically, or two squares vertically and one square horizontally. The completed move therefore looks like the letter 'L'. The green dots on the image represent all eight possible moves.
The task is to write a function based on the input of the beginning and end positions, and will return a minimum number of moves required for the knight to reach the end, indicated by a checkmark on the chessboard:
int FindPath(int x, int y, int x1, int y1)
It can move two squares horizontally and one square vertically, or two squares vertically and one square horizontally. The completed move therefore looks like the letter 'L'. The green dots on the image represent all eight possible moves.
The task is to write a function based on the input of the beginning and end positions, and will return a minimum number of moves required for the knight to reach the end, indicated by a checkmark on the chessboard:
int FindPath(int x, int y, int x1, int y1)

Answers