I uploaded a txt file (a maze) to my code in Python.
Example:
10 8
+-+-+-+-+-+-+-+-+-+-+
|* | |
+ +-+-+ + +-+ + +
| | |X | |
+-+ + +-+ +-+-+ +
| | | |
+-+-+-+-+ + + +-+ +
| | | | |
+ +-+-+ +-+ +-+ + +
| | | | | |
+ + +-+-+ + + +-+ +
| | | | | | | |
+ +-+ + +-+ +-+ + +
| | | | | |
+ +-+-+-+-+ + +-+ +
| |
+-+-+-+-+-+-+-+-+-+-+
I am willing to save the first row - the dimensions of the maze. The code I wrote works only when I have one number on each dimen. How can I get the dimension no matter how many numbers in each dimen. At the example above I want to get 10 & 8.
My code:
def loadMaze(file_name):
readIt = open(file_name, 'r')
readLines = readIt.readlines()
x_dim = int(readLines[0][0])
y_dim = int(readLines[0][2])
mazeList = [list(i.strip()) for i in readLines[1:]]
return x_dim, y_dim, mazeList