Carry out a move on the given board.
(board, move)
| 167 | |
| 168 | |
| 169 | def 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 | |
| 197 | def hasWon(board): |