My Quest
My quest recently has been to create a wordsearch creator for my wife. She and I homeschool our children, well it's more of her and less of me. She has looked at services offered online for $20 a month for a similar service.
Hey, I'm handy with computers...
I figured that I'd give it a go. Well, I've got an algorithm that works. Using this algorithm, I threw something together that worked. Then I wanted to put some polish on it and a web user interface. This part didn't go so well. I have been experiencing issues with getting all of the desired words added to the puzzle.
The Randomness
I have been using a random algorithm to place words in the puzzle grid. I choose a random direction for the word (horizontal, vertical or diagonal) and then choose a random potential starting point. This is where my algorithms differed, little did I know. In my first attempt, I declared a class level random number generator (the C# Random class). This seemed to work well. My second attempt had me using a localized and often re-created instance of the same class. The result was that I had very few, often just 1 word added to the grid.
My understanding of the Randomness
Somebody (like anybody reads this blog) shoudl correct me if I'm wrong. It seems as if I forgot the principle of seeding. It seems to me that the lack of a common seed for the Random class caused the generator to choose numbers too similar to the previous number to be of use. I found out that seeding the generator once, then using this generator for all random needs works like a charm. So far, with 12 words, words of my family, the wordsearch generator seems to work quickly and good enough.
Good Enough Performance
I expected this problem to be a performance hog. I thought that I would need many repetitions of attempting to place a word to get all of the words placed. It seems that for the time being, the solution works well enough. Is it the best solution, I don't know. I have some ideas of using a different algorithm to pack the words more tightly. Maybe performing all possible word placements to see which has the most resolvable collisions (a word intersection with same letters).
Enough for now
I'll be back with more. You can check the progress of the wordsearch builder at wordsearch.billnmel.com
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5