qsolve/
lib.rs

1#![warn(missing_docs)]
2
3//! A library for solving Queens puzzles
4//!
5//! This library is designed to solve [Queens puzzles](<https://www.linkedin.com/games/queens>),
6//! with a few key characteristics:
7//!
8//! * **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.
9//! * **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.
10//!
11//! # Example
12//!
13//! Basic usage of the library looks something like this:
14//!
15//! ```
16//! # use std::path::PathBuf;
17//! # use qsolve::file::QueensFile;
18//! # use qsolve::heuristic::all_heuristics;
19//! # use qsolve::solveiter::solve_iter;
20//! # use qsolve::solvestate::{SolveState, SolveStrategy};
21//! # use anyhow::Result;
22//! # fn main() -> Result<()> {
23//! // Parse a text file containing a Queens puzzle.
24//! let queens_file = QueensFile::try_from_text_file(&PathBuf::from("games/linkedin-1-empty.txt"))?;
25//!
26//! // Generate the initial solve state and print it.
27//! let solve_state = SolveState::from(&queens_file);
28//! println!("{}", solve_state);
29//!
30//! // Generate the list of heuristics to use to solve the puzzle.
31//! let heuristics = all_heuristics(solve_state.board);
32//!
33//! // Solve the puzzle and print out the solution.
34//! let solved = solve_iter(solve_state, SolveStrategy::Fast, &heuristics).last().unwrap().solve_state;
35//! println!("{}", solved);
36//! # Ok(())
37//! # }
38//! ```
39
40/// Structs to represent Queens boards.
41pub mod board;
42
43/// Data structures for efficient manipuations of rows, cols, colors and coords.
44pub mod datastructure;
45
46/// Logic to represent an underlying file containing a Queens game.
47pub mod file;
48
49/// Heuristics used to solve the Queens game.
50pub mod heuristic;
51
52/// Image parsing logic to allow screenshots of Queens games to be used.
53pub mod image;
54
55/// Iterators for moving through the process of solving a game.
56pub mod solveiter;
57
58/// Structs to represent intermediate states of solving a Queens puzzle.
59pub mod solvestate;
60
61/// Representation of different square colors and associated display logic.
62pub mod squarecolor;
63
64/// Logic to generate the share text for a solved puzzle.
65pub mod share;
66
67// Use doc_comment to ensure code snippets in the readme compile.
68extern crate doc_comment;
69doc_comment::doctest!("../README.md");