def vote(user_id, action, game_state, target_name):
    user_map = UserMap()
    target_id = user_map.get(name=target_name)
    user_name = user_map.get(user_id)

    if not status.player_in_game(game_state, user_id):
        return False, RESPONSE['u_not_in_game']

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

    if status.get_current_round(game_state) != 'day':
        return False, RESPONSE['not_day']

    if target_name == 'pass':
        return True, user_name + RESPONSE['pass']

    if not status.player_in_game(game_state, target_id):
        return False, RESPONSE['t_not_in_game']

    if not status.is_player_alive(game_state, target_id):
        return False, RESPONSE['t_not_alive']

    if status.has_voted(game_state, user_id):
        return True, user_name + ' changed vote to ' + '*' + target_name + '*'

    return True, user_name + ' voted for ' + '*' + target_name + '*'
    def vote():
        # 1) Make sure player who made the command
        # is in the game
        if not player_in_game(g, user_id):
            return False, MSG['u_not_in_game']
        # is alive
        if not is_player_alive(g, user_id):
            return False, MSG['u_not_alive']
        # only valid during day
        if get_current_round(g) != 'day':
            return False, MSG['not_day']

        # if target_name=pass is okay
        if target_name == 'pass':
            return True, user_name + ' wants to pass.'

        # target is in game
        if not player_in_game(g, target_id):
            return False, MSG['t_not_in_game']
        # target is alive
        if not is_player_alive(g, target_id):
            return False, MSG['t_not_alive']

        # voting again just changes your vote.
        if has_voted(g, user_id):
            return True, user_name + ' changed vote to ' + '*'+target_name + '.*'

        # after each success vote should list all votes.
        return True, user_name + ' voted for ' + '*' + target_name + '.*'
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 kill():
        # 1) Make sure player who made the command
        # is in the game
        if not player_in_game(g,user_id):
            return False, 'Not allowed.'
        # 1a) is a werewolf
        # Only werewolf can use kill. (for now)
        if player_role(g, user_id) != 'w':
            return False, 'Not allowed.'
        # 1c) is alive
        if not is_player_alive(g, user_id):
            return False, 'Dead wolves can not kill.'
        # 2) Kill command only valid at night.
        if get_current_round(g) != 'night':
            return False, 'Not allowed.'
        # 3) Target must be in game.
        if not player_in_game(g, target_id):
            return False, 'Not allowed.'
        # 4) Target must be alive.
        if not is_player_alive(g, target_id):
            return False, 'Not allowed.'

        return True, '' # no message