Ejemplo n.º 1
0
def message_everyone_roles(g):
    """
    for every player in game.
    DM them their roles.

    """
    u = UserMap()
    # player_role(g, player_id)

    all_alive = [(u.get(user_id=p_id, DM=True), player_role(g, p_id))
                for p_id in players_in_game(g)
                    if is_player_alive(g, p_id)]

    print(all_alive)

    for im, role in all_alive:
        if role=='v':
            nice=" Plain Villager"
        elif role=='w':
            nice=" Werewolf. *Awoooo!*"
        elif role=='s':
            nice=" Seer."
        elif role=='b':
            nice=" Bodyguard."
        send_message(nice, channel=im)
Ejemplo n.º 2
0
def make_end_round_str(g, alert=None, game_over=None):
    """
    g - game state
    alert - string of any alerts
    game_over - string of role that won, if game is over.
    """
    round_end_str = ''

    if alert:
        round_end_str += alert

    if game_over:
        if game_over == 'w':
            # werewolves won
            round_end_str += "\n Game Over. Werewolves wins.\n"

        elif game_over == 'v':
            # village wins
            round_end_str += "\n Game Over. Village wins.\n"

        # Display list of players and their roles
        round_end_str += '\n'.join(
                [u.get(user_id=p_id) + "%s | *%s*." % (u.get(user_id=p_id), player_role(g, p_id))
                    for p_id in players_in_game(g)])

    return round_end_str
Ejemplo n.º 3
0
    def can_start():
        """ some logic here """
        players = players_in_game(g)
        if len(players) < 1: # change to 3 later.
            # not enough players to start
            return False, MSG['num_players']

        if g.get('STATUS') != 'WAITING_FOR_JOIN':
            return False, MSG['not_waiting']

        return True, None
Ejemplo n.º 4
0
def assign_roles(g):
    players = players_in_game(g)
    create_wolf = random.choice(players) # id of player
    new_g = copy.deepcopy(g)

    for player in players:
        if player == create_wolf:
            new_g = update_game_state(new_g, 'role', player=player, role='w')
        else:
            new_g = update_game_state(new_g, 'role', player=player, role='v')
    return new_g
def should_start_game(user_id, action, game_state):
    """Check if we should start a new game"""
    players = status.players_in_game(game_state)

    # min for a good game is 11
    if len(players) < 1:
        return False, RESPONSE['num_players']

    if game_state.get('STATUS') != 'WAITING_FOR_JOIN':
        return False, RESPONSE['not_waiting']

    return True, None
Ejemplo n.º 6
0
def list_players(g, user_id, *args):
    """

    * args is args to command list
    g -> string to Slack of players
      -> "\n".join([list of players])

      "player_name"|"status"

    """
    u = UserMap()

    # gets all names.
    return '\n'.join([u.get(user_id=p_id) + ' | ' + player_status(g, p_id)
                    for p_id in players_in_game(g)]), None
def message_everyone_roles(game_state):
    """Ping players with their roles."""
    user_map = UserMap()

    role_message_mapping = {
        'v': " Vanilla Villa\nhttps://media.giphy.com/media/26ufgQWWT3BUtSRq0/giphy.gif",
        'w': " Werewolf\nhttps://media.giphy.com/media/VTGEse4Pt422I/giphy.gif",
        's': " Seer\nhttps://media.giphy.com/media/bpIWfYfOiHR3G/giphy.gif",
        'a': " Angel\nhttps://media.giphy.com/media/xbbq3NUIOtTVu/giphy.gif"
    }

    def _player_tuple(player_id, game_state):

        return (user_map.get(user_id=player_id, DM=True), status.player_role(game_state, player_id))

    all_alive = [_player_tuple(player_id, game_state) for player_id in status.players_in_game(game_state) if status.is_player_alive(game_state, player_id)]

    for im, role in all_alive:
        dm_message = role_message_mapping[role]
        send_message(dm_message, channel=im)
def start_game(game_state, user_id, *kwargs):
    """Start the game and set game status to `RUNNING`."""
    result, message = mod_valid_action(user_id, 'start', game_state)
    if not result:
        return message, None

    send_message("@channel: Game is starting...")
    players = status.players_in_game(game_state)
    num_werewolves = status.alive_for_werewolf(game_state)

    p1_str = "_There are *%d* players in the game._\n" % len(players)
    p2_str = "_There are *%d* werewolves in the game._\n" % len(num_werewolves)
    p3_str = "https://media.giphy.com/media/3o72FkgwrI7P4G1amI/giphy.gif"
    send_message(p1_str + p2_str + p3_str)

    game_state = update_game_state(game_state, 'status', status='RUNNING')

    new_game = assign_roles(game_state)
    message_everyone_roles(new_game)

    return start_day_round(new_game), None
