simplemaze


Namesimplemaze JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/david-pettifor-nd/simplemaze
SummaryA Python library for generating mazes
upload_time2025-02-18 17:26:06
maintainerNone
docs_urlNone
authorDavid W Pettifor
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SimpleMaze

A Python library for generating mazes.

## Installation

```bash
pip install simplemaze
```

## Usage

```python
from simplemaze import Maze

# generates a 10x10 maze (width, height)
maze = Maze(10, 10)

# export the maze to an html file for printing
maze.export_to_html('maze.html')

# export the maze to an image file
maze.export_to_image('maze.png')
```

## Algorithms

### Recursive Backtracker (Depth-First Search)
```python
from simplemaze import Maze

# generates a 10x10 maze (width, height) using the depth-first search algorithm
maze = Maze(10, 10, method='depth_first')
```

This algorithm is a simple depth-first search that starts at the top-left corner and randomly chooses a direction to move in. It then recursively calls itself to generate the maze.

This algorithm is very fast, and guarantees a unique solution if the maze has no cycles. However, it does not produce the most aesthetically pleasing mazes. Most of the time, it will create a maze that has a very long, winding solution with short dead ends.

### Kruskal's Algorithm
```python
from simplemaze import Maze

# generates a 10x10 maze (width, height) using Kruskal's algorithm
maze = Maze(10, 10, method='kruskal')
```

This algorithm is a more complex algorithm that guarantees a unique solution if the maze has no cycles. It works by randomly choosing two cells and removing the wall between them if they are not already connected. It then recursively calls itself to generate the maze.

It produces mazes that are much more aesthetically pleasing than the depth-first search algorithm, but are typically not as long as the depth-first search algorithm and easier to solve. However, it is slower than the depth-first search algorithm.

### Prim's Algorithm (default)
```python
from simplemaze import Maze

# generates a 10x10 maze (width, height) using Prim's algorithm
maze = Maze(10, 10, method='prim')
```

This algorithm is similar to Kruskal's algorithm, but it works by starting at a random cell and then growing the maze outward from there. It is faster than Kruskal's algorithm, but it produces mazes that are more challenging to solve with a shorter solution path but longer dead ends.

### Wilson's Algorithm
```python
from simplemaze import Maze

# generates a 10x10 maze (width, height) using Wilson's algorithm
maze = Maze(10, 10, method='wilson')
```

This algorithm is a more complex algorithm that guarantees a unique solution if the maze has no cycles (however, it is possible to generate a maze that has cycles with this algorithm). It works by starting at a random cell and then growing the maze outward from there. It is slower than Prim's algorithm, but it produces mazes that are more aesthetically pleasing and easier to solve.

## Exporting to HTML

The HTML export is designed to be printed on standard 8.5x11 inch paper with 0.39 inch margins on all sides. The HTML file will automatically scale the maze to fit the page, so it will be as large as possible without cutting off the walls. 

```python
maze.export_to_html('maze.html')
```

### Parameters

- `auto_scale`: If true, the maze will be scaled to fit the page. If false, the maze will be scaled to the specified cell size.
- `cell_size`: The size of each cell in the maze.
- `page_width`: The width of the page in inches.
- `page_height`: The height of the page in inches.
- `margin`: The margin of the page in inches.

```python
maze.export_to_html('maze.html', auto_scale=False, cell_size=20, page_width=8.5, page_height=11, margin=0.39)
```

## Exporting to Image

The image export takes in a filename and a cell size. It will create a blank image of the specified cell size and draw the maze on it.

```python
maze.export_to_image('maze.png')
```

### Parameters

- `cell_size`: The size of each cell in the maze.
- `wall_width`: The width of the walls in the maze.

