def submit_card_command(instance, player, arguments):
  """ Submit a noun card for the current round.

  Args:
    instance: The GameInstance database model for this operation.
    player: The player submitting the card. Cannot be the leader.
    arguments: A two item list consisting of the round to submit this
      card for and the card itself.

  If the submission is for the wrong round, a four item list with an
  error string as its first element will be returned.  The remaining
  elements are the player's hand, the current round and the current
  characteristic card to respond to. No other action will be taken.

  Removes the indicated card from the player's hand and adds it
  to this round's submissions. The current submissions are sent via
  message to all players.

  The requesting player's hand will be dealt another card after
  removing the submitted one. The updated hand will be sent to the
  requesting player in a message and be included in the return value
  of this command.

  Returns:
    If the submission is for the correct round, returns a three item
    list consisting of the current round number, a list of the
    submissions made so far by other players in this round and the
    player's new hand.

  Raises:
    ValueError if player is the leader. The leader is not allowed to
    submit cards.
  """
  if int(arguments[0]) != instance.ata_round:
    hand = card_game.get_player_hand(instance, player)
    return ['You tried to submit a card for the wrong round. ' +
            'Please try again.', hand, instance.ata_round,
            instance.ata_char_card]

  missing_player = check_players(instance)
  if missing_player:
    return missing_player

  if player == instance.leader:
    raise ValueError("The leader may not submit a card.")

  submission = arguments[1]
  submissions = set_submission(instance, player, submission).values()
  instance.create_message(player, 'ata_submissions', '',
                          [instance.ata_round, submissions, submission]).put()

  card_game.discard(instance, player, [submission], False)
  hand = card_game.draw_cards(instance, player, 1)
  return [instance.ata_round, submissions, hand]
def end_turn_command(instance, player, arguments):
  """ End the current turn and start a new one.

  Args:
    instance: The GameInstance database model for this operation.
    player: The player submitting the card. Must be the current
    leader.
    arguments: A two item list consisting of the round number to end
      and the selected winning card.

  If the command is for the wrong round, a four item list with an
  error string as its first element will be returned.  The remaining
  elements are the player's hand, the current round and the current
  characteristic card to respond to. No other action will be taken.

  Ends the current turn and adds 1 point to the score of the player
  who submitted the winning card. If that player has reached the
  winning score, an 'ata_game_over' message will be sent to all
  players.  The game over message content will be a three item list as
  its contents. The list contains the final round number, the winning
  card and the final scoreboard.

  Otherwise, sends an 'ata_new_round' message to all players. The new
  round message contents will be a five item list with the round
  number, the new characteristic card, the previous round winner, the
  winning card and the current scoreboard.

  Returns:
    If the command was for the correct round, returns the content of
    whichever message was sent to all players as described above.
  Raises:
    ValueError if player is not the leader.
    KeyError if no player has submitted the winning card.
  """
  if int(arguments[0]) != instance.ata_round:
    hand = card_game.get_player_hand(instance, player)
    return ['You tried to end a turn that has already ended. ' +
            'Please try again.', hand, instance.ata_round,
            instance.ata_char_card]

  missing_player = check_players(instance)
  if missing_player:
    return missing_player

  instance.check_leader(player)
  card = arguments[1]
  winner = None
  for player, submitted_card in get_submissions_dict(instance).items():
    if card == submitted_card:
      winner = player
      break
  if winner == None:
    raise KeyError('No player has submitted the card %s.' % card)
  board = scoreboard.add_to_score(instance, winner, 1)

  # Check to see if anyone has won
  instance.leader = winner
  if board[winner] == winning_score:
    return end_game(instance, card)

  setup_new_round(instance)
  return_scoreboard = scoreboard.format_scoreboard_for_app_inventor(board)
  content = [instance.ata_char_card, return_scoreboard,
             instance.ata_round, winner, card]
  instance.create_message(instance.leader, 'ata_new_round', '', content).put()
  return content