qsolve/lib.rs
1#![warn(missing_docs)]
2#![cfg_attr(doctest, doc = include_str!("../README.md"))]
3
4//! A library for solving Queens puzzles
5//!
6//! This library is designed to solve [Queens puzzles](<https://www.linkedin.com/games/queens>),
7//! with a few key characteristics:
8//!
9//! * **Human-understandable**: Humans solve queens by iteratively eliminating and confirming squares. This library does the same process; it doesn't use and do any sort of search-algorithms to try and find the solution from afar.
10//! * **Speed**: Within the bounds of the above, it tries to be as fast as possible. This means, for example, it uses bitfields rather than HashSets for efficient operations on small sets.
11//! - **Tested**: While tracing code and error recovery means this library doesn't have 100% code coverage, it aspires to be as well-tested as possible. If `cargo test` passes, then we should be confident things work.
12//! - **Documented**: The `qsolve` binary should have clear documentation available with `--help` for every subcommand. The `qsolve` library should have clear documentation (including doctests) for all public functionality.
13//!
14//! # Example
15//!
16//! Basic usage of the library looks something like this:
17//!
18//! ```
19//! # use std::str::FromStr;
20//! # use qsolve::file::QueensFile;
21//! # use qsolve::heuristic::all_heuristics;
22//! # use qsolve::solveiter::solve_iter;
23//! # use qsolve::solvestate::{SolveState, SolveStrategy};
24//! # use anyhow::Result;
25//! # fn main() -> Result<()> {
26//! // Parse a text file containing a Queens puzzle.
27//! let queens_file = QueensFile::from_str("wwww\nwkkk\nrrrr\nbbbb")?;
28//!
29//! // Generate the initial solve state and print it.
30//! let solve_state = SolveState::from(&queens_file);
31//! println!("{}", solve_state);
32//!
33//! // Generate the list of heuristics to use to solve the puzzle.
34//! let heuristics = all_heuristics(solve_state.board);
35//!
36//! // Solve the puzzle and print out the solution.
37//! let solved = solve_iter(solve_state, SolveStrategy::Fast, &heuristics).last().unwrap().solve_state;
38//! println!("{}", solved);
39//! # Ok(())
40//! # }
41//! ```
42
43/// Structs to represent Queens boards.
44pub mod board;
45
46/// Data structures for efficient manipuations of rows, cols, colors and coords.
47pub mod datastructure;
48
49/// Logic to represent an underlying file containing a Queens game.
50pub mod file;
51
52/// Heuristics used to solve the Queens game.
53pub mod heuristic;
54
55/// Image parsing logic to allow screenshots of Queens games to be used.
56#[cfg(feature = "image")]
57pub mod image;
58
59/// Iterators for moving through the process of solving a game.
60pub mod solveiter;
61
62/// Structs to represent intermediate states of solving a Queens puzzle.
63pub mod solvestate;
64
65/// Representation of different square colors and associated display logic.
66pub mod squarecolor;
67
68/// Logic to generate the share text for a solved puzzle.
69pub mod share;