def make_new_poll_command(instance, player, arguments): """ Make a new poll. Args: instance: The game instance to add the poll to. player: The email of the player creating the poll. arguments: A two item list containing the question and a second list of 2-5 options. Returns: Returns a list with information about the poll just created. See get_poll_return_list for its format. Raises: ValueError if the player is not in the instance. """ instance.check_player(player) if not arguments[0]: raise ValueError('Question cannot be empty') size = len(arguments[1]) if size < 2 or size > 5: raise ValueError('Incorrect number of options for poll. ' + 'Must be between two and five.') poll = Message(parent = instance, sender = player, msg_type = 'poll', recipient = '') poll.put() arguments.append(poll.key().id()) poll.content = simplejson.dumps(arguments) poll.votes = [0] * size poll.open = True poll.voters = [''] poll.put() return get_poll_return_list(poll)
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()]