Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Problem with a crosswords generator
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).



Report this thread to moderator Post Follow-up to this message
Old Post
Spoofix
10-14-04 08:58 PM


Re: Problem with a crosswords generator
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).
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
David Vago
10-15-04 01:56 AM


Re: Problem with a crosswords generator
"David Vago" <vd419ll@freemail.hu> a écrit dans le message de
news:ckmoog$5sf$1@namru.matavnet.hu...
> 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.

OK, thank you very much for these explanations... I was suspecting the
"X\==0" but I couldn't be sure... I just a beginner !

> 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).

Thank you ! It works fine !!!!

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

I can say the same with my english ! And your french is quite good !

Thank you.
Spoofix.



Report this thread to moderator Post Follow-up to this message
Old Post
Spoofix
10-15-04 01:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:00 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.