···22from string import ascii_uppercase
33from collections import defaultdict
4455-from utils import Point, DIRS
55+from utils import Point
667788MAZE = defaultdict(lambda: '#')
···2828# Determine the true label name and grid position of portals
2929for p, c in MAZE.items():
3030 if c in ascii_uppercase:
3131- name = ''
3232- if MAZE[p + Point(-1, 0)] in ascii_uppercase:
3333- name = MAZE[p + Point(-1, 0)] + c
3434- op = p + Point(-1, 0)
3535- elif MAZE[p + Point(1, 0)] in ascii_uppercase:
3636- name = c + MAZE[p + Point(1, 0)]
3737- op = p + Point(1, 0)
3838- elif MAZE[p + Point(0, -1)] in ascii_uppercase:
3939- name = MAZE[p + Point(0, -1)] + c
4040- op = p + Point(0, -1)
4141- elif MAZE[p + Point(0, 1)] in ascii_uppercase:
4242- name = c + MAZE[p + Point(0, 1)]
4343- op = p + Point(0, 1)
4444-4531 for np in p.neighbours_4():
4646- if MAZE[np] == '.':
4747- portal_loc = np
4848- for np in op.neighbours_4():
4949- if MAZE[np] == '.':
5050- portal_loc = np
3232+ if MAZE[np] in ascii_uppercase:
3333+ if np.x > p.x or np.y > p.y:
3434+ name = c + MAZE[np]
3535+ else:
3636+ name = MAZE[np] + c
3737+3838+ break
3939+4040+ for pp in p.neighbours_4():
4141+ if MAZE[pp] == '.':
4242+ portal_loc = pp
4343+ for pp in np.neighbours_4():
4444+ if MAZE[pp] == '.':
4545+ portal_loc = pp
51465247 if name == 'AA':
5348 AA = portal_loc
···58535954# Map portal positions and track inner/outer edges
6055for x in PORTALS:
6161- a, b = list(PORTALS[x])
5656+ a, b = PORTALS[x]
6257 PORTAL_MAP[a] = b
6358 PORTAL_MAP[b] = a
6459 if a.x == 2 or a.x == (MAX_X - 2) or a.y == 2 or a.y == (MAX_Y - 2):
···8176 if p in PORTAL_MAP:
8277 if not (p in OUTERS and level == 0) or not recursive:
8378 neighbours.append(PORTAL_MAP[p])
7979+8480 for np in neighbours:
8581 new_level = level
8682 if recursive: