1 unstable release
new 0.1.0 | Apr 1, 2025 |
---|
#152 in Games
11KB
121 lines
๐งญ cartesian-maze-puzzle
A minimal, efficient, and fun procedural maze generation library written in Rust ๐ฆ. Generate perfect mazes (no loops, no isolated sections), navigate them programmatically, and use them for puzzles, games, AI pathfinding, or teaching algorithms.
๐ Features
- Generates perfect mazes using randomized depth-first search (DFS)
- Easy-to-use API to move through the maze
- Fully deterministic size and layout
- Lightweight with zero external dependencies beyond
rand
- Built-in unit tests
- Suitable for CLI, GUI, or game integration
๐ฆ Installation
Add the following to your Cargo.toml
:
[dependencies]
cartesian-maze-puzzle = "0.1"
๐งฑ Example
use cartesian_maze_puzzle::{Maze, Direction};
fn main() {
let mut maze = Maze::new(5, 5);
println!("Starting at: {:?}", maze.player);
// Try moving east
if maze.try_move(Direction::East) {
println!("Moved to: {:?}", maze.player);
} else {
println!("Hit a wall!");
}
// Check if you've reached the end
if maze.is_at_end() {
println!("You solved the maze!");
}
}
๐งช Tests
Run unit tests with:
cargo test
Tests verify:
- Valid movement and boundary constraints
- All cells are reachable
- Player position is correctly updated
- Maze is fully connected (i.e., perfect maze)
๐ Documentation
The full API is available on docs.rs.
๐ค Why "Cartesian"?
Because the maze operates on a classic Cartesian coordinate grid where (0, 0)
is the top-left corner. It's simple, intuitive, and easy to visualize or integrate into grid-based games.
๐ Folder Structure Suggestion
src/
โโโ lib.rs # Maze logic
โโโ main.rs # (Optional) CLI or demo interface
tests/
โโโ integration.rs # Integration tests
๐ License
Licensed under either of:
- Apache License, Version 2.0
- MIT license
See LICENSE for more information.
โจ Contribution
Contributions welcome! Feel free to open issues or PRs for:
- Bug fixes
- Maze solving/pathfinding algorithms
- CLI game implementation
- Visualization features (ASCII or graphics)
โค๏ธ Acknowledgments
Thanks to the Rust community and all contributors to the rand
crate!
Made with ๐งฉ by Andrew Sims
Dependencies
~1MB
~17K SLoC