I'm trying to solve a water, jug problem (one 7L, one 4L, get 5L in the 7L jug) using dept first search. However something keeps going wrong whenever I try to get a new state back from one of my actions. Prolog Code
I can't figure out what is going wrong, this is what the output looks like after trace: enter image description here
Thanks in advance for any help!
You should copy and paste your code into your question; we cannot copy and paste it from your images, which makes it more work to help you, which in turn makes it less likely that we will help.
Some problems I noticed anyway:
go_to_goal/3does not talk about the relation betweenClosedListandPath. You will compute the path but will never be able to communicate it to the caller. (Then again, you also ignorePathinsolve/0...) If your Prolog system gives you "singleton variable" warnings, you should never ignore them!==operator wrong. The goalState == (5, X)states that at the end you are looking for a pair where the first component is 5 (this part is fine) and the second component is an unbound variable. In fact, after your computations, the second component of the pair will be bound to some arithmetic term. This comparison will always fail. You should use the=(unification) operator instead.==is only used rarely, in particular situations.X+Y-7into the head of a rule, it will not be evaluated to a number. If you want it to be evaluated to a number, you must useis/2in the body of your rules.go_to_goal/3tries to callaction/2with a pair(0, 0)as the first argument. This always fails because the first argument of every clause ofaction/2is a termstate(X, Y). If you change this tostate(0, 0)ingo_to_goal/3, you should be able to make a little bit of progress.