체스 보드에 놓여 있고 킹 캔처럼 움직일 수있는 로봇이 있다고 가정 해 봅시다.Prolog : 미로에서 길 찾기
보드의 좌표는 [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).
을하지만 실수가하고 값을 반환하지 않습니다
나는이 술어했다. 재귀가 멈추지 않는 이유를 찾을 수 없습니다.
첫 번째 줄의 의도는 무엇입니까? 그것은 항상 A와 B에 8을 할당 할 것입니다. 당신이 할당하는 대신에 비교하기를 원합니다. –