I am trying to implement a prolog that implements the depth of the first search and the width of the first search, solves the following problem.
Rowena has three unmarked glasses of different sizes: 3 ounces, 5 ounces and 8 ounces. The largest glass is filled. What can Rowena do to get 4 ounces of liquid in each of two big glasses?
I will have (large, medium, small)
So, the initial state (8,0,0), and the state of the goal (4,4,0).
Now I know that I have 6 moves available in the state space.
(1.2) Pour Large or medium (3.4) Pour Medium into large or small (5.6) Pour a small amount to medium or large
Now I only need help with the first rule, and I'll find out the rest. Therefore, I can only pour large on Wednesday if large> 0 and the medium are not filled, and the new large becomes the old big minus of the amount that was poured on Wednesday, and the new medium becomes the old medium plus the amount that was poured into it, and, of course he has not changed.
Here is what I tried to do.
%move rule
%move(oldstate,newstate)
move([L, M, S], [NewLarge,NewMedium,S]) :-
L > 0, %We can't move large into medium if Large has nothing
M < 5, %We can't pour into the medium if medium is full
Diff = 5 - M,
NewLarge is L - Diff, %calculate the new Large
NewMedium is M + (L - NewLarge). %calculate the new Medium
Is this the correct implementation of the first available movement (Large in medium). Did I find the correct logic there?