Skip to main content

Creating mazes using prims' algorithm for the stara project

Project description

Stara Maze Generator

A Python package for generating, solving, and visualizing mazes using a modified version of Prim's algorithm. The mazes are represented as NumPy arrays and can be exported as HTML visualizations.

Features

  • Generate random mazes using a modified Prim's algorithm
  • Configurable maze size and minimum number of valid paths
  • Reproducible maze generation using seeds
  • Pathfinding using Breadth-First Search (BFS)
  • Export mazes as HTML visualizations with optional solution paths
  • Efficient maze representation using NumPy arrays

Installation

The package can be installed using pip:

pip install stara-maze-generator

Or using Poetry:

poetry add stara-maze-generator

Usage

Command Line Interface

The package provides a command-line interface for quick maze generation:

# Generate a default 40x40 maze
generate-maze

# Generate a 20x20 maze with custom start/goal positions
generate-maze --size 20 --start 0 0 --goal 19 19

# Generate a maze with a specific seed and show solution
generate-maze --seed 123 --draw-solution

# Generate a maze with more paths
generate-maze --min-valid-paths 5

Python API

from pathlib import Path
import numpy as np
from stara_maze_generator.vmaze import VMaze
from stara_maze_generator.pathfinder import Pathfinder

# Create a 20x20 maze
maze = VMaze(
    seed=42,              # Random seed for reproducibility
    size=20,              # Creates a 20x20 grid
    start=(1, 1),         # Starting position
    goal=(18, 18),        # Goal position
    min_valid_paths=3     # Minimum number of valid paths
)

# Generate the maze structure
maze.generate_maze(pathfinding_algorithm=Pathfinder.BFS)

# Find a path from start to goal
path = maze.find_path()

# Export as HTML visualization
maze.export_html(Path("maze.html"), draw_solution=True)

Maze Representation

The maze is represented as a 2D NumPy array where:

  • 0 represents walls
  • 1 represents passages
  • The maze is guaranteed to have at least min_valid_paths different paths from start to goal

HTML Visualization

The exported HTML visualization includes:

  • Color-coded cells (walls, passages, start, goal)
  • Optional solution path highlighting
  • Responsive grid layout
  • Maze information (size, seed, algorithm used)

Development

To set up the development environment:

# Clone the repository
git clone https://github.com/yourusername/stara-maze-generator.git
cd stara-maze-generator

# Install dependencies with Poetry
poetry install

# Run tests
poetry run pytest

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stara_maze_generator-0.2.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stara_maze_generator-0.2.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file stara_maze_generator-0.2.1.tar.gz.

File metadata

  • Download URL: stara_maze_generator-0.2.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for stara_maze_generator-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5c10747cc659ad000afc03ee2b218419a420562a41ddf1f228af60bc0ecf01e2
MD5 6f8e57b36f3693c1fa8879691912a784
BLAKE2b-256 e9d39bc7c006d5c2d72be348b5d4580dcd75b9be67a514d8670e85b3d0ec9fc2

See more details on using hashes here.

File details

Details for the file stara_maze_generator-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: stara_maze_generator-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.12.1 Linux/6.5.0-1025-azure

File hashes

Hashes for stara_maze_generator-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a1b0d7c63b2010a65ce6a5458e798f3f764caab82f1b34bf4bfda2803861c745
MD5 ad0b3773dbe5f68f73f881bb88b94f6b
BLAKE2b-256 b769c767f3b7a5995deaff8f1b1ce25a16e1b618409b4ad6405a940616ae4bec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page