チェス盤上にあり、キングのように動くロボットがあるとします。
ボードの座標は [1,1] から [8,8] です。
開始位置は [1,1] で、最終位置は [8,8] です。[[1,4]、[2,5]、[5,6]] などの障害物の座標のリストを含むリスト X があります。問題は、ロボットが開始位置から最終位置まで移動できる方法があるかどうかです。
私はこの述語を作りました:
path([A,B],_):- A is 8, B is 8.
path([A,B],X):-
possibleMoves(A,B,L), % possibleMoves returns a list of all the possible coords that
the robot can go to. (Example for [1,1] are [[0,1],[0,0],[2,1]...])
member([Ex,Ey],L), % member generates all the possible members from the list L
not(member([Ex,Ey],X)), % if this member is not member of the "forbidden ones"
Ex<9,Ex>0,Ey<9,Ey>0, % and its coords are on the board
path([Ex,Ey],X).
isTherePath(X):- possibleMoves(1,1,L),
member(E,L),
path(E,X).
しかし、間違いがあり、値を返しません。再帰が止まらない理由がわかりません。