I am trying to write a script using python to solve a maze problem by the right hand method. I have written the below script to read in a file of the maze and put it into numpy 2D array. Now, I would like to search the first row of the array and find the 0. This 0 is the starting point of the maze. From here I would apply my maze algorithm to check the squares sourronding that point on whether or not they have a 1 or 0.
Maze_matrix is the matrix containing my maze and I want to find the index of the first 0 in the first row.
#!/usr/bin/python
import sys
import numpy as np
import itertools
if len(sys.argv) == 3:
maze_file = sys.argv[1]
soln_file = sys.argv[2]
rows = []
columns = []
with open(maze_file) as maze_f:
for line in maze_f:
row, column = line.split()
row = int(row)
column = int(column)
rows.append(row)
columns.append(column)
maze_matrix = np.zeros((rows[0], columns[0]))
for line1, line2 in zip(rows[1:], columns[1:]):
maze_matrix[line1][line2] = 1
print maze_matrix
else:
print('Usage:')
print(' python {} <maze file> <solution file>'.format(sys.argv[0]))
sys.exit()