View Full Version : Prolog - depth first search
Praetorian
04-15-2007, 09:21 AM
Ok Im rather stuck as I cant find many examples similar too this (and prolog isnt my strong point). Basically I need to find out the value of a state. If it is the goal then the value is 0, if the goal can be reached in 1 move then the value if 1 (all possible moves from a current state can be found using nextstate([1,1,1,1],X) etc.) If the value of the next state is 0 then the value of the current state is 1 and vice versa. How do I start doing this?
Reedbeta
04-15-2007, 09:28 AM
Try a predicate that looks something like: (not in prolog syntax)
parity(S1) is
0 if S1 is goal OR nextstate(S1, S2) and parity(S2) = 1,
1 if nextstate(S1, S2) and parity(S2) = 0.
This might cause problems if there are multiple paths from the states to the goal, where some are even length and others are odd length. In that case the parity's not uniquely definable.
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.