From 8ba3622663665dc6665183263ab1d0683cea5c85 Mon Sep 17 00:00:00 2001 From: oskarmeyenburg Date: Mon, 15 Jan 2024 16:40:12 +0100 Subject: [PATCH] Added class and improved docs --- src/mazeforge.egg-info/PKG-INFO | 4 +++- src/mazeforge.egg-info/SOURCES.txt | 2 +- src/mazeforge.egg-info/entry_points.txt | 2 -- src/mazeforge/__init__.py | 24 +++++++++++++++--------- src/mazeforge/base.py | 16 ++++++++++++++++ src/mazeforge/generator.py | 17 ++++++++++++++++- 6 files changed, 51 insertions(+), 14 deletions(-) delete mode 100644 src/mazeforge.egg-info/entry_points.txt create mode 100644 src/mazeforge/base.py diff --git a/src/mazeforge.egg-info/PKG-INFO b/src/mazeforge.egg-info/PKG-INFO index 280dc7c..d0bfbe0 100644 --- a/src/mazeforge.egg-info/PKG-INFO +++ b/src/mazeforge.egg-info/PKG-INFO @@ -25,9 +25,11 @@ 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 +Keywords: labyrinth,maze,pymaze,generation,generate,solve +Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 diff --git a/src/mazeforge.egg-info/SOURCES.txt b/src/mazeforge.egg-info/SOURCES.txt index 0a7af6a..bfa0b8b 100644 --- a/src/mazeforge.egg-info/SOURCES.txt +++ b/src/mazeforge.egg-info/SOURCES.txt @@ -3,11 +3,11 @@ MANIFEST.in README.md pyproject.toml src/mazeforge/__init__.py +src/mazeforge/base.py src/mazeforge/generator.py src/mazeforge.egg-info/PKG-INFO src/mazeforge.egg-info/SOURCES.txt src/mazeforge.egg-info/dependency_links.txt -src/mazeforge.egg-info/entry_points.txt src/mazeforge.egg-info/requires.txt src/mazeforge.egg-info/top_level.txt tests/test_generator.py \ No newline at end of file diff --git a/src/mazeforge.egg-info/entry_points.txt b/src/mazeforge.egg-info/entry_points.txt deleted file mode 100644 index e870c8c..0000000 --- a/src/mazeforge.egg-info/entry_points.txt +++ /dev/null @@ -1,2 +0,0 @@ -[console_scripts] -mazeforge = mazeforge.__main__:main diff --git a/src/mazeforge/__init__.py b/src/mazeforge/__init__.py index aa64110..f742c93 100644 --- a/src/mazeforge/__init__.py +++ b/src/mazeforge/__init__.py @@ -1,16 +1,22 @@ -"""MazeForge - -Contact: --------- +""" + MazeForge + ========= -- oskar.meyenburg@gmail.com + Provides + 1. Generation of mazes + 2. Solving of mazes + 3. Visualisation of mazes -More information is available at: + Contact + - oskar.meyenburg@gmail.com -- https://pypi.org/project/mazeforge/ -- https://github.com/oskarmeyenburg/mazeforge + More information + - https://pypi.org/project/mazeforge/ + - https://github.com/oskarmeyenburg/mazeforge """ from .generator import generate +from .base import Maze -__version__ = "0.1.0" \ No newline at end of file +__version__ = "0.1.0" +__all__ = ['Maze', 'generate'] diff --git a/src/mazeforge/base.py b/src/mazeforge/base.py new file mode 100644 index 0000000..9aa8cbe --- /dev/null +++ b/src/mazeforge/base.py @@ -0,0 +1,16 @@ +import numpy + + +class Maze(numpy.ndarray): + def __new__(cls, width, height): + # Create a new array with the specified dimensions and fill value + maze_array = numpy.full((height, width), 0, dtype=numpy.int_) + obj = maze_array.view(cls) + return obj + + @classmethod + def from_array(cls, array): + """ + Create a new Maze instance from an existing NumPy array + """ + return array.view(cls) \ No newline at end of file diff --git a/src/mazeforge/generator.py b/src/mazeforge/generator.py index 79bbe17..5889b5d 100644 --- a/src/mazeforge/generator.py +++ b/src/mazeforge/generator.py @@ -1,7 +1,22 @@ import random import numpy -def generate(width: int, height: int) -> numpy.array: +def generate(width: int, height: int) -> numpy.ndarray: + """ + Generate a 2d maze on a grid. + + Parameters + ---------- + width : int + Number of columns in the maze. + height : int + Number of rows in the maze. + + Returns + ------- + 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_)