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/3
does not talk about the relation between ClosedList
and Path
. You will compute the path but will never be able to communicate it to the caller. (Then again, you also ignore Path
in solve/0
...) If your Prolog system gives you "singleton variable" warnings, you should never ignore them!==
operator wrong. The goal State == (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-7
into 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 use is/2
in the body of your rules.go_to_goal/3
tries to call action/2
with a pair (0, 0)
as the first argument. This always fails because the first argument of every clause of action/2
is a term state(X, Y)
. If you change this to state(0, 0)
in go_to_goal/3
, you should be able to make a little bit of progress.