I am trying to formulate a successor state axiom for an agent that moves (north,south,west,east) in a 4x4 grid. The grid has two obstacles at 1,1 and 2,2 and the initial position of the agent is 3,3. The agent should reach the the teleportal which is in position 1,2 without hitting any obstacles. Here is the code:
obstacle(1,1).
obstacle(2,3).
teleportal(1,3).
agent(3,3,s0).
agent(X, Y, result(A,S)):-
( agent(X,Y,S),
( A = north, (X=0; (obstacle(X2,Y), X2 is X-1)))
;
(A = south, (X=3; (obstacle(X2,Y), X2 is X+1)));
(A = west, (Y=0; (obstacle(X,Y2), Y2 is Y-1)));
(A = east, (Y=3; (obstacle(X,Y2), Y2 is Y+1))))
;
(agent(X2, Y, S), A = north, X > 0, X2 is X-1);
(agent(X2, Y, S), A = south, X < 3, X2 is X+1);
(agent(X, Y2, S), A = west, Y > 0, Y2 is Y-1);
(agent(X, Y2, S), A = east, Y < 3, Y2 is Y+1).
escaped(S):- agent(X,Y,S), teleportal(X,Y).
When I run escape(S), it gives the following error: Out of local stack