OCR Project
Loading...
Searching...
No Matches
solver.h File Reference

Crossword word-search solver: find words in a 2-D character grid in all 8 directions. More...

#include <stddef.h>
Include dependency graph for solver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CharGrid
 A rectangular character grid. More...
struct  WordResult
 Result of a single word search. More...

Functions

CharGridgrid_create (int rows, int cols)
 Allocate a CharGrid of the given dimensions, filled with spaces.
void grid_fill (CharGrid *grid, const int *labels, size_t count)
 Fill a CharGrid from an array of predicted character indices.
CharGridgrid_load (const char *path)
 Read a CharGrid from a plain-text file.
void grid_print (const CharGrid *grid)
 Print a CharGrid to stdout (for debugging / verbose mode).
void grid_free (CharGrid *grid)
 Free a CharGrid.
WordResult solver_find (const CharGrid *grid, const char *word)
 Search for word in grid in all 8 directions.
const char * solver_dir_name (int dir)
 Return the human-readable name of direction index dir.

Detailed Description

Crossword word-search solver: find words in a 2-D character grid in all 8 directions.

The character grid is built from the CNN's predictions after segmentation: each cell in the crossword image yields one predicted character (A–Z). The solver then searches for user-supplied words in the resulting grid.

Directions (clockwise from East): RIGHT, DOWN_RIGHT, DOWN, DOWN_LEFT, LEFT, UP_LEFT, UP, UP_RIGHT

Function Documentation

◆ grid_create()

CharGrid * grid_create ( int rows,
int cols )

Allocate a CharGrid of the given dimensions, filled with spaces.

Parameters
rowsNumber of rows.
colsNumber of columns.
Returns
Heap-allocated CharGrid, or NULL on failure. Free with grid_free().
Here is the caller graph for this function:

◆ grid_fill()

void grid_fill ( CharGrid * grid,
const int * labels,
size_t count )

Fill a CharGrid from an array of predicted character indices.

Parameters
gridTarget grid (must already be allocated with the right size).
labelsArray of class indices in [0, 25]; labels[r*cols + c] gives the index for cell (r, c). 0='A', 25='Z'.
countNumber of elements in labels (must equal rows * cols).
Here is the caller graph for this function:

◆ grid_free()

void grid_free ( CharGrid * grid)

Free a CharGrid.

Parameters
gridGrid to free. No-op if NULL.
Here is the caller graph for this function:

◆ grid_load()

CharGrid * grid_load ( const char * path)

Read a CharGrid from a plain-text file.

File format (first line: dimensions, then one row per line):

rows cols
ABCDE
FGHIJ
Parameters
pathPath to the grid file.
Returns
Heap-allocated CharGrid on success, NULL on error. Free with grid_free().
Here is the call graph for this function:

◆ grid_print()

void grid_print ( const CharGrid * grid)

Print a CharGrid to stdout (for debugging / verbose mode).

Parameters
gridGrid to display.
Here is the caller graph for this function:

◆ solver_dir_name()

const char * solver_dir_name ( int dir)

Return the human-readable name of direction index dir.

Directions are numbered 0–7: 0=RIGHT, 1=DOWN_RIGHT, 2=DOWN, 3=DOWN_LEFT, 4=LEFT, 5=UP_LEFT, 6=UP, 7=UP_RIGHT

Parameters
dirDirection index in [0, 7].
Returns
Constant string (e.g. "RIGHT"), or "UNKNOWN" if out of range.
Here is the caller graph for this function:

◆ solver_find()

WordResult solver_find ( const CharGrid * grid,
const char * word )

Search for word in grid in all 8 directions.

The search is case-insensitive; the grid and word are both converted to uppercase before comparison.

Parameters
gridCharacter grid to search in.
wordNull-terminated string to search for (A–Z, case-insensitive).
Returns
WordResult with found=1 and coordinates if found, or found=0 if not present.
Here is the call graph for this function:
Here is the caller graph for this function: