Assignment 7
Due: 11:00 AM on Friday, November 19, 2010/b>
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.
Hints
You may find the answer scripts for Assignment #4 of use.
Submission
Please hand in printed copies of all of your Python script files.
You must also submit these files electronically using the
submit-assignment command.
Note that each script file must have the following comment
block at the top, where the X's are replaced with the appropriate
information, followed by a docstring briefly describing the program in that
script. For instance, my script for Question #1 of this assignment would
begin with the following comment block:
#########################################################
## CS 2500 (Fall 2010), Assignment #7, Question #1 ##
## Script File Name: maze3.py ##
## Student Name: Todd Wareham ##
## Login Name: harold ##
## MUN #: 8008765 ##
#########################################################
If you choose to base your script on any answer-scripts for previous
assignments, please note this in the docstring.
You do not have to develop your code on our CS departmental systems.
However, as your code will be compiled and tested on our CS departmental
systems as part of the assignment marking process,
you should ensure that your code compiles and runs correctly on at
least one of these systems.
- Oct 7, 9:35am
Assignment #7 posted.
Created: October 7, 2010
Last Modified: October 20, 2010