Ejemplo n.º 9
0
def start_game(g, user_id, *args):
    """
    Check if enough players.
    (optional) Pick config setup that works w/ num of players.
    Outut to channel (@channel) game is starting.
    Assign Roles.
    Message Users their roles.

    STATUS -> "RUNNING"
    """
    # can only start a game
    #   if enough players
    #   if g['STATUS'] == 'WAITING_FOR_JOIN'

    result, message = mod_valid_action(user_id, 'start', g)
    if not result:
        # cant start
        print(result, message)
        return message, None

    # tell everyone the game is starting
    send_message("@channel: Game is starting...")
    """ message everyone details of game. """
    players = players_in_game(g)
    num_werewolves = 1 # only one for now.

    p1_str = "_There are *%d* players in the game._\n" % len(players)
    p2_str = "There are *%d* werewolves in the game._" % num_werewolves
    send_message(p1_str + p2_str)
    g = update_game_state(g, 'status', status='RUNNING')
    # Go through and assign everyone in the game roles.
    new_g = assign_roles(g) # updated state w/ roles
    message_everyone_roles(new_g)

    # go to night round.

    return start_day_round(new_g), None # idk when this will return.
def make_end_round_str(game_state, alert=None, game_over=None):
    """Reconcile end of day actions and either enter night mode or end game."""
    user_map = UserMap()

    round_end_str = ''

    if alert:
        round_end_str += alert

    if game_over:
        if game_over == 'w':
            round_end_str += "\n Game Over. Werewolves wins.\n"

        elif game_over == 'v':
            round_end_str += "\n Game Over. Village wins.\n"

        def player_role_string(player_id, game_state):
            return user_map.get(user_id=player_id) + "%s | %s" % (user_map.get(user_id=player_id), status.player_role(game_state, player_id))

        status.player_roles = [player_role_string(player_id, game_state) for player_id in status.players_in_game(game_state)]
        round_end_str += '\n'.join(status.player_roles)

    return round_end_str
def list_players(game_state, user_id, *kwargs):
    """List all the current players in the game."""
    user_map = UserMap()
    players = status.players_in_game(game_state)

    return '\n'.join([user_map.get(user_id=player_id) + ' | ' + status.player_status(game_state, player_id) for player_id in players]), None
def assign_roles(game_state):
    """Assign all players in the game a role."""
    total_players = status.players_in_game(game_state)
    num_of_wolves = 1
    num_of_players = len(total_players)
    seer = None
    angel = None
    wolf = None
    villa = None

    # if it's only 2 players that's lame but whatev's
    if num_of_players <= 2:
        if num_of_players == 1:
            random_ints = range(20)
            decision = random.choice(random_ints)

            if decision <= 4:
                villa = total_players[0]

            elif decision >= 5 and decision <= 9:
                wolf = total_players[0]

            elif decision >= 10 and decision <= 14:
                seer = total_players[0]

            elif decision >= 15 and decision <= 20:
                angel = total_players[0]

        else:
            villa = total_players[0]
            wolf = total_players[1]

    new_game = copy.deepcopy(game_state)

    if num_of_players > 2:
        if num_of_players >= 1 and num_of_players < 13:
            num_of_wolves = 2

        elif num_of_players >= 13 and num_of_players < 23:
            num_of_wolves = 3

        elif num_of_players >= 23:
            num_of_wolves = 6

        wolves = random.sample(total_players, num_of_wolves)
        non_wolves = [player for player in total_players if player not in created_wolves]

        ramdom.shuffle(non_wolves)

        seer = non_wolves[0]
        angel = non_wolves[1]
        villas = [x for x in non_wolves if x != seer and x != angel]

        if seer and angel:
            new_game = update_game_state(new_game, 'role', player=seer, role='s')
            new_game = update_game_state(new_game, 'role', player=angel, role='a')

        for villa in villas:
            new_game = update_game_state(new_game, 'role', player=villa, role='v')

        for wolf in wolves:
            new_game = update_game_state(new_game, 'role', player=wolf, role='w')

    else:
        if villa:
            new_game = update_game_state(new_game, 'role', player=villa, role='v')
        if wolf:
            new_game = update_game_state(new_game, 'role', player=wolf, role='w')
        if seer:
            new_game = update_game_state(new_game, 'role', player=seer, role='s')
        if angel:
            new_game = update_game_state(new_game, 'role', player=angel, role='a')

    return new_game