Takes a string representation of a wall drawing (like those in ALL_OPEN or CLOSED) and returns a representation in a dictionary with (x, y) tuples as keys and single-character strings of the character to draw at that x, y location.
(wallStr)
| 18 | |
| 19 | |
| 20 | def wallStrToWallDict(wallStr): |
| 21 | """Takes a string representation of a wall drawing (like those in |
| 22 | ALL_OPEN or CLOSED) and returns a representation in a dictionary |
| 23 | with (x, y) tuples as keys and single-character strings of the |
| 24 | character to draw at that x, y location.""" |
| 25 | wallDict = {} |
| 26 | height = 0 |
| 27 | width = 0 |
| 28 | for y, line in enumerate(wallStr.splitlines()): |
| 29 | if y > height: |
| 30 | height = y |
| 31 | for x, character in enumerate(line): |
| 32 | if x > width: |
| 33 | width = x |
| 34 | wallDict[(x, y)] = character |
| 35 | wallDict['height'] = height + 1 |
| 36 | wallDict['width'] = width + 1 |
| 37 | return wallDict |
| 38 | |
| 39 | EXIT_DICT = {(0, 0): 'E', (1, 0): 'X', (2, 0): 'I', |
| 40 | (3, 0): 'T', 'height': 1, 'width': 4} |