Guest_imported
New member
- Jan 1, 1970
- 0
I'm using IDS to find a path from a start point to a goal in a maze. The problem is that when no path exists, my algorithm keeps looping. How can I correct this?
Also the variable containing the resulting path (Move) always has a tail of the form of 'GD<number>' which shouldn't be there but keeps getting appended. The head of the list contains the correct path in the form of 'left', 'up'...etc directives.
Thanks
iterative_DF(X, Y, Move, Depth) :- depth_first(X, Y, Move, Depth), !.
iterative_DF(X, Y, Move, Depth) :- NewDep is Depth + 1, iterative_DF(X, Y, Move, NewDep).
depth_first(CX, CY, _, _) :- goal(CX, CY).
depth_first(CX, CY, [Move|T], Depth) :- Depth > 0, NextDep is Depth - 1, move(CX, CY, Move, NX, NY), depth_first(NX, NY, T, NextDep).
Also the variable containing the resulting path (Move) always has a tail of the form of 'GD<number>' which shouldn't be there but keeps getting appended. The head of the list contains the correct path in the form of 'left', 'up'...etc directives.
Thanks
iterative_DF(X, Y, Move, Depth) :- depth_first(X, Y, Move, Depth), !.
iterative_DF(X, Y, Move, Depth) :- NewDep is Depth + 1, iterative_DF(X, Y, Move, NewDep).
depth_first(CX, CY, _, _) :- goal(CX, CY).
depth_first(CX, CY, [Move|T], Depth) :- Depth > 0, NextDep is Depth - 1, move(CX, CY, Move, NX, NY), depth_first(NX, NY, T, NextDep).