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

Function getValidMoves

src/gamesbyexample/hexapawn.py:227–238  ·  view source on GitHub ↗

Return a list of board space labels that have a player piece that can make a move.

(player, board)

Source from the content-addressed store, hash-verified

225
226
227def getValidMoves(player, board):
228 """Return a list of board space labels that have a player piece
229 that can make a move."""
230 validMoves = []
231 for x in range(board[WIDTH]):
232 for y in range(board[HEIGHT]):
233 if board[(x, y)] == player:
234 if (pieceCanAdvance(player, x, y, board) or
235 pieceCanCaptureLeft(player, x, y, board) or
236 pieceCanCaptureRight(player, x, y, board)):
237 validMoves.append(getNthLetter(x) + str(y + 1))
238 return validMoves
239
240
241def pieceCanAdvance(player, x, y, board):

Callers 2

mainFunction · 0.70
doPlayerMoveFunction · 0.70

Calls 4

pieceCanAdvanceFunction · 0.85
pieceCanCaptureLeftFunction · 0.85
pieceCanCaptureRightFunction · 0.85
getNthLetterFunction · 0.85

Tested by

no test coverage detected