This project contains a homemade crossword algorithms, working on a short given list of words. It's not making real complete without-gap crossword at all, because these one works with big database of words and take quite a time to process. Here is juste an algorithm working with very few words but trying to make the best it can to cross these words together.
The source version you can download below is a rebuild version of it on Unity 4.3.4. It works fine on my computer.
Crossword Generator.zip |
A Really Quick How-To
The Generator Algorithm
Here is how it works:
- Sort the words list by length (descendant)
- Put the first (= biggest) word of the list on the grid
- Loop on all the words in the list
- For each word of the list, find letters in common with words letters on the grid, that gives you a list of potential position
- Remove from this new list all positions that "if you place the new word there, it will overlap existing words" on the grid. Except if overlapping letters are both equal.
- Choose one of this position to place the word on.
That's of course the very basic process but it takes others parameters to be more precise.
That's some features I added:
- To choose which position to place the new word, I use a score system to find the best position. This score is based on several parameters like: How many intersections it will create with existing words, How much it will increase our grid (the less the better), or little random fuzzer...
- Not always sorting the words lists by length, but shuffling instead
- Since we have some random parameters, one list of words won't give us always the same grid. So when generating a grid, I generate a certain amount of them and choose the best, that has the more words and the smallest size.
To work with words easily I make a class that has position and grid features called CrossedWord. The algorithm code is not clean at all, and contains lots of variables strangely named, sorry about that. I let you have a look at it: