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

Function askForPlayerMove

src/gamesbyexample/reversegam.py:184–205  ·  view source on GitHub ↗

Let the player type in their move. Returns the move as [x, y] (or returns the string 'QUIT')

(board)

Source from the content-addressed store, hash-verified

182
183
184def askForPlayerMove(board):
185 """Let the player type in their move. Returns the move as [x, y]
186 (or returns the string 'QUIT')"""
187 while True:
188 print('Enter your move, or type quit to end the game.')
189 move = input('> ').upper()
190 if move == 'QUIT':
191 return 'QUIT'
192
193 if len(move) == 2 and move[0] in COLS and move[1] in ROWS:
194 x = 'ABCDEFGH'.find(move[0])
195 y = int(move[1]) - 1
196 if isValidMove(board, HUMAN, x, y) == False:
197 print('That is not a valid space to place a tile.')
198 continue
199 else:
200 break
201 else:
202 print('Type the column (A-H) and row (1-8).')
203 print('For example, H1 will be the top-right corner.')
204
205 return (x, y)
206
207
208def makeMove(board, tile, xstart, ystart):

Callers 1

mainFunction · 0.70

Calls 1

isValidMoveFunction · 0.70

Tested by

no test coverage detected