i tried to write a prolog code for Depth First Search (DFS). Program has given a certain state space on input, which is rated tree and i need to realize browsing of this state space with DFS method.
My code is:
dfs(state(NAME,TRANSITIONS)) :- write(NAME), write('\n'), expand(TRANSITIONS).
expand([]).
expand([H]) :- dfs(H).
expand([H|T]) :- dfs(H), expand(T).
And my defination for goal is:
dfs(state('A',[state('AA',[state('AAA',[])]),state('AB',[])])).
Answer of prolog is:
A
AA
AAA
AB
true.
I dont know how to define certain space. Do you have any advice ?
Thank you and ha ve a nice day Vinnie
My code is:
dfs(state(NAME,TRANSITIONS)) :- write(NAME), write('\n'), expand(TRANSITIONS).
expand([]).
expand([H]) :- dfs(H).
expand([H|T]) :- dfs(H), expand(T).
And my defination for goal is:
dfs(state('A',[state('AA',[state('AAA',[])]),state('AB',[])])).
Answer of prolog is:
A
AA
AAA
AB
true.
I dont know how to define certain space. Do you have any advice ?
Thank you and ha ve a nice day Vinnie