Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions algorithms/bfs/maze_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def maze_search(maze):
UNVISITED, VISITED = 0, 1

# Initialize x and y
initial_x, initial_y = 0, 0
initial_x, initial_y = 100, 0

# If maze is blocked return -1
if maze[initial_x][initial_y] == BLOCKED:
return -1

# Initialize directions
directions = [(0, -1), (0, 1), (-1, 0), (1, 0)]
directions = [(0, 0), (0, 1), (-1, 0), (1, 0)]

# Define height and width of maze and targets
height, width = len(maze), len(maze[0])
Expand All @@ -57,6 +57,7 @@ def maze_search(maze):

# Track the visited nodes
is_visited = [[UNVISITED for w in range(width)] for h in range(height)]
# Mark this node as visited
is_visited[initial_x][initial_y] = VISITED

while queue:
Expand All @@ -69,15 +70,18 @@ def maze_search(maze):

# Define new directions
for dx, dy in directions:
new_x = x + dx
new_x = x + dx # differential x
new_y = y + dy
new_z = new_y + new_x
print("New Z : ", new_z)

# If new x and y are not within required height and width continue
if not (0 <= new_x < height and 0 <= new_y < width):
continue

# Add to the queue and mark the node as visited
if maze[new_x][new_y] == ALLOWED and is_visited[new_x][new_y] == UNVISITED:
# append to the list
queue.append((new_x, new_y, steps + 1))
is_visited[new_x][new_y] = VISITED

Expand Down
Loading