def new_game_command(instance, player, arguments = None): """ Start a new game and reset any game in progress. Args: instance: The GameInstance database model for this operation. player: The player starting a new game. Must be the only player in the instance. arguments: Not used, can be any value. Returns: A list containing the number of guesses remaining, the starting score of the player, the player's historical high score and the number of games completed in the past. Raises: ValueError if there is more than 1 player in the instance or the player is not the current leader. """ old_games = instance.get_messages_query('bac_game', player, sender = player, keys_only = True) db.delete(old_games) score = scoreboard.get_score(instance, player) if (score == 0): # Score is [high score, total score, games played] score = [0, 0, 0] scoreboard.set_score(instance, player, score) game = Message(parent = instance, sender = player, msg_type = 'bac_game', recipient = player) game.bac_solution = sample(colors, solution_size) game.bac_guesses_remaining = starting_guesses game.bac_score = solution_size * starting_guesses * 2 game.bac_last_guess = [''] game.bac_last_reply = '' game.put() return [game.bac_guesses_remaining, game.bac_score, score, game.key().id()]