Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
omeyenburg committed Jan 15, 2024
1 parent 8ba3622 commit 8775729
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 40 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# MazeForge

Generation of mazes in Python

## Installation

You can install **MazeForge** from [PyPI](https://pypi.org/project/mazeforge/) by running the following in your terminal.<br>
`python -m pip install mazeforge`
<br>

MazeForge is supported on Python 3.7 and above.

## How to use

```python
>>> import mazeforge
>>> mazeforge.generate(3, 3)
Expand All @@ -21,5 +25,7 @@ array([[1., 1., 1., 1., 1., 1., 1.],
```

## Documentation

### mazeforge.generate
`mazeforge.generate` generates a perfect maze. This means that any two cells are connected by one single unique path. The function returns 2d numpy array. Walls are represented as a `1` and corridor as a `0`. The maze is generated using the prim's algorithm.

`mazeforge.generate` generates a perfect maze. This means that any two cells are connected by one single unique path. The function returns 2d numpy array. Walls are represented as a `1` and corridor as a `0`. The maze is generated using the prim's algorithm.
Binary file modified dist/mazeforge-0.1.0-py3-none-any.whl
Binary file not shown.
Binary file modified dist/mazeforge-0.1.0.tar.gz
Binary file not shown.
49 changes: 24 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[build-system]
requires = ["setuptools>=61.0.0", "wheel"]
requires = ["setuptools >= 61.0.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "mazeforge"
version = "0.1.0"
description = "Simple and fast generation of mazes in Python"
description = "Simple and fast generation of mazes"
readme = "README.md"
authors = [{ name = "Oskar Meyenburg", email = "[email protected]" }]
license = { file = "LICENSE" }
classifiers = [
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
Expand All @@ -19,38 +20,36 @@ keywords = ["labyrinth", "maze", "pymaze", "generation", "generate", "solve"]
dependencies = ["numpy"]
requires-python = ">=3.7"

[project.optional-dependencies]
build = ["build", "twine"]
dev = ["black", "bumpver", "isort", "mypy", "pytest"]
[project.optional-dependencies]
build = ["build", "twine"]
dev = ["black", "bumpver", "isort", "mypy", "pytest"]

# This would create the terminal command "mazeforge"
#[project.scripts]
#mazeforge = "mazeforge.__main__:main"
# This would create the terminal command "mazeforge"
#[project.scripts]
#mazeforge = "mazeforge.__main__:main"

[project.urls]
Homepage = "https://github.com/oskarmeyenburg/mazeforge"
repository = "https://github.com/oskarmeyenburg/mazeforge"
documentation = "https://github.com/oskarmeyenburg/mazeforge/blob/main/README.md"
[project.urls]
repository = "https://github.com/oskarmeyenburg/mazeforge"
documentation = "https://github.com/oskarmeyenburg/mazeforge/blob/main/README.md"

[tool.bumpver]
current_version = "0.1.0"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "bump version {old_version} -> {new_version}"
commit = true
tag = true
push = false

[tool.bumpver.file_patterns]
"pyproject.toml" = [
'current_version = "{version}"',
'version = "{version}"',
]
"src/mazeforge/__init__.py" = ["{version}"]
"src/mazeforge/__main__.py" = ["- mazeforge v{version}"]
commit = true
tag = true
push = false

[tool.bumpver.file_patterns]
"pyproject.toml" = [
'current_version = "{version}"',
'version = "{version}"',
]
"src/mazeforge/__init__.py" = ["{version}"]

[tool.isort]
profile = "black"
import_heading_stdlib = "Standard library imports"
profile = "black"
import_heading_stdlib = "Standard library imports"
import_heading_thirdparty = "Third party imports"
import_heading_firstparty = "Reader imports"

Expand Down
10 changes: 8 additions & 2 deletions src/mazeforge.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Metadata-Version: 2.1
Name: mazeforge
Version: 0.1.0
Summary: Simple and fast generation of mazes in Python
Summary: Simple and fast generation of mazes
Author-email: Oskar Meyenburg <[email protected]>
License: MIT License

Expand All @@ -25,10 +25,10 @@ License: MIT License
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Project-URL: Homepage, https://github.com/oskarmeyenburg/mazeforge
Project-URL: repository, https://github.com/oskarmeyenburg/mazeforge
Project-URL: documentation, https://github.com/oskarmeyenburg/mazeforge/blob/main/README.md
Keywords: labyrinth,maze,pymaze,generation,generate,solve
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Expand All @@ -48,15 +48,19 @@ Requires-Dist: mypy; extra == "dev"
Requires-Dist: pytest; extra == "dev"

# MazeForge

Generation of mazes in Python

## Installation

You can install **MazeForge** from [PyPI](https://pypi.org/project/mazeforge/) by running the following in your terminal.<br>
`python -m pip install mazeforge`
<br>

MazeForge is supported on Python 3.7 and above.

## How to use

```python
>>> import mazeforge
>>> mazeforge.generate(3, 3)
Expand All @@ -70,5 +74,7 @@ array([[1., 1., 1., 1., 1., 1., 1.],
```

## Documentation

### mazeforge.generate

`mazeforge.generate` generates a perfect maze. This means that any two cells are connected by one single unique path. The function returns 2d numpy array. Walls are represented as a `1` and corridor as a `0`. The maze is generated using the prim's algorithm.
20 changes: 8 additions & 12 deletions src/mazeforge/generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random
import numpy

def generate(width: int, height: int) -> numpy.ndarray:
def generate(width, height):
"""
Generate a 2d maze on a grid.
Expand All @@ -17,27 +17,23 @@ def generate(width: int, height: int) -> numpy.ndarray:
numpy.ndarray
Maze as a numpy.ndarray with the shape (2 * width + 1, 2 * height + 1)
"""
width = width * 2 + 1
height = height * 2 + 1
maze = numpy.ones((width, height), dtype=numpy.int_)
# Prim's algorithm
array_width = width * 2 + 1
array_height = height * 2 + 1
maze = numpy.ones((array_width, array_height), dtype=numpy.int_)

for x, y in numpy.ndindex((width, height)):
for x, y in numpy.ndindex((array_width, array_height)):
if 1 == x % 2 == y % 2:
maze[x, y] = 0

# Prim's algorithm
maze_width = (width - 1) // 2
maze_height = (height - 1) // 2

def get_neighbours(x, y):
neighbours = {(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)}
for neighbour in tuple(neighbours):
if not (0 <= neighbour[0] < maze_width and 0 <= neighbour[1] < maze_height):
if not (0 <= neighbour[0] < width and 0 <= neighbour[1] < height):
neighbours.discard(neighbour)
return neighbours


existing_cells = {(maze_width // 2, maze_height // 2)}
existing_cells = {(width // 2, height // 2)}
adjacent_cells = get_neighbours(*list(existing_cells)[0])

while len(adjacent_cells):
Expand Down

0 comments on commit 8775729

Please sign in to comment.