내 이해에서, 분리형 일반 형식 (예 : (A && B) || (C && D) --> pred
)의 술어가있는 경우 다음을 수행 할 수 있습니다.술어가 실패 할 때 예외를 throw하는 프롤로그
pred(parameters) :-
A, B;
C, D.
이 정보가 맞습니까? 그렇다면 다음 코드를 살펴보십시오.
나는 ... 나는 trace.
를 사용
maze(X, Y, Maze, Path, Score) :-
find_eggs_and_pika(X, Y, Maze, Path, Score, 0, 0, 0, Masterball_found),
write(Score).
find_eggs_and_pika(X, Y, Maze, Path, Score, PrevDirection, Has_egg, Egg_steps, Masterball_found) :-
is_masterball(X, Y, Maze, Masterball_found);
...more predicates
is_masterball(X, Y, Maze, Masterball_found) :-
nth1(Y, Maze, Row),
nth1(X, Row, mb),
Masterball_found is 1,
false.
나는 다음과 같은 다음과 같은 세 가지 조건 얻을 수있다 :
{trace}
| ?- maze(1,1,[[ o, e, j, p, o], [ o, j, o, o, o], [ o, j, mt, j, o], [ o, o, e, o, o],[ p, o, j, mb, o]], Path, 0).
1 1 Call: maze(1,1,[[o,e,j,p,o],[o,j,o,o,o],[o,j,mt,j,o],[o,o,e,o,...],[p,o,j,...]],_339,0) ?
2 2 Call: find_eggs_and_pika(1,1,[[o,e,j,p,o],[o,j,o,o,o],[o,j,mt,j,o],[o,o,e,o,...],[p,o,j,...]],_339,0,0,0,0,_373) ?
3 3 Call: is_masterball(1,1,[[o,e,j,p,o],[o,j,o,o,o],[o,j,mt,j,o],[o,o,e,o,...],[p,o,j,...]],_373) ?
4 4 Call: nth1(1,[[o,e,j,p,o],[o,j,o,o,o],[o,j,mt,j,o],[o,o,e,o,...],[p,o,j,...]],_470) ?
4 4 Exit: nth1(1,[[o,e,j,p,o],[o,j,o,o,o],[o,j,mt,j,o],[o,o,e,o,...],[p,o,j,...]],[o,e,j,p,o]) ?
5 4 Call: nth1(1,[o,e,j,p,o],mb) ?
5 4 Fail: nth1(1,[o,e,j,p,o],mb) ?
3 3 Fail: is_masterball(1,1,[[o,e,j,p,o],[o,j,o,o,o],[o,j,mt,j,o],[o,o,e,o,...],[p,o,j,...]],_373) ?
3 3 Call: '$call'(0,find_eggs_and_pika,9,true) ?
3 3 Exception: '$call'(0,find_eggs_and_pika,9,true) ?
2 2 Exception: find_eggs_and_pika(1,1,[[o,e,j,p,o],[o,j,o,o,o],[o,j,mt,j,o],[o,o,e,o,...],[p,o,j,...]],_339,0,0,0,0,_373) ?
is_masterball()
가 실패하지만이처럼 (이것은이 예에서해야한다 등) 프롤로그가 find_eggs_and_pika()
에 다시 전화를 걸려고합니까? ...more predicates
부분으로 이동하는 대신.
문제점을 발견했습니다. 'is_masterball()'이후의 술어는 예외를 던지고있다. 감사. –