10 ....|
11 ....|
11 ....|
11 ....|
11 ....|
11 ....|
11 .../.
11 ../..'''.strip()) # Paste to 0, 0.
11
11 CLOSED['F'] = wallStrToWallDict(r'''
11 ../..
12 _/...
12 |....
12 |....
12 |....
12 |....
12 |....
12 |....
12 |....
12 |....
12 |....
13 .\...
13 ..\..'''.strip()) # Paste to 12, 0.
13
13 def displayWallDict(wallDict):
13 """Display a wall dictionary, as returned by wallStrToWallDict(), on
13 the screen."""
13 print(BLOCK * (wallDict['width'] + 2))
13 for y in range(wallDict['height']):
13 print(BLOCK, end='')
13 for x in range(wallDict['width']):
14 wall = wallDict[(x, y)]
14 if wall == '.':
14 wall = ' '
14 print(wall, end='')
14 print(BLOCK) # Print block with a newline.
14 print(BLOCK * (wallDict['width'] + 2))
14
14
14 def pasteWallDict(srcWallDict, dstWallDict, left, top):
14 """Copy the wall representation dictionary in srcWallDict on top of
15 the one in dstWallDict, offset to the position given by left, to"""
15 dstWallDict = copy.copy(dstWallDict)
15 for x in range(srcWallDict['width']):
15 for y in range(srcWallDict['height']):
15 dstWallDict[(x + left, y + top)] = srcWallDict[(x, y)]
15 return dstWallDict
15
15
15 def makeWallDict(maze, playerx, playery, playerDirection, exitx, exity):
15 """From the player's position and direction in the maze (which has
16 an exit at exitx, exity), create the wall representation dictionary
16 by pasting wall dictionaries on top of ALL_OPEN, then return it."""
16
16 # The A-F "sections" (which are relative to the player's direction)
16 # determine which walls in the maze we check to see if we need to
16 # paste them over the wall representation dictionary we're creating.
16
16 if playerDirection == NORTH:
16 # Map of the sections, relative A
16 # to the player @: BCD (Player facing north)
17 # E@F
17 offsets = (('A', 0, -2), ('B', -1, -1), ('C', 0, -1),
17 ('D', 1, -1), ('E', -1, 0), ('F', 1, 0))
17 if playerDirection == SOUTH:
17 # Map of the sections, relative F@E
17 # to the player @: DCB (Player facing south)
17 # A
17 offsets = (('A', 0, 2), ('B', 1, 1), ('C', 0, 1),
17 ('D', -1, 1), ('E', 1, 0), ('F', -1, 0))
17 if playerDirection == EAST:
18 # Map of the sections, relative EB
18 # to the player @: @CA (Player facing east)
18 # FD
18 offsets = (('A', 2, 0), ('B', 1, -1), ('C', 1, 0),
18 ('D', 1, 1), ('E', 0, -1), ('F', 0, 1))
18 if playerDirection == WEST:
18 # Map of the sections, relative DF
18 # to the player @: AC@ (Player facing west)
18 # BE
18 offsets = (('A', -2, 0), ('B', -1, 1), ('C', -1, 0),
19 ('D', -1, -1), ('E', 0, 1), ('F', 0, -1))
19
19 section = {}
19 for sec, xOff, yOff in offsets:
19 section[sec] = maze.get((playerx + xOff, playery + yOff), WALL)
19 if (playerx + xOff, playery + yOff) == (exitx, exity):
Do'stlaringiz bilan baham: |