```python
maze.export_to_image('maze.png', cell_size=20, wall_width=1)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/david-pettifor-nd/simplemaze",
    "name": "simplemaze",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "David W Pettifor",
    "author_email": "noctemowl@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d0/9c/15b90a4582dbd5804d2a7c4ac5dfc73f570ed0a4b5640e78254d4af23bc1/simplemaze-0.1.1.tar.gz",
    "platform": null,
    "description": "# SimpleMaze\n\nA Python library for generating mazes.\n\n## Installation\n\n```bash\npip install simplemaze\n```\n\n## Usage\n\n```python\nfrom simplemaze import Maze\n\n# generates a 10x10 maze (width, height)\nmaze = Maze(10, 10)\n\n# export the maze to an html file for printing\nmaze.export_to_html('maze.html')\n\n# export the maze to an image file\nmaze.export_to_image('maze.png')\n```\n\n## Algorithms\n\n### Recursive Backtracker (Depth-First Search)\n```python\nfrom simplemaze import Maze\n\n# generates a 10x10 maze (width, height) using the depth-first search algorithm\nmaze = Maze(10, 10, method='depth_first')\n```\n\nThis algorithm is a simple depth-first search that starts at the top-left corner and randomly chooses a direction to move in. It then recursively calls itself to generate the maze.\n\nThis algorithm is very fast, and guarantees a unique solution if the maze has no cycles. However, it does not produce the most aesthetically pleasing mazes. Most of the time, it will create a maze that has a very long, winding solution with short dead ends.\n\n### Kruskal's Algorithm\n```python\nfrom simplemaze import Maze\n\n# generates a 10x10 maze (width, height) using Kruskal's algorithm\nmaze = Maze(10, 10, method='kruskal')\n```\n\nThis algorithm is a more complex algorithm that guarantees a unique solution if the maze has no cycles. It works by randomly choosing two cells and removing the wall between them if they are not already connected. It then recursively calls itself to generate the maze.\n\nIt produces mazes that are much more aesthetically pleasing than the depth-first search algorithm, but are typically not as long as the depth-first search algorithm and easier to solve. However, it is slower than the depth-first search algorithm.\n\n### Prim's Algorithm (default)\n```python\nfrom simplemaze import Maze\n\n# generates a 10x10 maze (width, height) using Prim's algorithm\nmaze = Maze(10, 10, method='prim')\n```\n\nThis algorithm is similar to Kruskal's algorithm, but it works by starting at a random cell and then growing the maze outward from there. It is faster than Kruskal's algorithm, but it produces mazes that are more challenging to solve with a shorter solution path but longer dead ends.\n\n### Wilson's Algorithm\n```python\nfrom simplemaze import Maze\n\n# generates a 10x10 maze (width, height) using Wilson's algorithm\nmaze = Maze(10, 10, method='wilson')\n```\n\nThis algorithm is a more complex algorithm that guarantees a unique solution if the maze has no cycles (however, it is possible to generate a maze that has cycles with this algorithm). It works by starting at a random cell and then growing the maze outward from there. It is slower than Prim's algorithm, but it produces mazes that are more aesthetically pleasing and easier to solve.\n\n## Exporting to HTML\n\nThe HTML export is designed to be printed on standard 8.5x11 inch paper with 0.39 inch margins on all sides. The HTML file will automatically scale the maze to fit the page, so it will be as large as possible without cutting off the walls. \n\n```python\nmaze.export_to_html('maze.html')\n```\n\n### Parameters\n\n- `auto_scale`: If true, the maze will be scaled to fit the page. If false, the maze will be scaled to the specified cell size.\n- `cell_size`: The size of each cell in the maze.\n- `page_width`: The width of the page in inches.\n- `page_height`: The height of the page in inches.\n- `margin`: The margin of the page in inches.\n\n```python\nmaze.export_to_html('maze.html', auto_scale=False, cell_size=20, page_width=8.5, page_height=11, margin=0.39)\n```\n\n## Exporting to Image\n\nThe image export takes in a filename and a cell size. It will create a blank image of the specified cell size and draw the maze on it.\n\n```python\nmaze.export_to_image('maze.png')\n```\n\n### Parameters\n\n- `cell_size`: The size of each cell in the maze.\n- `wall_width`: The width of the walls in the maze.\n\n```python\nmaze.export_to_image('maze.png', cell_size=20, wall_width=1)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python library for generating mazes",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://github.com/david-pettifor-nd/simplemaze"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a224d7eef58ae187265c8c33fdd65a249aca9d604e86bc2d8d391b8bdcfca8f3",
                "md5": "5bc28b1b0635f20412898620f5c5dad2",
                "sha256": "dbc5efd9a81f732d219a7564bf89f581204abbbebc58fcb2c382b10777cef19c"
            },
            "downloads": -1,
            "filename": "simplemaze-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5bc28b1b0635f20412898620f5c5dad2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5973,
            "upload_time": "2025-02-18T17:26:05",
            "upload_time_iso_8601": "2025-02-18T17:26:05.098771Z",
            "url": "https://files.pythonhosted.org/packages/a2/24/d7eef58ae187265c8c33fdd65a249aca9d604e86bc2d8d391b8bdcfca8f3/simplemaze-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d09c15b90a4582dbd5804d2a7c4ac5dfc73f570ed0a4b5640e78254d4af23bc1",
                "md5": "9303033e92226c2740529d6ce223bcb8",
                "sha256": "b309681efad25033debef5a1a1073d291ceb27cdf8609fc80ecb95fd83795a3b"
            },
            "downloads": -1,
            "filename": "simplemaze-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9303033e92226c2740529d6ce223bcb8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6111,
            "upload_time": "2025-02-18T17:26:06",
            "upload_time_iso_8601": "2025-02-18T17:26:06.669195Z",
            "url": "https://files.pythonhosted.org/packages/d0/9c/15b90a4582dbd5804d2a7c4ac5dfc73f570ed0a4b5640e78254d4af23bc1/simplemaze-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-18 17:26:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "david-pettifor-nd",
    "github_project": "simplemaze",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "simplemaze"
}
        
Elapsed time: 1.20580s