I'm working on the "monkey and bananas" problem but with 2 boxes instead of one. I tried adapting the code from 1 box to 2 boxes, but I have this problem.
I need to keep a list of "visited states" since the tree grows too big and my program crashes. In this list are all the visited states from start to the actual state, so if I'm going to go to an already visited state, the clause fails and backtrack occurs.
The problem is sometimes this happens:
Call: (8) lists:member(estado(_G3634, p0, ventana, centro, noapiladas, notiene), [estado(_G3619, p0, ventana, centro, noapiladas, notiene)]) ? creep
Exit: (8) lists:member(estado(_G3619, p0, ventana, centro, noapiladas, notiene), [estado(_G3619, p0, ventana, centro, noapiladas, notiene)]) ? creep
I need to check all possible positions (for instance: door (puerta), window (ventana) and middle (centro)) when trying to find all possible states, but since the variables are not instantiated, apparently they unify and member(State, List) returns true so the program backtracks and I never check all possible states.
I tried checking membership with \== but other problem happens: since the states (with uninstantiated variables) are always different (state(_G1234) is different from state(_2345)) I enter in an infinite loop and never ends since it's checking a lot of states with uninstantiated (but different) variables.
How could I solve this? Or should I try another approximation? I thought about defining a preset of "positions" but I'm not sure how to check all the different positions when executing the rules.
The rules are like this:
mover(estado(P, p0, P1, P2, A, E),
desplazar(P, PD),
estado(PD, p0, P1, P2, A, E)).
Where estado(P, p0, P1, P2, A, E) represents:
- Position of the monkey (X-Axis).
- Position of the monkey (Y-Axis).
- Position of the 1st box.
- Position of the 2nd box.
- If the boxes are stacked or not.
- If the monkey has the banana or not.
I should try to check all posible PD (Destiny position of the monkey) but I'm not sure how to do it.
Thanks in advance.