Assignment 4
Due: 11:00 AM on Friday, October 17, 2008
Question #1
Consider the following advanced version of the maze-navigation script
described in Question #2 of Assignment #2: Maze and move files are as
previously described, but now, instead of just evaluating where the
status of the final position, you must also also evaluate and print the
co-ordinates and status resulting from each move and terminate the
move-sequence if the current move is onto a segment of maze wall. If all
moves are valid, the status of the final position is printed as before.
Write and document a Python script maze2.py which takes as
command-line arguments a maze file, a move file, and starting X- and
Y-co-ordinates on the 2-D integer plane and implements this version.
Your script must work on datafile
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
Consider the following design for a 2D integer matrix manipulation system:
All matrices manipulated by this system are stored as files in which each
line is a space-separated list of integers. Each such file has a name
of the form (matName + ".mat"). The system itself accepts the
following commands:
- read M: Read matrix with name M into system from file.
If matrix already stored in system, overwrite with file contents.
- print M: Display stored matrix with name M on terminal.
Print error if this matrix is not currently stored.
- dimensions M: Display row and column dimensions of matrix with name
M on terminal. Print error if this matrix is not currently stored.
- add X to matName: Add X to each entry of stored matrix with name
M. Print error if matrix is not currently stored.
- append columns of M1 to M2: Replace stored matrix named M2 with the
version of M2 in which the columns of M1 have been appended to
M2. Print errors if source (M1) or target (M2) matrices
not currently stored or if the operation is invalid, i.e., the
row dimensions of M1 and M2 do not match.
- append rows of M1 to M2: Replace stored matrix named M2 with the
version of M2 in which the rows of M1 have been appended to
M2. Print errors if source (M1) or target (M2) matrices
not currently stored or if the operation is invalid, i.e., the
column dimensions of M1 and M2 do not match.
Write and document a Python script matm1.py implementing the system
described above which takes as a command-line argument a text file of system commands
and executes those command, printing results or error messages as appropriate.
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 various example scripts in the course notes of use.
In Question #1, you may find it useful to modify the script written
(either by you or the course instructor) for Question #2 of
Assignment #2 to use a nest-listed matrix representation of the maze.
In Question #2, you may find it useful to store 2D matrices in the
system as a
list of matrix-descriptions, where each matrix-description
is a four-element list consisting of the matrix name, the number
of rows, the number of columns, and a list of the rows in that
matrix.
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 2008), Assignment #4, Question #1 ##
## Script File Name: maze2.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.
- Sep 30, 10:05am
Assignment #4 posted.
Created: September 30, 2008
Last Modified: September 30, 2008