lichess.org
Donate

Question regarding the Knight minimal moves pattern.

@AcabaComigo

Fair enough;

" -1/2 < y/x < 1/2" corresponds to the gradient, under which this formula works. If you look at the images generated, it is clear there are 8 distinct regions, cutting the plane into 4 pairs of identical regions. This "-1/2 < y/x < 1/2" denotes the two "pizza slices" that are going left and right, towards x = minus infinite, and x = plus infinite, respectively.

Think of the function y = 1/2 * x, which is the same as saying that if we change the value of x by two squares, then the value of y will change by one square. All of the points that satisfy this are on a line of coordinate (0, 0), (1, 2), (2, 4), (3, 6), (4, 8), etc. These squares are all squares the Knight would go on, if it was going two squares to the right, and one square up, forever. He would stay on the line defined by y = 1/2 * x.

The lines defined by y = 1/2 * x and y = -1/2 * x:

https://imgur.com/7XXMDYc

If y = 1/2 * x, then clearly y/x = 1/2. This is what I mean when I say gradient, maybe you have another word for it, but to me it means how fast a line goes up.

When I say " -1/2 < y/x < 1/2", I can rewrite this as "-1/2 * x < y < 1/2 * x.
The point is, we are looking for x and y, such that y is underneath (<) the line defined by y = 1/2 * x, but OVER (>) the line defined by y = -1/2 * x. This is the region that I highlight here in gray / blue:

https://imgur.com/sWie0KI

So this formula, ceiling(x/2) + (x+y) mod 2, only works in this region of space, and even then not for the smallest cases, when x and y are less than 4. However, it is easy to adapt this formula for the other 3 regions.

This || thing I added doesn't matter, I think. Thank you @ClaireWerk
@AcabaComigo So for example, a single knight move is 2x1 squares. The distance of a knight move is sqrt(5) because a^2+b^2=c^2 (where c is the distance of the move). In other words, 2^2+1^2=c^2 or 5^2=c^2 therefore c=sqrt(5).

Take the example of an origin square and a target square 4x2 squares apart. 4^2+2^2=c^2... so 20^2=c^2.. or c=sqrt(20). So the distance between two squares 4x2 squares apart is sqrt(20). Now divide that total distance by the length of a knight move. sqrt(20)/sqrt(5) = 2. So in this example, you can divide the distance traveled by the distance of a single knight move which is 2 moves.

Another example is a target square 6x3 squares from an origin. 6^2+3^2=c^2.. or 45^2=c^2... or c=sqrt(45). So the distance from a start square to a target 6x3 squares away is sqrt(45). The total distance divided by a single knight move sqrt(45)/sqrt(5)=3. 3 knight moves.

Of course, it's more complicated than that because knights don't always move the greatest distance from an origin each consecutive move - but I suspect with some creative modular math, there is a solution that would allow you to use the total distance between any two squares and the length of a single knight move to determine the minimum number of knight moves required for the journey.
@AcabaComigo I agree, which is why I say the number of moves it takes is of the form ceiling(x/2) + (x + y) mod 2, this is a linear function (sort of). This is why I divide x by two, because each move, the Knight goes forth 2 squares in one direction...
@AcabaComigo It's a two dimensional coordinate reference. For example, when I say 2x1 or 1x2 to describe a knight move, I am saying "move two squares by one square" or "move one square by two squares". So when I say 4x2, I am saying start at an orgin square and move four squares horizontally and then move two squares vertically. If you do that, you will notice that the final square is exactly 2 knight moves from the origin.

The additional '2's in the pythagorean equation 4^2+2^2=c^2 are exponents (i.e. a squared exponent is written ^2). Thus 4^2+2^2=c^2 is "four squared plus 2 squared equals c squared". 4^2=16. 2^2=4. 16+4=20 So c^2=20 Apply square root to each side to get rid of the squared exponent of c. Therefore c=sqrt(20) "c equals the square root of 20".

Then divide the total distance of sqrt(20) by a single knight move sqrt(5). sqrt(20)/sqrt(5)=2

This topic has been archived and can no longer be replied to.