Skip to content

Word Search Generator

Generates word search grids dynamically. The DB stores only words and clues; the engine builds the grid.

Usage

const result = engine.generateWordSearch(
[
{ word: 'APPLE', clue: { type: 'TEXT', value: 'A red fruit' } },
{ word: 'DOG', clue: { type: 'IMAGE', value: 'https://cdn/dog.webp' } },
],
12, // gridSize
true, // allowDiagonal
false, // allowReverse
);

Response

{
"grid": [
["A", "P", "P", "L", "E", "X", "K", "M", "R", "T", "W", "Z"],
["B", "Q", "D", "O", "G", "U", "V", "W", "X", "Y", "Z", "A"]
],
"placedWords": [
{
"word": "APPLE",
"clue": { "type": "TEXT", "value": "A red fruit" },
"startRow": 0,
"startCol": 0,
"direction": [0, 1]
}
],
"size": 12
}

Parameters

ParameterTypeDescription
words{ word, clue }[]Words with clues
gridSizenumberGrid dimension (gridSize x gridSize)
allowDiagonalbooleanAllow diagonal words
allowReversebooleanAllow reversed words

Directions

VectorDescriptionAvailable when
[0, 1]Horizontal rightAlways
[1, 0]Vertical downAlways
[1, 1]Diagonal down-rightallowDiagonal: true
[1, -1]Diagonal down-leftallowDiagonal: true
[0, -1]Horizontal leftallowReverse: true
[-1, 0]Vertical upallowReverse: true
[-1, -1]Diagonal up-leftBoth true
[-1, 1]Diagonal up-rightBoth true

Algorithm

  1. Sorts words by length (longest first).
  2. Tries up to 100 random positions per word.
  3. Places if no conflict (empty cell or same letter).
  4. Fills empty cells with random A-Z letters.
  5. Returns grid and word placement metadata.

Words that don’t fit are silently omitted.