Re: Problem with a crosswords generator

From: David Vago (vd419ll_at_freemail.hu)
Date: 10/14/04

  • Next message: Michael D. Kersey: "Re: implementation"
    Date: Thu, 14 Oct 2004 22:49:14 +0200
    
    

    Hi!

    The reason you get multiple black squares is that when the
    variable X is not instantiated, the X \== 0 expression will be
    true, but that does not mean, that when X becomes instantiated,
    it cannot take the value 0.
    That is why genereMC/1 generates invalid crossword puzzles, however
    when all variables are instantiated at the beginning (calling the predicate
    with the [0,0,0,97,98,99,0,0,0] argument), it will correctly recognize
    that is is an invalid puzzle.

    Here is how I would generate (and test) the validity of lines of puzzle

    % La ligne commence avec un carre noir
    verifLigne([0|L]) :- verifLigne2(L).

    % La ligne ne commence pas avec un carre noir
    verifLigne(L) :- verifLigne2(L).

    % Cas #1) Fin de la ligne.
    verifLigne2([]) :- !.

    % Cas #2) Tout le reste est un mot.
    verifLigne2(L) :- mot(L).

    % Cas #3) Il y a un mot, suivant par un carre noir, est des autres mots.
    verifLigne2(L) :- append(M, [0|L2], L), mot(M), verifLigne2(L2).

    Sorry for my French, I haven't used it for a long time.

    Dave

    The
    "Spoofix" <xxx@xxx.xxx.invalid> wrote in message
    news:416ebd92$0$27928$626a14ce@news.free.fr...
    > Hi everybody,
    >
    > I have a problem with my prolog program, which is a crosswords generator :
    > When I call :
    > ?- consult('code.txt').
    > ?- genereMC(L).
    >
    > It finds : L = [0, 0, 0, 97, 98, 99, 0, 0, 0]
    >
    > which corresponds to
    > ???
    > abc
    > ???
    > (0 are "black cases")
    > whereas this solution is false because I only want to have isolated black
    > cases.
    >
    > The most surprising is that
    > ?- genereMC([0, 0, 0, 97, 98, 99, 0, 0, 0]).
    > answers NO !!!
    >
    > Where is my mistake ? (I use SWI-Prolog)
    >
    > I give you my code (NB : I'm french) :
    > 'liste_francais_3.txt' contains a list of words like that :
    > mot("abc").
    > mot("adn").
    > mot("afp").
    > mot("age").
    > mot("age").
    > mot("agi").
    > mot("ah").
    > etc....
    >
    > ----------------------------------------------------------------------------
    > ------------------
    >
    > /* Charge la liste de mots */
    >
    > ?-consult('liste_francais_3.txt').
    >
    >
    > /*--------------------------------------------------------------------------
    > ----*/
    > /*---------------------------
    > verifLigne ---------------------------------------*/
    > /*--------------------------------------------------------------------------
    > ----*/
    >
    > /* Cas de l'appel de la fonction (2e parametre par défaut = []) */
    > verifLigne(L) :- verifLigne(L, []).
    >
    > /* Quand on arrive au bout de la ligne */
    > verifLigne([], []).
    > verifLigne([], MotCourant) :- mot(MotCourant).
    >
    > /* Quand on rencontre "un carré noir" */
    > verifLigne([0], []).
    > verifLigne([0], MotCourant) :- mot(MotCourant).
    > verifLigne([0|[X|R]], []) :- X\==0, verifLigne([X|R], []).
    > verifLigne([0|[X|R]], MotCourant) :- X\==0, mot(MotCourant),
    > verifLigne([X|R], []).
    >
    > /* Cas général */
    > verifLigne([X|R], MotCourant) :- X\==0, append(MotCourant, [X],
    > NewMotCourant), verifLigne(R, NewMotCourant).
    >
    >
    > /*pasDeLettresIsolees(MC).*/
    >
    >
    > verifMotCroise([A,B,C,D,E,F,G,H,I]) :- verifLigne([A,B,C]),
    > verifLigne([D,E,F]), verifLigne([G,H,I]),
    >
    > verifLigne([A,D,G]), verifLigne([B,E,H]), verifLigne([C,F,I]).
    >
    > affich([A,B,C,D,E,F,G,H,I]) :- name(L1, [A,B,C]), name(L2, [D,E,F]),
    > name(L3, [G,H,I]), write(L1), nl, write(L2),
    >
    > nl, write(L3), nl.
    >
    > genereMC(L) :- verifMotCroise(L), affich(L).
    >
    >


  • Next message: Michael D. Kersey: "Re: implementation"