COMP9021 Principles of Programming Term 1, 2024
Assignment 2
Worth 13 marks and due Week 11 Monday @ 10am
1. General Matters 1.1 Aim
Copyright By PowCoder代写 加微信 powcoder
The purpose of this assignment is to design and implement a program that will:
• analyse the various characteristics of a maze, represented by a particular coding of its basic constituents into numbers, from the set {0,1,2,3} only, stored in a file whose contents is read, and
• either output those characteristics, or
• output some Latex code in a text file, from which a pictorial representation of
the maze can be produced.
• use object-oriented programming.
1.2 Marking
This assignment is worth 13 marks distributed approximately as follows:
Your program will be tested against several inputs. For each test, the auto-marking script will let your program run for 30 seconds. The outputs of your program should be exactly as indicated.
1.3 Due Date and Submission
Your program will be stored in a file named maze.py. The assignment can be submitted more than once. The last version just before the due date and time will be marked (unless you submit late in which case the last late version will be marked).
Assignment 2 is due Week 11 Monday 22 April 2024 @ 10:00am (Sydney time)
Note that late submission with 5% penalty per day is allowed up to 5 days from the due date, that is,
any late submission after Week 11 Saturday 27 April 2024 @ 10:00am will be discarded.
Make sure not to change the filename maze.py while submitting by clicking on [Mark] button in Ed. It is your responsibility to check that your submission did go through properly using Submissions link in Ed otherwise your mark will be zero for Assignment 2.
Please note that the testing is done in two steps. You can test part 1 of the assignment in “Assignment 2: for testing of part 1 and for submission” on the sample inputs.
Your submission will NOT be downloaded from “Assignment 2: NOT for submission, for testing of part 2 ONLY” for marking. You can ONLY test part 2 of the assignment in “Assignment 2: NOT for submission, for testing of part 2 ONLY” on the sample inputs.
Please also note that your submission for BOTH PART 1 AND PART 2 will be downloaded from “Assignment 2: for testing of part 1 and for submission” for marking.
1.4 Reminder on Plagiarism Policy
You are permitted, indeed encouraged, to discuss ways to solve the assignment with other people. Such discussions must be in terms of algorithms, not code. But you must implement the solution on your own. Submissions are scanned for similarities that occur when students copy and modify other people’s work or work very closely together on a single implementation. Severe penalties apply.
2. Description
The representation of the maze is based on a coding with the four digits 0, 1, 2 and 3 such that:
• 0codespointsthatareconnectedtoneithertheirrightnortheirbelowneighbours.
• 1codespointsthatareconnectedtotheirrightneighboursbutnottotheirbelowones: • 2codespointsthatareconnectedtotheirbelowneighboursbutnottotheirrightones: • 3codespointsthatareconnectedtoboththeirrightandbelowneighbours:
A point that is connected to none of their left, right, above, and below neighbours represents a pillar:
Analysing the maze will allow you to also represent:
• cul-de-sacs:
• certain kinds of paths:
3. Examples
3.1 First example
The file named maze_1.txt has the following contents:
10221230 32212022 30113100 20300120 32201232 10011000
Here is a possible interaction:
>>> from maze import *
>>> maze = Maze(‘maze_1.txt’)
>>> maze.analyse()
The maze has 12 gates.
The maze has 8 sets of walls that are all connected. The maze has 2 inaccessible inner points.
The maze has 4 accessible areas.
The maze has 3 sets of accessible cul-de-sacs that are all connected.
The maze has a unique entry-exit path with no intersection not to cul-de-sacs. >>> maze.display()
The effect of executing maze.display() is to produce a file named maze_1.tex that can be given as argument to pdflatex to produce a file named maze_1.pdf that views as follows:
3.2 Second example
The file named maze_2.txt has the following contents:
022302120222 222223111032 301322130302 312322232330 001000100000
Here is a possible interaction:
$ python3 …
>>> from maze import *
>>> maze = Maze(‘maze_2.txt’)
>>> maze.analyse()
The maze has 20 gates.
The maze has 4 sets of walls that are all connected. The maze has 4 inaccessible inner points.
The maze has 13 accessible areas.
The maze has 11 sets of accessible cul-de-sacs that are all connected. The maze has 5 entry-exit paths with no intersections not to cul-de-sacs. >>> maze.display()
The effect of executing maze.display() is to produce a file named maze_2.tex that can be given as argument to pdflatex to produce a file named maze_2.pdf that views as follows:
3.3 Third example
The file named labyrinth.txt has the following contents:
31111111132 21122131202 33023022112 20310213122 31011120202 21230230112 30223031302 03122121212 22203110322 22110311002 11111101110
Here is a possible interaction:
$ python3 …
>>> from maze import *
>>> maze = Maze(‘labyrinth.txt’)
>>> maze.analyse()
The maze has 2 gates.
The maze has 2 sets of walls that are all connected. The maze has no inaccessible inner point.
The maze has a unique accessible area.
The maze has 8 sets of accessible cul-de-sacs that are all connected.
The maze has a unique entry-exit path with no intersection not to cul-de-sacs. >>> maze.display()
The effect of executing maze.display() is to produce a file named labyrinth.tex that can be given as argument to pdflatex to produce a file named labyrinth.pdf that views as follows:
4. Detailed description 4.1 Input
The input is expected to consist of ydim lines of xdim members of {0, 1, 2, 3}, where xdim and ydim are at least equal to 2 and at most equal to 31 and 41, respectively, with possibly lines consisting of spaces only that will be ignored and with possibly spaces anywhere on the lines with digits. If n is the x-th digit of the y-th line with digits, with 0 ≤x < xdim and 0 ≤y < ydim then
• n is to be associated with a point situated x x 0.5 cm to the right and y x 0.5 cm below an origin,
• n is to be connected to the point 0.5 cm to its right just in case n = 1 or n = 3, and
• n is to be connected to the point 0.5 cm below itself just in case n = 2 or n = 3.
The last digit on every line with digits cannot be equal to 1 or 3, and the digits on the last line with digits cannot be equal to 2 or 3, which ensures that the input encodes a maze, that is, a grid of width (xdim - 1) × 0.5 cm and of height (ydim - 1) × 0.5 cm (hence of maximum width 15 cm and of maximum height 20 cm), with possibly gaps on the sides and inside.
A point not connected to any of its neighbours is thought of as a pillar; a point connected to at least one of its neighbours is thought of as part of a wall.
We talk about inner point to refer to a point that lies (x + 0.5) × 0.5 cm to the right of and (y + 0.5) × 0.5cmbelowtheoriginwith0≤x