This program creates a crossword grid and fills it with words. The filling routine is quite simple and a number of tries are required before a completed grid is produced.
The program creates a standard 15x15 grid with the following rules:
- Words can be only between 4 and 10 letters long
- The grid is 2-fold symmetric (if you rotate it through 180 degrees, it'll be the same)
- There must be perfect contiguousness
The routine for checking contiguousness is fairly simple, but I believe that it will trap faulty grids: if you discover a noncontiguous grid, please let me know. The routine for placing the blanks is also fairly simple and some grids do not have the standard crossword look (although all are acceptable).
The method for filling the grid with words is a simple blundering process: a random word of the correct length is tried: if all its squares are blank then this word is added: if some of its squares are already filled and the word does not fit, another word is tried. If (as is likely) the grid cannot be successfully filled, then another grid is generated and the process begins again.
This blundering process takes some time to achieve a completely filled grid, and some efforts have been made to improve the chance of success. The dictionary used was created from two readily available on the web: quite a large number of words are thus contained in the dictionary. You may find (as I do) that a completed grid uses some seemingly improbable words, but somebody has judged them acceptable. The dictionary also includes some phrases.
When selecting words from the dictionary, the program makes some judgement of how likely the word is to cross successfully. A word which would produce a cross word ending with unlikely letters like Q or Z is avoided. And a word which would be less likely to cross with another in the middle (letters like J and X) are also avoided.
So you will notice that a completed grid has words which favour the common letters like E in the crossing positions. The Qs, J's, K's et cetera will only appear at the start of words or in non-crossing positions.
The longest words are placed first, as fitting the shorter words to existing ones has a better chance.
The program is multilingual, and you can choose which language to use. The alternatives are:
- British English
- US English
- German
- Spanish
- French
- Italian
- Dutch
Running the program
Extract the folder "Crossword Generator" from the .zip file and place the folder in your QB64 folder (be careful not to create an extra folder layer). Open the "Multilingual Crossword Generator.bas" in the IDE (with "Output EXE to Source Folder" checked).
[The source folder contains another .bas file which is an older version (English only) of the program].
You will be presented with a Menu List to choose your language.
Although I have constructed this Options Menu to look like an InForm program (Windows native look), there is no mouse function available. Press the Spacebar to change the language and Return to select your language.
The program will generate a grid and slowly fill with words. When a word can no longer be found to fit, asterisks are filled in that place - it is unlikely that the grid will be successfully filled - and the program waits for keyboard input. If you press the Spacebar, another grid will be generated and again words will be added. If you press "f" when the filling stops, the program will quickly generate new grids and try to fill and the process will continue until a filled grid is obtained. Then the program will again wait for keyboard input. Spacebar will create another grid, "f" will revert to the step-by-step method. Esc will quit.
It takes a number of attempts to produce a completely filled grid, and on my Core i5 PC this takes some seconds (dependent upon the language, and if you've a slower machine you may have to wait for longer).
The process to fill the grid clearly has no intelligence to find words that will allow crossing words to be found in a small number of attempts. An actual human compiler will be careful to think in advance. Also, there may be some cases where the program, as is, is rejecting acceptable words. So if you're sufficiently interested, you may like to create a rather cleverer program.
You may well suggest that a naive bystanding youngster would say of this program "But it doesn't do anything!". This innocent would be correct: the emperor is entirely unclothed.
Multilingual Program now included (Updated 13/09/19)