Tactical Tinkering

Wordsearch Generator (C++)

Here's a wee program I built a long, long time ago, when I was just learning C++. It's a console program that generates a wordsearch of arbitrary dimensions from user input, and saves to a file.

As far as the algorithm goes, it just selects a random square to begin placing a word, picks a random orientation, then checks to see if the word will fit there – happily allowing words to cross each other if they happen to match up. So it's about as brute force as you can get; sure, it's not particularly efficient, it will generate and check some ridiculous positions, like trying to fit 'RIDICULOUS' in horizontally starting in the last column, but, unless you have some particular reason to want to generate a million wordsearches a second, who cares? The only realistic problem I see is if you wanted a wordsearch densely packed with words, in which case a program which looks for efficient ways of 'packing' the words in would be preferable. But I'm not a big fan of those anyway – by the time you're on the last few words your wordsearch is inked up like a Jackson Pollock, and nothing but tediosity remains.

Visual Studio 2010 project file included.

© Dan Brown 2013