Exemplo n.º 1
0
def banner():
    """ Returns the banner """

    t = Terminal()

    return t.bright_blue('''\
     ╦╔═╗┌─┐┬ ┬┌─┐┬  ┬  
     ║╚═╗└─┐├─┤├┤ │  │  
    ╚╝╚═╝└─┘┴ ┴└─┘┴─┘┴─┘ 2.0 \
    ''') + f'''
Exemplo n.º 2
0
def show_board(board, status=''):
    term = Terminal()
    for i, (word, category) in enumerate(board):
        jword = word[:11]
        if category == UNKNOWN:
            print(justify(jword), end='')
        elif category == RED:
            print(term.bright_red(justify(jword + ' [r]')), end='')
        elif category == BLUE:
            print(term.bright_blue(justify(jword + ' [b]')), end='')
        elif category == NEUTRAL:
            print(term.yellow(justify(jword + ' [n]')), end='')
        elif category == ASSASSIN:
            print(term.reverse(justify(jword + ' [a]')), end='')
        if i % 5 == 4:
            print('\n')
    print(status)
Exemplo n.º 3
0
def main():
    term = Terminal()
    board = make_board()
    board_indices = {word: i for (i, (word, category)) in enumerate(board)}
    known_board = [(word, UNKNOWN) for (word, category) in board]
    current_player = RED
    status = ''

    board_vocab = [tag_en(word) for (word, category) in board]
    simframe = VECTORS.frame.dot(VECTORS.frame.loc[board_vocab].T)

    with open('/tmp/codenames.log', 'w') as log:
        print(board, file=log)
        while True:
            real_counts = Counter(category for (word, category) in board)
            known_counts = Counter(category for (word, category) in known_board)
            diff = real_counts - known_counts
            if diff[RED] == 0:
                show_board(board, "Red team wins.")
                return RED
            if diff[BLUE] == 0:
                show_board(board, "Blue team wins.")
                return BLUE

            show_board(known_board, '')
            print("%s spymaster is thinking of a clue..." % PLAYER_NAMES[current_player])
            clue_number, clue_word = get_ai_clue(simframe, board, known_board, diff, current_player, log)
            print("Clue: %s %d" % (clue_word, clue_number))

            picked_category = current_player
            while picked_category == current_player:
                choice = get_human_guess(board, current_player)
                if choice == 'PASS':
                    status = '%s passes.' % PLAYER_NAMES[current_player]
                    print(status)
                    break

                idx = board_indices[choice]
                word, picked_category = board[idx]
                known_board[idx] = board[idx]

                if picked_category == RED:
                    shown_category = term.bright_red('red')
                elif picked_category == BLUE:
                    shown_category = term.bright_blue('blue')
                elif picked_category == NEUTRAL:
                    shown_category = term.yellow('neutral')
                elif picked_category == ASSASSIN:
                    shown_category == term.reverse('the assassin')
                else:
                    raise ValueError(picked_category)
                status = '%s is %s.' % (choice, shown_category)
                print(status)

                if picked_category == ASSASSIN:
                    if current_player == RED:
                        show_board(board, "Blue team wins.")
                        return BLUE
                    else:
                        show_board(board, "Red team wins.")
                        return RED
            current_player = OPPOSITE_PLAYER[current_player]