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

Function checkIfPlayerReachedEnd

src/gamesbyexample/hexapawn.py:284–298  ·  view source on GitHub ↗

Return True if the player has reached the opposite end of the board and won. Otherwise return False.

(player, board)

Source from the content-addressed store, hash-verified

282
283
284def checkIfPlayerReachedEnd(player, board):
285 """Return True if the player has reached the opposite end of the
286 board and won. Otherwise return False."""
287 if player == X_PLAYER:
288 # Check if X has any pieces on the bottom row:
289 for x in range(board['width']):
290 if board[(x, board['height'] - 1)] == X_PLAYER:
291 return True
292 return False
293 elif player == O_PLAYER:
294 # Check if O has any pieces on the top row:
295 for x in range(board['width']):
296 if board[(x, 0)] == O_PLAYER:
297 return True
298 return False
299
300
301# If this program was run (instead of imported), run the game:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected