The square cells of a rectangular grid are filled with one of the building blocks below, forming a roadmap. The possible building blocks are (from left to right) i) empty cells, ii) cells with one junction (end points), iii) cells with two opposite junctions (straight lanes), iv) cells with two adjacent junctions (curves) and v) cells with four junctions (crossroads). Each of these building blocks can be rotated over an angle of 90°. This gives four possible end points, two possible straight lanes (horizontal and vertical) and four possible curves. 

bouwstenen
Building blocks for building a street map: i) empty cell, ii) cell with one junction (an end point), iii) cell with two opposite junctions, iv) cell with two adjacent junctions (a curve) and v) cell with four junctions (crossroads).

The roadmap is built in such a way that neighbouring cells always have adjacent junctions. Moreover, the roadmap map always links two ending points, if we always continue straight ahead at every crossroads. All ending points are indicated with a unique uppercase letter.

stratenplan
Example of a roadmap that links the following ending points: A-B, C-D, E-F en G-H.

A roadmap with $$m$$ rows and $$n$$ columns can be saved in a text file of $$n$$ lines, that each consist of $$m$$ characters, as follows:

To determine whether a plus sign indicates a bow or a crossroads, you must verify the number of junctions a cell has with its neighbouring cells above, underneath, left and right. The file streetmap1.txt1, for example, contains the street map that was given as an example above.

Assignment

Define a class Streetmap that can be used to determine the positions of the ending points for a given street map that was saved in a text file, and which ending points are linked. The objects of the class must contain at least the following methods:

Example

For the below example session, we assume that the files streetmap1.txt2 and streetmap2.txt3 are in the current directory.

>>> map = RoadMap('roadmap1.txt')
>>> map.rows()
10
>>> map.columns()
28

>>> map.location('A')
(4, 0)
>>> map.location('F')
(7, 15)

>>> map.connection('A')
'B'
>>> map.connection('B')
'A'
>>> map.connection('C')
'D'
>>> map.connection('D')
'C'
>>> map.connection('E')
'F'
>>> map.connection('F')
'E'
>>> map.connection('G')
'H'
>>> map.connection('H')
'G'
>>> map.connection('X')
Traceback (most recent call last):
AssertionError: unknown end point

>>> map = RoadMap('roadmap2.txt')
>>> map.connection('A')
'B'
>>> map.connection('B')
'A'
>>> map.connection('C')
'D'
>>> map.connection('D')
'C'
>>> map.connection('E')
'F'
>>> map.connection('F')
'E'
>>> map.connection('G')
'H'
>>> map.connection('H')
'G'
>>> map.connection('X')
Traceback (most recent call last):
AssertionError: unknown end point