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

Function makeMove

src/gamesbyexample/parkingvalet.py:169–194  ·  view source on GitHub ↗

Carry out a move on the given board.

(board, move)

Source from the content-addressed store, hash-verified

167
168
169def makeMove(board, move):
170 """Carry out a move on the given board."""
171 validMoves = getValidMoves(board)
172 if move not in validMoves:
173 return False
174
175 car = move[0]
176 direction = move[1]
177
178 newCarPositions = []
179
180 for x in range(board['width']):
181 for y in range(board['height']):
182 if board[(x, y)] == car:
183 board[(x, y)] = '.'
184 if direction == 'U':
185 newCarPositions.append((x, y - 1))
186 elif direction == 'D':
187 newCarPositions.append((x, y + 1))
188 elif direction == 'L':
189 newCarPositions.append((x - 1, y))
190 elif direction == 'R':
191 newCarPositions.append((x + 1, y))
192
193 for newCarPosition in newCarPositions:
194 board[newCarPosition] = car
195
196
197def hasWon(board):

Callers 1

mainFunction · 0.70

Calls 1

getValidMovesFunction · 0.70

Tested by

no test coverage detected