This is a homework problem, but I just need a simple question answered. I am supposed to print all the possible ways a knight can jump on a chess board from it's position. I am getting the correct numbers but I don't seem to get the correct output that I want. For example:
?- knight(8,1,R,C)
is supposed to print out the output as:
C = 3
R = 7;
C = 2
R = 6;
But I get the exact opposite as in:
R = 7,
C = 3;
R = 6,
C = 2.
here is my code:
knight(C, R, C2, R2):-
C2 is C - 1,R2 is R + 2,
withinBoard(C2,R2)
; C2 is C + 1,R2 is R + 2,
withinBoard(C2,R2)
; C2 is C + 2, R2 is R + 1,
withinBoard(C2,R2)
; C2 is C + 2, R2 is R - 1,
withinBoard(C2,R2)
; C2 is C + 1, R2 is R - 2,
withinBoard(C2,R2)
; C2 is C - 1, R2 is R - 2,
withinBoard(C2,R2)
; C2 is C - 2, R2 is R - 1,
withinBoard(C2,R2)
; C2 is C - 2, R2 is R + 1,
withinBoard(C2,R2).
withinBoard(Col,Row):-
Row < 9, Row > 0, Col < 9, Col > 0.