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

Function displayBoard

src/gamesbyexample/barca.py:127–166  ·  view source on GitHub ↗

Display the board on the screen.

(board)

Source from the content-addressed store, hash-verified

125
126
127def displayBoard(board):
128 """Display the board on the screen."""
129 # A list of arguments to pass to format() to fill in the board
130 # template string's {}.
131 spaces = []
132 for y in range(BOARD_HEIGHT):
133 for x in range(BOARD_WIDTH):
134 if board[(x, y)] == EMPTY_SPACE:
135 # This space is an empty land or waterhole.
136 if (x, y) in WATERING_HOLES:
137 spaces.append(WATER)
138 else:
139 spaces.append(LAND)
140 else:
141 # This space has an animal piece on it.
142 spaces.append(getAnimalStr(board, x, y))
143
144 print("""
145 +--A---B---C---D---E---F---G---H---I---J-+
146 | |
147 1{}{}{}{}{}{}{}{}{}{}1
148 | |
149 2{}{}{}{}{}{}{}{}{}{}2
150 | |
151 3{}{}{}{}{}{}{}{}{}{}3
152 | |
153 4{}{}{}{}{}{}{}{}{}{}4
154 | |
155 5{}{}{}{}{}{}{}{}{}{}5
156 | |
157 6{}{}{}{}{}{}{}{}{}{}6
158 | |
159 7{}{}{}{}{}{}{}{}{}{}7
160 | |
161 8{}{}{}{}{}{}{}{}{}{}8
162 | |
163 9{}{}{}{}{}{}{}{}{}{}9
164 | |
16510{}{}{}{}{}{}{}{}{}{}10
166 +--A---B---C---D---E---F---G---H---I---J-+""".format(*spaces))
167
168
169def getAnimalStr(board, x, y):

Callers 1

mainFunction · 0.70

Calls 1

getAnimalStrFunction · 0.85

Tested by

no test coverage detected