def list_votes(g, *args):
    """
    Print a list of all the people alive.

    votes is a dictionary with-
    key: voter_id
    value: voted_on_id

    """
    votes = get_all_votes(g)
    out_list = []
    if votes:
        u = UserMap()
        # turn id's into names
        # voter ' voted ' votee
        for v_id in votes.keys():
            voter_name = u.get(user_id=v_id)
            votee_name = u.get(user_id=votes[v_id])
            if votee_name:
                tmp = voter_name + ' voted ' + votee_name
            else:
                tmp = voter_name + ' passed.'
            out_list.append(tmp)

        return '\n'.join(out_list), None

    return 'Cannot list votes now.', None
def resolve_votes(g):
    """
    Everyone has voted.

    If anyone has more than half the votes.
    They die.

    If more than half the people passed then no one dies.

    votes is a dictionary
    key   - voter_id
    value - voted_on_id
    """
    votes = get_all_votes(g)
    # count up all the votes
    if votes:
        c = Counter(votes.values())
        # c.most_common()
        # [('b',2), ('a',1), ('c',1)]
        most_votes_id = c.most_common()[0][0]
        most_votes_count = c[most_votes_id]
        total_votes = len(votes.keys())
        if most_votes_count > total_votes // 2:
            # more than half the votes
            # they die.
            if most_votes_id == 'pass':
                return False # no one dies
            else:
                return most_votes_id

        else:
            return False

    return False # votes was none for some reason.
def should_countdown(user_id, action, game_state):
    """Check if we can start a countdown. To do so it must be day and the command must come
   from a player in the game.
   """
    if status.get_current_round(game_state) != "day":
        return False, RESPONSE['not_day']

    elif not status.is_player_alive(game_state, user_id):
        return False, RESPONSE['no_countdown']

    elif len(status.get_all_alive(game_state)) - 1 == len(
            status.get_all_votes(game_state).keys()):
        return True, None

    else:
        return False, RESPONSE['no_countdown']
 def can_countdown():
    """
    Must be day.
    Must be one player left to vote.
    """
    if get_current_round(g) != "day":
        return False, 'It is not day.'
    elif not is_player_alive(g, user_id):
        return False, 'You are not in the game.'
    # get list of all alive
    # get list of votes
    # if list of votes == all alive - 1
    elif len(get_all_alive(g))- 1 == len(get_all_votes(g).keys()):
        return True, None
    else:
        return False, 'Can not start countdown now.'
def list_votes(game_state, *kwargs):
    """List all votes from players int he game."""
    votes = status.get_all_votes(game_state)

    out_list = []
    if votes:
        user_map = UserMap()
        for voter_id in votes.keys():
            voter_name = user_map.get(user_id=voter_id)
            votee_name = user_map.get(user_id=votes[voter_id])

            if votee_name:
                vote_mess = voter_name + ' voted ' + votee_name
            else:
                vote_mess = voter_name + ' passed'

            out_list.append(vote_mess)

        return '\n'.join(out_list), None

    return 'Cannot list votes now', None
def resolve_votes(game_state):
    """Reconcile all the votes, lynching the player with the majority of the votes."""
    votes = status.get_all_votes(game_state)

    if votes:
        count = Counter(votes.values())

        most_votes_id = count.most_common()[0][0]
        most_votes_count = count[most_votes_id]
        total_votes = len(votes.keys())

        if most_votes_count > total_votes // 2:
            if most_votes_id == 'pass':
                return False

            else:
                return most_votes_id

        else:
            return False

    # we shouldn't ever really get here
    return False