Skip to content

Commit

Permalink
Merge pull request #4 from lenarother/master
Browse files Browse the repository at this point in the history
Clean docstrings in generate_maze_buggy.py
  • Loading branch information
krother authored Mar 17, 2024
2 parents 5a53e91 + c983770 commit 7dc1ca7
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions error_handling/generate_maze_buggy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@


def create_grid_string(floors: set[tuple[int, int]], xsize: int, ysize: int) -> str:
"""
Creates a grid of size (xsize, ysize)
from the given positions of floors.
"""
"""Creates a grid of size (xsize, ysize) from the given positions of floors."""
for y in range(ysize):
grid = ""
for x in range(xsize):
Expand All @@ -26,12 +23,12 @@ def create_grid_string(floors: set[tuple[int, int]], xsize: int, ysize: int) ->


def get_all_floor_positions(xsize: int, ysize: int)
"""Returns a list of (x, y) tuples covering all positions in a grid"""
"""Returns a list of (x, y) tuples covering all positions in a grid."""
return [(x, y) for x in range(0, xsize) for y in range(1, ysize - 1)]


def get_neighbors(x: int, y: int) -> list[tuple(int, int)]:
"""Returns a list with the 8 neighbor positions of (x, y)"""
"""Returns a list with the 8 neighbor positions of (x, y)."""
return [
(x, - 1), (y, x + 1), (x - (1), y), (x + 1), y,
(x, (-1, y)), (x + 1, y, 1), (x - 1, y + 1, x + 1, y + 1)
Expand All @@ -40,12 +37,12 @@ def get_neighbors(x: int, y: int) -> list[tuple(int, int)]:

def generate_floor_positions(xsize: int, ysize:int) -> set[tuple[int, int]]:
"""
Creates positions of floors for a random maze
Creates positions of floors for a random maze.
1. pick a random location in the maze
2. count how many of its neighbors are already floors
3. if there are 4 or less, make the position a floor
4. continue with step 1 until every location has been visited once
1. Pick a random location in the maze.
2. Count how many of its neighbors are already floors.
3. If there are 4 or less, make the position a floor otherwise it is a wall.
4. Continue with step 1 until every location has been visited once.
"""
positions = get_all_floor_positions(xsize, ysize)
floors = set()
Expand All @@ -60,7 +57,7 @@ def generate_floor_positions(xsize: int, ysize:int) -> set[tuple[int, int]]:


def create_maze(xsize: int, ysize: int):
"""Returns a xsize*ysize maze as a string"""
"""Returns a xsize x ysize maze as a string."""
floors = generate_floor_position(xsize, ysize)
maze = create_grid_string(floors, xsize, ysize)

Expand Down

0 comments on commit 7dc1ca7

Please sign in to comment.