Recently, I purchased a subscription to the Chicago Tribune, and while reading over the first issue I received, I noticed that they included a word search. As the days went on, I really started to enjoy working through the puzzle.
This got me thinking about how the publishers generated the puzzle. So I decided to see if I could make my own. As a result, I am pleased to share my own word search puzzle generator! Here is a link to the GitHub repo.
The premise behind the program is simple: have users enter in a list of words, then generate a word search puzzle.
To generate my puzzle, I had to setup a few things.
After the user enters the list of words they would like to use, the program sorts the words longest to shortest.
Words in a puzzle can have 8 directions:
Direction | Visual |
---|---|
up | ↑ |
down | ↓ |
left | ← |
right | → |
up-left | ↖ |
up-right | ↗ |
down-left | ↙ |
down-right | ↘ |
Every time a puzzle is generated, you need to setup the initial puzzle grid.
To do this, I created a 2-d array and set every point in there to a NULL
value.
My programs implements a Point
class that represents a (X, Y) point on the puzzle grid.
Once the directions are set and the words are sorted, it is time to generate the puzzle.
The algorithm was pretty simple, for each word in the puzzle:
To check if the word can be inserted into the puzzle, there are a few things you need to examine. You will need the word itself, the starting point, and the direction.
The word cannot be inserted if any of the conditions are true:
https://github.com/sbj42/word-search-generator
https://github.com/jamis/wordsearch
https://github.com/danbarbarito/Word-Search-Generator
https://weblog.jamisbuck.org/2015/9/26/generating-word-search-puzzles.html
© 2024 by Ryan Rickgauer