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

Function isWinner

src/gamesbyexample/barca.py:333–349  ·  view source on GitHub ↗

Return True if the player occupies three of the four watering holes on this board.

(player, board)

Source from the content-addressed store, hash-verified

331
332
333def isWinner(player, board):
334 """Return True if the player occupies three of the four watering
335 holes on this board."""
336 squareClaims = 0
337 roundClaims = 0
338 for space in WATERING_HOLES:
339 if board[space] in (SQUARE_MOUSE, SQUARE_LION, SQUARE_ELEPHANT):
340 squareClaims += 1
341 elif board[space] in (ROUND_MOUSE, ROUND_LION, ROUND_ELEPHANT):
342 roundClaims += 1
343
344 if player == SQUARE_PLAYER and squareClaims >= 3:
345 return True
346 elif player == ROUND_PLAYER and roundClaims >= 3:
347 return True
348 else:
349 return False
350
351
352# If the program is run (instead of imported), run the game:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected