0
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).

Line below fails,

findall( [T, R, C], ( location(T, R, C), member(T, BumpedTimeList) ), BumpedPosList)

What I want to do is to find time instances where bump() is true and find the corresponding location() for that time instance. When I delete the location definition at top and only have the facts, it works. I am completely new to Prolog so please be as specific as you can.

Thanks all in advance.

false
  • 10,182
  • 12
  • 93
  • 182
omerfirmak
  • 163
  • 1
  • 9
  • You can find out *where* the error is occurring, using trace. But generally, your code is *very* error prone, since the logic is repeated everywhere. You should really try to code DRY, keep the specification as short as you can. – CapelliC Apr 08 '18 at 10:27
  • *I am completely new to Prolog so please be as specific as you can.* I'd ask you do the same. Please provide the exact error message. It should tell you what predicate is complaining and might give a line number as well. – lurker Apr 08 '18 at 14:46
  • 1
    Possible duplicate of [Prolog - Arguments are not sufficiently instantiated](https://stackoverflow.com/questions/23815952/prolog-arguments-are-not-sufficiently-instantiated) – Isabelle Newbie Apr 08 '18 at 18:55
  • 2
    As with your last question, the problem has nothing to do with `findall/3`. Even this query fails with the same error: `?- location(T, R, C). ERROR: location/3: Arguments are not sufficiently instantiated`. The right-hand-side argument of `is/2` may not contain unbound variables. – Isabelle Newbie Apr 08 '18 at 18:57

0 Answers0