I'm very new to Prolog and I'm trying to write a simple method to determine if a knight on a chessboard can jump to another square, or output all of the squares that a knight could jump to given a square. For this method, assume the first argument must always be instantiated. It works correctly, given both parameters, but I am not sure why it will not output only given one.
% validSquare/2
% validSquare(X1/Y1, X2/Y2) iff the coordinate is a valid position on an 8x8 chessboard.
validSquare(X1/Y1, X2/Y2) :-
X1 >= 1, X1 =< 8,
Y1 >= 1, Y1 =< 8,
X2 >= 1, X2 =< 8,
Y2 >= 1, Y2 =< 8.
% jump/2
% jump(Square1, Square2) iff a knight could jump to the coordinate
% Square1/Square2 on a chessboard.
jump(X1/Y1, X2/Y2) :-
validSquare(X1/Y1, X2/Y2),
X2 is X1 + 1,
Y2 is Y1 + 2.
jump(X1/Y1, X2/Y2) :-
validSquare(X1/Y1, X2/Y2),
X2 is X1 + 2,
Y2 is Y1 + 1.
jump(X1/Y1, X2/Y2) :-
validSquare(X1/Y1, X2/Y2),
X2 is X1 + 1,
Y2 is Y1 - 2.
jump(X1/Y1, X2/Y2) :-
validSquare(X1/Y1, X2/Y2),
X2 is X1 + 2,
Y2 is Y1 - 1.
jump(X1/Y1, X2/Y2) :-
validSquare(X1/Y1, X2/Y2),
X2 is X1 - 1,
Y2 is Y1 - 2.
jump(X1/Y1, X2/Y2) :-
validSquare(X1/Y1, X2/Y2),
X2 is X1 - 2,
Y2 is Y1 - 1.
jump(X1/Y1, X2/Y2) :-
validSquare(X1/Y1, X2/Y2),
X2 is X1 - 1,
Y2 is Y1 + 2.
jump(X1/Y1, X2/Y2) :-
validSquare(X1/Y1, X2/Y2),
X2 is X1 - 2,
Y2 is Y1 + 1.
Like I said, I'm very new to Prolog, so I'm not really sure how I should format the query. This query is false.
?- jump(1/1, X2/Y2).
ERROR: >=/2: Arguments are not sufficiently instantiated
Thanks for any help.