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

Function makeMove

src/gamesbyexample/slidingtilepuzzle.py:96–108  ·  view source on GitHub ↗

Carry out the given move on the given board.

(board, move)

Source from the content-addressed store, hash-verified

94
95
96def makeMove(board, move):
97 """Carry out the given move on the given board."""
98 # Note: This function assumes that the move is valid.
99 bx, by = findBlankSpace(board)
100
101 if move == 'W':
102 board[bx][by], board[bx][by+1] = board[bx][by+1], board[bx][by]
103 elif move == 'A':
104 board[bx][by], board[bx+1][by] = board[bx+1][by], board[bx][by]
105 elif move == 'S':
106 board[bx][by], board[bx][by-1] = board[bx][by-1], board[bx][by]
107 elif move == 'D':
108 board[bx][by], board[bx-1][by] = board[bx-1][by], board[bx][by]
109
110
111def makeRandomMove(board):

Callers 2

mainFunction · 0.70
makeRandomMoveFunction · 0.70

Calls 1

findBlankSpaceFunction · 0.85

Tested by

no test coverage detected