Newbie in ned of help

From: Shmmeee (fletchei_at_coventry.ac.uk)
Date: 04/22/04

  • Next message: Joachim Schimpf: "Re: Simulating inheritance with a metainterpreter"
    Date: 22 Apr 2004 02:40:06 -0700
    
    

    Hello,
        I'm not going to lie to you, I have an assignment to do and it's
    causing me problems. The question I'm stuck on requires me to solve a
    word game using best first search strategy. The game is where two
    words are entered and the program produces a "chain" of words that
    link one to the other. i.e. ["big","bug","bun","fun"]

    I have been trying to get this working and have come up with a
    solution that uses a breadth first search with a bubblesort to create
    a best-first strategy. My problem is that I need to define the gt(X,Y)
    predicate for the bubblesort and although I know what I want it to do
    (return the word with the most letters the same as the goal) I don't
    know how to do it. Any guidance in the right direction would be
    greatly appreciated. I'm told there is an answer on the forum
    somewhere but I haven't been able to find it.

    TIA,
     Ean

    PROLOG CODE

    bubblesort(List,Sorted) :-
            swap(List,PartSorted),!,
            bubblesort(PartSorted,Sorted).
    bubblesort(L,L).

    swap([X,Y|Rest],[Y,X|Rest]):-
            gt(X,Y),!.
    swap([H|T],[H|Rest]):-
            swap(T,Rest).

    gt(X,Y):-
            <<THIS IS THE PART I NEED HELP WITH>>

    word_game(Start,Goal,Path) :-
            best_first([[Start]],Goal,Path).

    best_first([[Goal|Path]|_],Goal,[Goal|Path]).
    best_first([[Current|Trail]|OtherPaths],Goal,Path) :-
            findall([Next,Current|Trail],next_node(Current,Next,Trail),NewPaths),
            append(OtherPaths,NewPaths,AllPaths),
            bubblesort(AllPaths,SortAllPaths),
            best_first(SortAllPaths,Goal,Path).

    next_node(Current, Next, Trail):-
            one_off2(Current, Next, _),
            not(member(Next, Path)).

    <<FINDALL>>

    one_off(dark, park).
    one_off(dark, lark).
    one_off(dark, dart).
    one_off(dark, mark).
    one_off(park, lark).
    one_off(park, perk).
    one_off(park, part).
    one_off(perk, pert).
    one_off(perk, berk).


  • Next message: Joachim Schimpf: "Re: Simulating inheritance with a metainterpreter"