To me the easy human way it is to start from the square that you want to go to (backtracking approach), lets call it 'A' and exclude from the path calculation the direct linked paths from 'A' that you can't go to because they are attack or there is a piece on it.
For example, you want to go to the square c4, so the directed linked paths will be from by a5
, a3
, b2
, d2
, e3
, e5
, d6
and b6
, but if only the square a5
and b6
are available you can reduce your calculation to only to 2 paths now. Furthermore, if you use this "technique" you can check if the target square is reachable at all (if have at least 1 directed linked path not being occupied or attacked).
After doing that, you go to the position where you knight stands and you check which are the squares that you can go to. Using this two phase approach you reduce you tree of calculation immensely.
You should also know beforehand how many moves you need to go from one square to another with your knight, in order to avoid the calculation of larger paths than the ones really need it. I din't check online to find any heuristic for this but I can give you some inside tips about it:
- The Knight on a black square can only go to a white square and vise-versa, in the next move;
- Every square on the diagonal of the actual square of the Knight can be reach in only two moves. Square
(x,y)
to the squares(x-1,y+1)
,(x+1,y+1)
,(x+1,y-1)
and(x-1,y-1)
takes 2 moves; - The squares up, above, right and left of the actual square takes 3 moves;
- Every square on the diagonal of the actual square with a one square between them (e.g actual square = c4, target square a6), takes 4 moves.
- Every square on the diagonal of the actual square with a 2 squares between them (e.g actual square = c4, target square f7), takes only 2 moves.
Finally, if you are in a given color square you will take a odd number of moves to reach the opposite color square. If the target square have the same color as the square that you are in now it will take a even number of moves.