location(T1,R,C) :-
T0 is T1 - 1,
RN is R - 1,
RS is R + 1,
CW is C - 1,
CE is C + 1,
(
((action(T0,eat);action(T0,clockWise);action(T0,counterClockWise)), location(T0,R,C));
((action(T0,attack);action(T0,forward)), bump(T1), location(T0,R,C));
((action(T0,attack);action(T0,forward)), dir(T0,north), not(bump(T1)), location(T0,RS,C));
((action(T0,attack);action(T0,forward)), dir(T0,south), not(bump(T1)), location(T0,RN,C));
((action(T0,attack);action(T0,forward)), dir(T0,west), not(bump(T1)), location(T0,R,CE));
((action(T0,attack);action(T0,forward)), dir(T0,east), not(bump(T1)), location(T0,R,CW))
).
peek_location( [T0, R, C], [R_n, C_n]) :-
RN is R - 1,
RS is R + 1,
CW is C - 1,
CE is C + 1,
(
((action(T0,eat);action(T0,clockWise);action(T0,counterClockWise)), R_n is R, C_n is C);
((action(T0,attack);action(T0,forward)), dir(T0,north), R_n is RS, C_n is C);
((action(T0,attack);action(T0,forward)), dir(T0,south), R_n is RN, C_n is C);
((action(T0,attack);action(T0,forward)), dir(T0,west), R_n is R, C_n is CE);
((action(T0,attack);action(T0,forward)), dir(T0,east), R_n is R, C_n is CW)
).
dir(T1,north) :-
T0 is T1 - 1,
(
((action(T0,eat);action(T0,attack);action(T0,forward)), dir(T0,north) );
(action(T0,clockWise) , dir(T0,west));
(action(T0,counterClockWise), dir(T0,east))
).
dir(T1,east) :-
T0 is T1 - 1,
(
((action(T0,eat);action(T0,attack);action(T0,forward)), dir(T0,east));
(action(T0,clockWise) , dir(T0,north));
(action(T0,counterClockWise), dir(T0,south))
).
dir(T1,south) :-
T0 is T1 - 1,
(
((action(T0,eat);action(T0,attack);action(T0,forward)), dir(T0,south));
(action(T0,clockWise) , dir(T0,east));
(action(T0,counterClockWise), dir(T0,west))
).
dir(T1,west) :-
T0 is T1 - 1,
(
((action(T0,eat);action(T0,attack);action(T0,forward)), dir(T0,west) );
(action(T0,clockWise) , dir(T0,south));
(action(T0,counterClockWise), dir(T0,north))
).
findWhenBumped(BumpedTimeList) :- findall(T_prime ,(bump(T), T_prime is T -1),BumpedTimeList).
test(X,List):- findall(X,X,List).
/* Wall variables related */
isWall(T,R,C):-
isWall(R,C).
isWall(X,Y):- % change in Q1
(X =:= 0;
Y =:= 0);
(
findWhenBumped(BumpedTimeList),
findall( [T, R, C], ( location(T, R, C), member(T, BumpedTimeList) ), BumpedPosList),
maplist(peek_location, BumpedPosList, WallPosList ),
member([X,Y],WallPosList)
).
isClear(T,R,C) :- % change in Q1
hasNotEnemy(T,R,C),
hasNotPit(T,R,C),
not(isWall(R,C)).
bump(-1).
hasNotEnemy(T,X,Y). % change in Q2
hasNotPit(-1,X,Y). % change in Q2
hasPit(-1,X,Y). % change in Q3
hasEnemy(-1,X,Y). % change in Q3
hasDeadEnemy(-1,X,Y). % change in Q3
hasFood(-1,X,Y). % change in Q4
hasNotFood(T,X,Y). % change in Q4
isWall(-1,-1).
isWall(-1,-1,-1).
location(1,1,1).
dir(1,east).
下面的行失败,
findall( [T, R, C], ( location(T, R, C), member(T, BumpedTimeList) ), BumpedPosList)
我想要做的是找到bump()为真的时间实例,并找到该时间实例的相应位置()。当我删除顶部的位置定义并且只有事实时,它可以工作。我对 Prolog 完全陌生,所以请尽可能具体。
提前谢谢大家。