MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / wallStrToWallDict

Function wallStrToWallDict

src/gamesbyexample/mazerunner3d.py:20–37  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

18
19
20def 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
39EXIT_DICT = {(0, 0): 'E', (1, 0): 'X', (2, 0): 'I',
40 (3, 0): 'T', 'height': 1, 'width': 4}

Callers 1

mazerunner3d.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected