Can someone please help me troubleshoot this issue. I can't figure out why it's behaving as it is. I've got a maze generation script. I want the maze to generate on a grid, leaving borders on the top, bottom, left, and right - each 1-unit thick. The problem is that the the walls on the right and bottom sides are generating 2 units thick. Here is the main part of the maze generation script:
def get_neighbors(x, y):
neighbors = []
for direction in DIRECTIONS:
nx, ny = x + direction[0] * 2, y + direction[1] * 2
# Ensure that we are not going out of bounds and respect the maze's borders
if 1 <= nx <= COLS - 1 and 1 <= ny <= ROWS - 1 and not visited[ny][nx]:
neighbors.append((nx, ny))
random.shuffle(neighbors)
return neighbors
def generate_maze():
x, y = 1, 1
stack.append((x, y))
visited[y][x] = True
maze[y][x] = 0
while stack:
draw_maze()
pygame.display.update()
clock.tick(60)
x, y = stack[-1]
neighbors = get_neighbors(x, y)
if neighbors:
nx, ny = neighbors[0]
stack.append((nx, ny))
visited[ny][nx] = True
# Remove the wall between the current cell and the chosen cell
maze[(y + ny) // 2][(x + nx) // 2] = 0
maze[ny][nx] = 0
else:
stack.pop()
# Initialize maze grid with all walls, leaving borders intact
for row in range(ROWS):
for col in range(COLS):
if row == 0 or row == ROWS - 1 or col == 0 or col == COLS - 1:
maze[row][col] = 1 # Borders remain as walls
else:
maze[row][col] = 1 # Inside cells initially walls but will be carved