I need a program in Swi Prolog which will execute the algorithm of search in depth and in breadth for making a search of a path where an agent will follow in a frame NxN. The agent can go up, down, right , left inside the limits of the frame.
The program must execute two basic predicates (commands)
depthfirst(CurrentPos, FinalPos, Visited, Path)
breadthfirst(CurrentPos, FinalPos, Visited, Path)
for the two searches and what else is needed.
[url removed, login to view] the search of the path from the cell [2,3] to [4,4] with depthfirst will write: depthfirst(p(2,3), p(4,4),,Path) and Prolog must return the result through the path. The Visited is initially null and gradually contains the positions already visited by our agent. Used to avoid places already visited.
To analyze the function of two predicates, using an example moving from point 2,3 to 4,4 in a frame of 5x5.
In deptfirst search is needed:
move from pos(X,Y) to pos(X+1,Y)
size(5) for N=5
move(pos(X,Y),pos(X1,Y1)):-size(N),X1 is .......
For the breadth:
memory retention by using assert and retract
state(pos(X,Y)),[...path from the beginning to X,Y])and the frontier will have states with the order in which will returned.
The program should be with comments.
Thanks in advanced.