I'm trying to resolve chess knight problem for custom matrix but I don't know where is problem. A chess knight must visit each place once, and when he manages to visit all fields then finish the program. Currently, he is looking for the correct combination of fields all the time and it takes a very long time ... I have no idea what to do next or what to change
append([], POINT, [POINT]).
append([H|T], POINT, [H|R]) :-
append(T, POINT, R).
member(POINT,[POINT|_]).
member(POINT,[_|R]) :-
member(POINT, R).
try(X, Y, Xmax, Ymax, A, B) :-
(X + 1 < Xmax, Y + 2 < Ymax, A is X + 1, B is Y + 2).
try(X, Y, Xmax, Ymax, A, B) :-
(X + 2 < Xmax, Y + 1 < Ymax, A is X + 2, B is Y + 1).
try(X, Y, Xmax, Ymax, A, B) :-
(X + 2 < Xmax, Y - 1 >= Ymax - Ymax, A is X + 2, B is Y - 1).
try(X, Y, Xmax, Ymax, A, B) :-
(X + 1 < Xmax, Y - 2 >= Ymax - Ymax, A is X + 1, B is Y - 2).
try(X, Y, Xmax, Ymax, A, B) :-
(X - 1 >= Xmax - Xmax, Y - 2 >= Ymax - Ymax, A is X - 1, B is Y - 2).
try(X, Y, Xmax, Ymax, A, B) :-
(X - 2 >= Xmax - Xmax, Y - 1 >= Ymax- Ymax, A is X - 2, B is Y - 1).
try(X, Y, Xmax, Ymax, A, B) :-
(X - 2 >= Xmax - Xmax, Y + 1 < Ymax, A is X - 2, B is Y + 1).
try(X, Y, Xmax, Ymax, A, B) :-
(X - 1 >= Xmax - Xmax, Y + 2 < Ymax, A is X - 1, B is Y + 2).
move(X, Y, Xmax, Ymax, L) :-
not(member([X, Y], L)),
write('X='), write(X),
write('Y='), write(Y), nl,
try(X, Y, Xmax, Ymax, A, B),
append(L, [X, Y], L2),
move(A, B, Xmax, Ymax, L2).
Example:move(0, 0, 3, 3, []).
Output
X=0Y=0
X=1Y=2
X=2Y=0
X=0Y=1
X=2Y=2
X=1Y=0
X=0Y=2
X=2Y=1
X=2Y=1
X=0Y=2
X=1Y=0
X=2Y=2
X=0Y=1
X=2Y=0
X=1Y=2
false
That's true, because it will never be in the center of the matrix. But for matrix 5x5 he can't find combination...