liveBook · Manning

Game_over

As explained in Learn AI-Assisted Python Programming, Second Edition

game_over is a book-specific Python function that determines whether the Bogart game has ended from player chip counts and recent dice rolls.

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:

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

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Defines three termination conditions and implements them as one Boolean expression, without decomposing the check into subtasks.
Examples
Uses the Bogart game, chip totals, five-roll sequences, and explicit if-else versus direct-return implementations.
What you can do after
Build it from scratch as a Python predicate that reports whether the Bogart game has ended.
How it connects
Connects functions, Boolean expressions, while loops, player switching, and dice rolls.

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.