This is the Solution for KNICOV problem. asked 25 Aug '17, 11:41

A knight move is defined as follows: It moves to a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. (from Wikipedia) So if you are at the square $(x, y)$, you can either move to $(x+2, y+1)$, $(x+2, y1)$, $(x2, y+1)$, $(x2, y1)$, $(x+1, y+2)$, $(x+1, y2)$, $(x1, y+2)$, $(x1, y2)$. Therefore you can extract the arrays $dx = [2, 2, 2, 2, 1, 1, 1, 1]$ and $dy = [1, 1, 1, 1, 2, 2, 2, 2]$ and iterate over them with
The order of possible moves can obviously vary. So you would end up at different Here are two game theory problems about knights: A Chessboard Game, Chessboard Game, Again! answered 25 Aug '17, 12:12
got it, Thanks mate! @afaxnraner
(25 Aug '17, 12:25)

direction array is used to go from a index to other indexes in certain directions as told in the question. The most common directions are going in 4 directions Up, Down, Left, Right, 8 directions Up, Down, Left, Right and 4 diagonal directions and knight directions(If you've played chess, you'd know how knight moves) Now, we use 2 dimensional arrays to make a grid. suppose X,Y is the coordinate of the position in the grid. So how will you move upward direction. X+= (1) and Y = 0. Add this in the direction array.
Now, how will you move downward direction? X+= 1 and Y = 0. Add this also.
Similarly after adding left and right directions, you will get,
So, now if you iterate through them and add them to X and Y one by one, you can move to all the 4 directions. Here are the direction array of 8 direction movement and knight movement:
answered 25 Aug '17, 12:13
