#puzzle #cartesian #maze #direction

cartesian_maze_puzzle

A cartesian maze puzzle for you to solve

1 unstable release

new 0.1.0 Apr 1, 2025

#152 in Games

MIT license

11KB
121 lines

๐Ÿงญ cartesian-maze-puzzle

Crates.io Docs.rs

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