For a university assignment I was asked to convert a 1 line text file into a 2d array. However, when I run the program, I get this error:
(venv) D:Uni StuffYear 2AIGPAssignmentPYTHONASSIGNMEN>python astar.py
Input file name: Lab9TerrainFile1.txt
Traceback (most recent call last):
File "D:Uni StuffYear 2AIGPAssignmentPYTHONASSIGNMENastar.py", line 129, in <module>
main()
File "D:Uni StuffYear 2AIGPAssignmentPYTHONASSIGNMENastar.py", line 110, in main
number_of_rows = maze_file[1]
IndexError: index 1 is out of bounds for axis 0 with size 1
This is the code for generating the maze:
def main():
maze_file = open(input("Input file name: "), "r").readlines()
maze_file = np.array([maze_file])
number_of_columns = maze_file[0]
number_of_rows = maze_file[1]
maze_column = np.array_split(maze_file[2:8], number_of_columns)
maze_row = np.array_split(maze_file[2:8], number_of_rows)
maze = np.concatenate([maze_column][maze_row])
start = np.where(maze == 2)
end = np.where(maze == 3)
maze_file.close()
path = astar(maze, start, end)
print(path)
Any help would be appreciated and thank you!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…