Question #1
Write and document a Python script maze3.py which re-implements
the maze-navigation program described in Question #1 of Assignment #4
using the following functions:
- readMaze(mazeFilename): Read in and return a nested-list representation of the 2D
maze stored in file mazeFilename.
- getPostStatus(maze, curX, curY): Given a nested-list representation of a maze and
X/Y-coordinates of a point on the 2D plane, return a string in the set {"outside maze",
"at goal", "in corridor", "inside wall"} describing the status of the given point
relative to the given maze.
- makeMazeMove(maze, curX, curY, move): Given a nested-list representation of a maze,
X/Y-coordinates of a point on the 2D plane, and a move-string in the set {"up", "down",
"left", "right"}, return a tuple (X,Y) describing the point reached by applying the
move to the given point.
All manipulation of the nested-list representation of the maze must occur within these
specified functions.
Your script must work on datafiles
maze1.dat,
maze2.dat,
move1.dat,
move2.dat,
move3.dat, and
move4.dat
to produce the output given in typescript-file
maze2.script.
You may assume that all maze and move files are valid.
Question #2
Write and document a Python script matm2.py which re-implements
the matrix-manipulation program described in Question #2 of Assignment #4
using the following functions:
- getMatrixIndex(matList, matName): Given a nested-list representation of a
matrix-list and a matrix name, return i if this matrix is stored at position i in
the list and -1 otherwise.
- readMatrix(matList, matName): Given a nested-list representation of a
matrix-list and a matrix name, read in and store this matrix in the matrix-list.
If that matrix is already in the matrix-list, overwrite the matrix-list version with
the file-version.
- getMatrixString(matList, matName): Given a nested-list representation of a
matrix-list and a matrix name, return a string describing the contents of that matrix
as stored in the matrix-list. If that matrix is not in the matrix-list, return the
null-string ("").
- incMatrix(matList, matName, val): Given a nested-list representation of a
matrix-list, a matrix name, and an integer value, increment all elements in that matrix as
stored in the matrix by the given value. Return True if the matrix is in the matrix-list
and False otherwise.
- appendRows(matList, matName1, matName2): Given a nested-list representation of a
matrix-list and two matrix names, append all rows of matName1 to matName2 in the matrix-list
and return True if the column-dimensions of the matrices match, and False otherwise.
- appendColumns(matList, matName1, matName2): Given a nested-list representation of a
matrix-list and two matrix names, append all columns of matName1 to matName2 in the matrix-list
and return True if the row-dimensions of the matrices match, and False otherwise.
All manipulation of the nested-list representation of the matrix-list must occur within these
specified functions.
Your script must work on datafiles
m1.mat,
m2.mat,
m3.mat, and
com1.txt
to produce the output given in typescript-file
matm1.script.
You may assume that all matrix files are valid.