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 xth digit of theyth linewithdigits,with0≤x
• n is to be associated with a point situated x × 0.5 cm to the right and y × 0.5 cm below an origin, • nistobeconnectedtothepoint0.5cmtoitsrightjustincasen=1orn=3,and
• nistobeconnectedtothepoint0.5cmbelowitselfjustincasen=2orn=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.5 cm below the origin with 0≤x < xdim −1 and 0≤y < ydim −1.
3.2 Output
Consider executing from the Python prompt the statement from maze import * followed by the state- ment maze = Maze(some_filename). In case some_filename does not exist in the working directory, then Python will raise a FileNotFoundError exception, that does not need to be caught. Assume that some_filename does exist (in the working directory). If the input is incorrect in that it does not contain only digits in {0, 1, 2, 3} besides spaces, or in that it contains either too few or too many nonblank lines, or in that some nonblank lines contain too many or too few digits, or in that two of its nonblank lines do not contain the same number of digits, then the effect of executing maze = Maze(some_filename) should be to generate a MazeError exception that reads
Traceback (most recent call last): ...
maze.MazeError: Incorrect input.
If the previous conditions hold but the further conditions spelled out above for the input to qualify as a maze (that is, the condition on the last digit on every line with digits and the condition on the digits on the last line) do not hold, then the effect of executing maze = Maze(some_filename) should be to generate a MazeError exception that reads
Traceback (most recent call last):
5
...
maze.MazeError: Input does not represent a maze.
If the input is correct and represents a maze, then executing maze = Maze(some_filename) should have the effect of outputting a first line that reads one of
The maze has no gate.
The maze has a single gate. The maze has N gates.
with N an appropriate integer at least equal to 2, a second line that reads one of
The maze has no wall.
The maze has walls that are all connected.
The maze has N sets of walls that are all connected.
with N an appropriate integer at least equal to 2, a third line that reads one of
The maze has no inaccessible inner point.
The maze has a unique inaccessible inner point. The maze has N inaccessible inner points.
with N an appropriate integer at least equal to 2, a fourth line that reads one of
The maze has no accessible area.
The maze has a unique accessible area. The maze has N accessible areas.
with N an appropriate integer at least equal to 2, a fifth line that reads one of
The maze has no accessible cul-de-sac.
The maze has accessible cul-de-sacs that are all connected.
The maze has N sets of accessible cul-de-sacs that are all connected.
with N an appropriate integer at least equal to 2, and a sixth line that reads one of
The maze has no entry-exit path with no intersection not to cul-de-sacs.
The maze has a unique entry-exit path with no intersection not to cul-de-sacs. The maze has N entry-exit paths with no intersections not to cul-de-sacs.
with N an appropriate integer at least equal to 2.
6
Agateisanypairofconsecutivepointsononeofthefoursidesofthemazethatarenotconnected.
An inaccessible inner point is an inner point that cannot be reached from any gate.
An accessible area is a maximal set of inner points that can all be accessed from the same gate (so the number of accessible inner points is at most equal to the number of gates).
A set of accessible cul-de-sacs that are all connected is a maximal set S of connected inner points that can all be accessed from the same gate g and such that for all points p in S, if p has been accessed from g for the first time, then either p is in a dead end or moving on without ever getting back leads into a dead end.
An entry-exit path with no intersections not to cul-de-sacs is a maximal set S of connected inner points that go from a gate to another (necessarily different) gate and such that for all points p in S, there is only one way to move on from p without getting back and without entering a cul-de-sac.
Pay attention to the expected format, including spaces.
If the input is correct and represents a maze, then executing maze = Maze(some_filename) followed by maze.display() should have the effect of producing a file named some_filename.tex that can be given as argument to pdflatex to generate a file named some_filename.pdf. The provided examples will show you what some_filename.tex should contain.
Walls are drawn in blue. There is a command for every longest segment that is part of a wall. Horizontal segments are drawn starting with the topmost leftmost segment and finishing with the bottommost rightmost segment. Then vertical segments are drawn starting with the topmost leftmost segment and finishing with the bottommost rightmost segment.
Pillarsaredrawnasgreencircles.
Inner points in accessible cul-de-sacs are drawn as red crosses.
The paths with no intersection not to cul-de-sacs are drawn as dashed yellow lines. There is a command for every longest segment on such a path. Horizontal segments are drawn starting with the topmost leftmost segment and finishing with the bottommost rightmost segment, with those segments that end at a gate sticking out by 0.25 cm. Then vertical segments are drawn starting with the topmost leftmost segment and finishing with the bottommost rightmost segment, with those segments that end at a gate sticking out by 0.25 cm.
Pay attention to the expected format, including spaces and blank lines. Lines that start with % are comments; there are 4 such lines, that have to be present even when there is no item to be displayed of the kind described by the comment. The output of your program redirected to a file will be compared with the expected output saved in a file (of a different name of course) using the diff command. For your program to pass the associated test, diff should silently exit, which requires that the contents of both files be absolutely identical, character for character, including spaces and blank lines. Check your program on the provided examples using the associated .tex files, renaming them as they have the names of the files expected to be generated by your program.
7
4 Submission and assessment 4.1 Submission
Your program will be stored in a file which has to be named maze.py. Your code can be submitted more than once on Ed. The last version and only the last version will be downloaded, run, tested and marked. Your assignment is due by Monday 22 November 2021 @ 10:00am (Week 11).