karasek / CrossWord

Simple crossword generator
MIT License
26 stars 9 forks source link

Generate method does not return when a solution is not possilble #3

Closed tommercutio closed 8 years ago

tommercutio commented 8 years ago

The CrossGenerator.Generate method runs into an infinite loop when it is called without a puzzle, and if a solution is not possible. The method never returns.

karasek commented 8 years ago

The search space is enormous and for decent dictionary size you just can't wait long enough to check all possibilities. If you use small dictionary you will see that the Generate method ends :-)

tommercutio commented 8 years ago

Thank you!

I tested this and it does return you're right :) My observation is that the likelihood of generation of a result is the same for each iteration in the while loop in the Generate method. But I'm not sure.

Right now, I have 50K words and I'm limiting the number of iteration in the while loop to 1000, shuffling my dictionary and I'm calling it again.

When I limit the loop to 1000 iterations, does it mean that I'm limiting my result to the first 1000 words in my dictionary?

karasek commented 8 years ago

Ok, great.

When you limit the white loop to 1000 iterations, it assigns max 1000 words from dictionary to some place in crossword, but during the assignment is backtracking done when needed. It cannot be said that only first 1000 words from dict are used, because selected words depends on actually filled pattern which is limited by number of letters or is partially filled from the adjanced pattern, for example U _ (words DRUM, BRUM, CRUD, ...). Words for pattern are taken from whole dictionary