game_over is a Bogart game function that checks whether either player has reached 30 chips or the current player has rolled five dice without rolling a 1. section 10.4.2 section 10.4.3
The function accepts three inputs and returns one Boolean result:
- player1: Player 1's current chip count. section 10.4.3
- player2: Player 2's current chip count. section 10.4.3
- rolls: the most recent list of dice rolls. section 10.4.2
- Returns True when any ending condition holds; otherwise returns False. section 10.4.3
Direct Boolean expression
def game_over(player1, player2, rolls): return player1 >= 30 or player2 >= 30 or \ (len(rolls) == 5 and not 1 in rolls) The expression combines chip thresholds with the five-roll condition. Returning the expression directly produces the same result as writing explicit if and else branches. section 10.4.3
Listing 10.6 game_over function in Bogart
def game_over(player1, player2, rolls):
'''
player1 is the number of chips that player 1 has.
player2 is the number of chips that player 2 has.
rolls is the last list of dice rolls.
Return True if the game is over, False otherwise.
The game is over if player1 has at least 30 chips,
or player 2 has at least 30 chips,
or there are 5 rolls none of which is a 1.
'''
return player1 >= 30 or player2 >= 30 or \ #1
(len(rolls) == 5 and not 1 in rolls) #1
Browse the complete game_over implementation and its docstring. section 10.4.3
