Prolog crossword 
Author Message
 Prolog crossword

Hello!

I need to implement a program that creates crosswords. I think I have
to have a huge database of words, otherwise it will be very difficult
to create a crossword.

Now I have a database of words, their length is 5 chars. They're
represented as lists, let's say:

word(w1,[m,o,u,s,e]).
word(w2,[o,p,e,r,a]).

and so on.

First I would like to do 5x5 crossword - 5 words horizontal, 5 words
vertical. My idea was to make a big list (in this case with 25 elements).
Then I would put in the first word and fill the words in - one
vertically, one horizontally (don't know how, yet). I think this way it
would be easy to write the crossword on screen when it would be solved.

Could I do this like that?
The indexes:

| 1| 2| 3| 4| 5|  
| 6| 7| 8| 9|10|  
|11|12|13|14|15|  
|16|17|18|19|20|  
|21|22|23|24|25|  

The crossword:

|m|o|u|s|e|
| |p| | | |
| |e| | | |
| |r| | | |
| |a| | | |

The empty fields would be represented by _.

So the whole list in this case would be:
[m,o,u,s,e,_,p,_,_,_,_,e,_,_,_,_,r,_,_,_,_,a,_,_,_].

Would this be difficult to implement? Am I even thinking in the
right direction? If not, can you give me some hints?

Thanks in advance!

Trin

P.S.: How long does it take to learn prolog? I think this is
way over my head..



Tue, 21 Jun 2005 21:28:41 GMT  
 Prolog crossword


Quote:
>I need to implement a program that creates crosswords. I think I have
>to have a huge database of words, otherwise it will be very difficult
>to create a crossword.

>Now I have a database of words, their length is 5 chars. They're
>represented as lists, let's say:

>word(w1,[m,o,u,s,e]).
>word(w2,[o,p,e,r,a]).

>and so on.

Good idea.

You can download an English wordlist, e.g. from
http://www.resco-net.com/wordgame_faq.asp.  It should be easy enough to
convert it to Prolog, in the format you suggest.  Or you could omit the
w1 w2 etc., as they aren't really any use, and just store
  word( [m,o,u,s,e] ).
  word( [o,p,e,r,a] ).
Or you might prefer, for efficiency, to store the lengths:
  word( 5, [m,o,u,s,e] ).
  word( 5, [o,p,e,r,a] ).
  word( 3, [c,a,t] ).

Quote:
>First I would like to do 5x5 crossword - 5 words horizontal, 5 words
>vertical. My idea was to make a big list (in this case with 25 elements).
>Then I would put in the first word and fill the words in - one
>vertically, one horizontally (don't know how, yet). I think this way it
>would be easy to write the crossword on screen when it would be solved.

>Could I do this like that?
>The indexes:

>| 1| 2| 3| 4| 5|
>| 6| 7| 8| 9|10|
>|11|12|13|14|15|
>|16|17|18|19|20|
>|21|22|23|24|25|

The Prolog for this could be very simple.  It could look like this:
   word( 5, [L1,L2,L3,L4,L5] ),
   word( 5, [L6,L7,L8,L9,L10] ),
   word( 5, [L11,L12,L13,L14,L15] ),
   word( 5, [L16,L17,L18,L19,L20] ),
   word( 5, [L21,L22,L23,L24,L25] ),
   word( 5, [L1,L6,L11,L16,L21] ),
   word( 5, [L2,L7,L12,L17,L22] ),
   word( 5, [L3,L8,L13,L18,L23] ),
   word( 5, [L4,L9,L14,L19,L24] ),
   word( 5, [L5,L10,L15,L20,L25] ).

Note that this uses 25 variables.

However it would take ages to run.  You could speed it up by shuffling
the order of the lines:

   word( 5, [L1,L2,L3,L4,L5] ),
   word( 5, [L1,L6,L11,L16,L21] ),
   word( 5, [L6,L7,L8,L9,L10] ),
   word( 5, [L2,L7,L12,L17,L22] ),
   word( 5, [L11,L12,L13,L14,L15] ),
   word( 5, [L3,L8,L13,L18,L23] ),
   word( 5, [L16,L17,L18,L19,L20] ),
   word( 5, [L4,L9,L14,L19,L24] ),
   word( 5, [L21,L22,L23,L24,L25] ),
   word( 5, [L5,L10,L15,L20,L25] ).

Nick
--



Tue, 21 Jun 2005 21:59:15 GMT  
 Prolog crossword

Quote:

> The Prolog for this could be very simple.  It could look like this:
>    word( 5, [L1,L2,L3,L4,L5] ),
>    word( 5, [L6,L7,L8,L9,L10] ),
>    word( 5, [L11,L12,L13,L14,L15] ),
>    word( 5, [L16,L17,L18,L19,L20] ),
>    word( 5, [L21,L22,L23,L24,L25] ),
>    word( 5, [L1,L6,L11,L16,L21] ),
>    word( 5, [L2,L7,L12,L17,L22] ),
>    word( 5, [L3,L8,L13,L18,L23] ),
>    word( 5, [L4,L9,L14,L19,L24] ),
>    word( 5, [L5,L10,L15,L20,L25] ).

> Note that this uses 25 variables.

> However it would take ages to run.  You could speed it up by shuffling
> the order of the lines:

>    word( 5, [L1,L2,L3,L4,L5] ),
>    word( 5, [L1,L6,L11,L16,L21] ),
>    word( 5, [L6,L7,L8,L9,L10] ),
>    word( 5, [L2,L7,L12,L17,L22] ),
>    word( 5, [L11,L12,L13,L14,L15] ),
>    word( 5, [L3,L8,L13,L18,L23] ),
>    word( 5, [L16,L17,L18,L19,L20] ),
>    word( 5, [L4,L9,L14,L19,L24] ),
>    word( 5, [L21,L22,L23,L24,L25] ),
>    word( 5, [L5,L10,L15,L20,L25] ).

> Nick

Thanks Nick!

Now can I switch from thist to the crossword that wouldn't only work
for 5x5? And that would have black spots in it?

Something like:

|o|p|e|r|a|#|
|r|o|c|k|e|t|
|a|_|_|_|_|o|
|n|e|w|#|a|t|
|g|_|_|_|_|o|
|e|_|_|_|_|#|

Where # means that the word is ended and that there cannot be
any letter, and _ means, that there has to be a letter.

I don't know yet how, but the program should assign those black
fields at the beginning and then try to solve the crossword with
those empty places in it.
If it fails, it has to backtrace and find another solution.

Any ideas would be very appreciated..

Thanks, Trin



Wed, 22 Jun 2005 16:27:53 GMT  
 Prolog crossword

Quote:

> Now can I switch from thist to the crossword that wouldn't only work
> for 5x5? And that would have black spots in it?

> Something like:

> |o|p|e|r|a|#|
> |r|o|c|k|e|t|
> |a|_|_|_|_|o|
> |n|e|w|#|a|t|
> |g|_|_|_|_|o|
> |e|_|_|_|_|#|

[...]

Quote:
> Any ideas would be very appreciated..

One thing you may want to take note of is that crosswords are supposed
to be symmetrical.  For this you need to unify the black-spaceness
("#") of the grids, but not the letters.

One approach might be to start with an initial template, something
like:

 [
     [G0,G1,G2,...         ],
     [...               ...],
     [G50,G51, ... ,G51,G50],
     [...               ...],
     [         ...,G2,G1,G0]
 ]

Bind each of the symbols to '#' or ' ', constraining runs of
whitespace to reasonable word-lengths (3 to 7, with the occasional
long word)

Then copy, replacing each ' ' with a fresh variable.

Quote:
> Thanks, Trin

--
Tom Breton at panix.com, username tehom.  http://www.panix.com/~tehom


Thu, 23 Jun 2005 03:06:54 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Crosswords for Linux Backtracking recursive crossword generator

2. Crossword Puzzle generator to postscript

3. Crosswords for python

4. crossword puzzle

5. Crossword generator

6. Crosswords for Linux ( python section)

7. crossword

8. Crosswords for python

9. Do You Have Tips for a crosswords implementation?

10. PDC prolog and prolog++ (object-prolog)

11. Prolog Comparison Charts; Prolog Embeddings

12. SWI Prolog Vs GNU Prolog

 

 
Powered by phpBB® Forum Software