Crossword Puzzle Generator
This is a Rust-based command-line application that generates crossword puzzles from a given list of words. It uses a backtracking algorithm to arrange words on a grid, handling placement, resizing, and validation.
Features
- Generates crossword puzzles from a list of words using a backtracking algorithm.
- Eliminates words that do not share common characters to optimize generation.
- Supports horizontal and vertical word placements.
- Dynamically resizes the grid to accommodate words.
- Includes custom error handling for word and grid operations.
How to Build
To build the project, navigate to the project's root directory and run the following command:
This will compile the project and create an executable in the target/release/ directory.
How to Run
Running from Source
After building, you can run the application from the project's root directory:
Replace <word1> <word2> ... with the words you want to use in your crossword puzzle. All words must be in uppercase.
Installation via Cargo
If you have Rust and Cargo installed, you can install the crossword-puzzle CLI directly from crates.io:
Once installed, the crossword-puzzle executable will be available in your Cargo bin directory (usually ~/.cargo/bin), allowing you to run it from anywhere in your terminal:
Example Usage
To generate a crossword puzzle with the words "LOREM", "IPSUM", "DOLOR", "SIT", and "AMET":
The application will then print the generated crossword puzzle grid to the console.
A
M
E
SIT
P
D S
O U
LOREM
O
R
JSON Output
The crossword-puzzle library and CLI application provide JSON output for the generated grid, which can be useful for programmatic access or integration with other tools. The Grid and Word structs implement serde::Serialize, allowing them to be easily converted to JSON.
CLI Output
When running the CLI application, the generated grid is printed to the console in a human-readable format, followed by its JSON representation. This allows for both quick visual inspection and easy parsing of the output.
Library Usage
If you are using crossword-puzzle as a library, you can serialize the Grid object to JSON using the to_json() or to_json_pretty() methods:
use ;
This functionality is enabled by the serde feature. Ensure it is enabled in your Cargo.toml if you wish to use these methods:
[]
= {
version = "*",
= ["serde"]
}
Usage as a Library
You can use this crate as a library in your Rust project. Add it to your Cargo.toml:
[]
= "*"
Then, you can use the generate function to create a crossword puzzle:
use ;
Error Handling
The application includes custom error types for WordError and GridError to provide informative messages for issues such as:
- Empty or whitespace-only word segments.
- Lowercase characters in word segments (all words must be uppercase).
- Invalid directions for word placement or grid operations.
- Inability to generate a puzzle with the given words.
To-Do List
- Implement more sophisticated word placement algorithms.
- Add support for different grid shapes and sizes.
- Develop a graphical user interface (GUI).
- Allow custom word lists from a file.
- Improve error handling and user feedback.