-
Pl
chevron_right
Laureen Caliman: Pick a word, any word
news.movim.eu / PlanetGnome • 15:40 • 1 minute
Over the past few weeks, I have been writing the backend for the vocabulary-puzzle generator for Crosswords.
But what entirely dictates a valid word placement whilst being mindful of all edge cases and managing the state of the puzzle upon the exploration of possible solutions?
Finding valid intersections
For each word in the list, the vocab generator searches for every valid location where the word at the current depth could be added (or not added) to the current puzzle. A candidate must satisfy several constraints:
- Word must intersect existing puzzle.
- Intersecting characters must match.
- Existing letters must not be overwritten by conflicting letters.
- The word is within a 30×30 board boundary.
- Puzzle remains entirely connected.
- Word placements cannot connect flush to their head/tail to another word.
- Could there be multiple valid intersections?
As more words are added, the number of possible intersections rapidly grow. A single placement may produce several valid connections, each of which must be evaluated independently.
Modeling the intersections
The vocab grid generator represents candidate placements by using the coordinates of the intersection, placement direction (across, down), and the offset of the intersecting character within the word. As a whole, an intersection can transform the entire puzzle. For instance, “APPLE” and “PEAR” are just two words, but share four possible intersections. Rather than selecting one immediately, we ultimately want to record every valid candidate.
Each of these shared candidates then become a potential node in our recursive search tree. As our puzzle grows in size, the problem becomes less about placing words and more about exploring all valid intersections whilst preserving the integrity of the puzzle state as we add and rearrange words.