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

Function pieceCanCaptureLeft

src/gamesbyexample/hexapawn.py:254–266  ·  view source on GitHub ↗

Return True if the player's piece at (x, y) on the board can capture the piece forward and left. Otherwise return False.

(player, x, y, board)

Source from the content-addressed store, hash-verified

252
253
254def pieceCanCaptureLeft(player, x, y, board):
255 """Return True if the player's piece at (x, y) on the board can
256 capture the piece forward and left. Otherwise return False."""
257 # Can this piece capture an opponent's piece?
258 if player == X_PLAYER: # X's "forward" is the space below.
259 # Check diagonally forward and left:
260 if (x - 1, y + 1) in board and board[(x - 1, y + 1)] == O_PLAYER:
261 return True
262 elif player == O_PLAYER: # O's "forward" is the space above.
263 # Check diagonally forward and left:
264 if (x - 1, y - 1) in board and board[(x - 1, y - 1)] == X_PLAYER:
265 return True
266 return False # This piece cannot capture.
267
268
269def pieceCanCaptureRight(player, x, y, board):

Callers 2

doPlayerMoveFunction · 0.85
getValidMovesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected