Ejemplo n.º 1
0
def print_player_cards(playername, cards):
    cards_points = sum_cards_values(cards)

    utils.print_colored(f"§BCartas de §y{playername}§0:")

    for card in cards:
        card_info = get_card_info(card)

        print(f" - {card_description(card_info)}")

    utils.print_success(f"{playername} marcou {cards_points} pontos!")
Ejemplo n.º 2
0
def print_greetings():
    lines = [
        "§r", "▄▄▄▄·  ▄▄▄·  ▄▄·  ▄▄▄· ▄▄▄   ▄▄▄·",
        "▐█ ▀█▪▐█ ▀█ ▐█ ▌▪▐█ ▀█ ▀▄ █·▐█ ▀█ ",
        "▐█▀▀█▄▄█▀▀█ ██   ▄█▀▀█ ▐▀▀▄ ▄█▀▀█ ",
        "██▄▪▐█▐█ ▪▐▌▐█  █▐█ ▪▐▌▐█•█▌▐█ ▪▐▌",
        "·▀▀▀▀  ▀  ▀ ·▀▀▀  ▀  ▀ .▀  ▀ ▀  ▀ ", "§B",
        "§g > Seja bem vindo(a) ao BACARA!", "§w   Por Luciano Felix", "§0",
        "Insira as informações para começar...", ""
    ]

    utils.print_colored('\n'.join(lines))
Ejemplo n.º 3
0
def ask_bet_bid(input_message, player_tokens):
    while True:
        bet_bid_input = input(utils.colored(input_message))

        if bet_bid_input:
            bet_bid = int(bet_bid_input)

            if bet_bid < 0 or bet_bid > player_tokens:
                utils.print_colored("§0Não é possível apostar essa quantia!")

            else:
                return bet_bid

        else:
            return False
Ejemplo n.º 4
0
def splash_screen(img=None):
    from utils import print_colored
    from menus import menu, msgbox
    from tiles import tile
    screen.clear()

    while True:
        if img:
            screen.clear()
            libtcod.image_blit_rect(img, 0, 0,0, -1,-1, 1)
            if img == INTRO_IMAGE:
                print_colored(screen, Pos(30, 30), colors.WHITE, "PRESS ENTER TO START!")
            screen.flush()
        else:
            game_draw()
        key, mouse = libtcod.Key(), libtcod.Mouse()
        libtcod.sys_check_for_event(libtcod.EVENT_ANY, key, mouse)
        if key.pressed and key.vk == libtcod.KEY_ENTER:
            if img == INTRO_IMAGE:
                opt = menu((colors.WHITE, "Select a mode (changeable in-game with 'tab'):"), 
                            [(colors.PALE_RED, "Tiles mode"),(colors.PALE_GREEN, "Classic ASCII") ], 50, index_color=colors.YELLOW)
                global ASCII_MODE
                ASCII_MODE = (opt == 1)
                if opt != None: 
                    hole= [] if not ASCII_MODE else [colors.YELLOW, ' (O)']
                    explanation = [ colors.BABY_BLUE, "Welcome to BUGHACK\n",
                                    colors.WHITE, "You are a leader ant who must lead worker ants to delicious harvest.\n",
                                    colors.WHITE, "Every sector you must gather a certain amount of harvest.\n", 
                                    colors.PALE_RED, "Keep your ants safe, or you'll take damage!\n", 
                                    colors.WHITE, "You must call ants out of an ant hole"] + hole + [colors.WHITE,", and then lead them to \n",
                                    colors.WHITE, "to fruit.\n",colors.WHITE, '\n',
                                    colors.YELLOW, "Press C in-game to see controls."]
                    screen.clear()
                    libtcod.image_blit_rect(img, 0, 0,0, -1,-1, 1)
                    screen.flush()
                    msgbox(explanation, 70)
                    if game_save_exists():
                        game_load()
                else:
                    continue
            screen.clear()
            screen.flush()
            return
        elif (key.pressed and key.vk == libtcod.KEY_ESCAPE) or libtcod.console_is_window_closed():
            exit()
Ejemplo n.º 5
0
def print_stats(players, tokens):
    header = ("NOME", "FICHAS")
    body = zip(players, tokens)

    max_names_len = utils.get_max_len(players + [header[0]])
    max_tokens_len = utils.get_max_len(tokens + [header[1]])

    print(
        f"┌ {header[0]} { '─' * (max_names_len - 6 + 3) } {header[1]} { '─' * (max_tokens_len - 6) }┐"
    )

    for line in body:
        name, player_tokens = line

        name_length = len(name)
        name_spacer = " " * (max_names_len - name_length + 3)

        tokens_length = len(str(player_tokens))
        tokens_spacer = " " * (max_tokens_len - tokens_length)

        utils.print_colored(
            f"│ §y{name}{name_spacer}§g{player_tokens}{tokens_spacer} §0│")

    print("└" + "─" * (max_names_len + 3 + max_tokens_len + 2) + "┘")
Ejemplo n.º 6
0
def register_players():
    players_list = []
    tokens = []

    taken_names = game_names

    index = 1
    while True:
        name = input(
            utils.colored(f"Jogador {index}, vai jogar? Qual seu nome? §y"))
        name_lower = name.lower()

        if not name_lower in taken_names:
            tokens_input = input(
                utils.colored(f"§0Quantas fichas você tem, {name}? §g"))
            tokens_amount = 0

            if tokens_input:
                int_tokens = int(tokens_input)

                if int_tokens > 0:
                    tokens_amount = int_tokens

                else:
                    utils.print_colored(
                        "§0Não é possível entrar no jogo sem fichas!\n")
                    continue

            taken_names.append(name_lower)
            players_list.append(name)
            tokens.append(tokens_amount)

            utils.print_success(
                f"{name} entrou no jogo com {tokens_amount} fichas!")

            index += 1

        elif name_lower in exit_names:
            utils.print_colored(f"§0Fim da entrada de jogadores.")

            break

        else:
            utils.print_colored(f"§0Não é possível usar esse nome!\n")

    if players_list:
        players_list.append("Banco")
        tokens.append("∞")

        utils.print_success(f"Banco entrou no jogo com infinitas fichas!")

    else:
        system.game_over()

    return (players_list, tokens)
Ejemplo n.º 7
0
def ask_bets(players_names, players_tokens):
    players_names_tokens = list(zip(players_names, players_tokens))
    players_bets = []
    leavers = []

    for player_name_tokens in players.get_real_players(players_names_tokens):
        playername, tokens = player_name_tokens

        player_bet = []

        bet_bid = ask_bet_bid(
            f"§0Quanto você aposta nesta rodada, {playername}? (Ou saia sem apostar) §g",
            tokens)

        if bet_bid:
            player_bet.append(bet_bid)

            while True:
                bet_what = input(
                    utils.colored(
                        f"§0Jogador, banco ou empate. Em que você aposta {bet_bid} fichas, {playername}? §b"
                    ))
                bet_what_lower = bet_what.lower()

                if bet_what_lower in ["jogador", "j"]:
                    player_bet.append("player")

                    while True:
                        bet_who = input(
                            utils.colored(
                                f"§0Em qual jogador você aposta {bet_bid} fichas, {playername}? §y"
                            ))

                        bet_player = players.get_playername(
                            bet_who, players_names)
                        bet_leaver = players.get_playername(bet_who, leavers)

                        if bet_player and not bet_leaver and bet_who.lower(
                        ) != playername.lower():
                            player_bet.append(bet_player)
                            utils.print_success(
                                f"{playername} apostou {bet_bid} fichas em {bet_player}!"
                            )
                            break

                        else:
                            utils.print_colored(
                                "§0Não é possível apostar nesse jogador!")

                    break

                elif bet_what_lower in ["banco", "b"]:
                    player_bet.append("bank")
                    utils.print_success(
                        f"{playername} apostou {bet_bid} fichas no Banco!")
                    break

                elif bet_what_lower in ["empate", "e"]:
                    player_bet.append("tie")
                    utils.print_success(
                        f"{playername} apostou {bet_bid} fichas por um empate no jogo!"
                    )
                    break

                else:
                    utils.print_colored(
                        "§0Não é possível realizar esse tipo de aposta!")

        else:
            leavers.append(playername)
            utils.print_info(f"{playername} saiu do jogo com {tokens} fichas!")

        players_bets.append(player_bet)

    # Bank bet
    players_bets.append([])

    # Update players, removing who didn't bet
    players_names, players_tokens, players_bets = get_betting_players(
        players_names, players_tokens, players_bets)

    if not players.has_players(players_names):
        system.game_over()

    return (players_names, players_tokens, players_bets)
Ejemplo n.º 8
0
def plot_cost_function(data, max_iterations, ratio):
    utils.print_colored("[cost_function][Plotting cost function...] start!",
                        utils.bcolors.YELLOW)
    cost = []

    utils.print_colored("[cost_function][Calculating cost function...] start!",
                        utils.bcolors.YELLOW)
    for _ in range(1, max_iterations + 1):
        data.norm_theta0, data.norm_theta1 = train_model.train_model(
            ratio, data.norm_theta0, data.norm_theta1, data.norm_tab_x,
            data.norm_tab_y)
        cost.append(cost_function(data))
    utils.print_colored(
        "[cost_function][Calculating cost function...] finished!",
        utils.bcolors.GREEN)

    utils.print_colored("[cost_function][Generating figure...] start!",
                        utils.bcolors.YELLOW)
    max_iter_table = np.arange(max_iterations)
    fig = go.Figure(data=go.Scatter(x=max_iter_table, y=cost))
    fig.show()
    utils.print_colored("[cost_function][Generating figure...] finished!",
                        utils.bcolors.GREEN)
    utils.print_colored(
        "[cost_function][Plotting cost function...] finished!\n",
        utils.bcolors.GREEN)
Ejemplo n.º 9
0
def plot_linear_regression(data, slope, max_iterations, ratio):
    utils.print_colored(
        "[linear_regression][Plotting linear regression...] start!",
        utils.bcolors.YELLOW)
    graph_data = {}
    graph_data["figure"] = generate_fig(max_iterations, "Kilometers", "Price")
    graph_data["sliders"] = generate_sliders()

    # Build initial figure data, and frame_data for i == 0
    utils.print_colored(
        "[linear_regression][Building initial figure and frame datas...] start!",
        utils.bcolors.YELLOW)
    estimations = []
    for x in data.tab_x:
        estimations.append(est.estimate_price(x, data.theta0, data.theta1))
    build_fig_data_linear_regression(data, estimations, graph_data)
    build_frame_data_linear_regression(data, estimations, 0, graph_data)
    utils.print_colored(
        "[linear_regression][Building initial figure and frame datas...] finished!",
        utils.bcolors.GREEN)

    # Iterate max_iterations times through the dataset to train the model
    utils.print_colored("[linear_regression][Building frame data...] start!",
                        utils.bcolors.YELLOW)
    for i in range(1, max_iterations + 1):
        data.norm_theta0, data.norm_theta1 = train_model.train_model(
            ratio, data.norm_theta0, data.norm_theta1, data.norm_tab_x,
            data.norm_tab_y)
        # Every slope times, we make a snapshot of the estimations with the current thetas (slope can be equal to 1)
        if i % slope == 0:
            # De-normalize our thetas to use them for the estimations
            data.theta0 = utils.de_normalize(data.norm_theta0, data.max_y,
                                             data.min_y)
            data.theta1 = utils.de_normalize(
                data.norm_theta1, data.max_y,
                data.min_y) / (data.max_x - data.min_x)
            estimations = []
            # Iterate through the dataset to estimate for each entry
            for x in data.tab_x:
                estimations.append(
                    est.estimate_price(x, data.theta0, data.theta1))
            build_frame_data_linear_regression(data, estimations, i,
                                               graph_data)
    utils.print_colored(
        "[linear_regression][Building frame data...] finished!",
        utils.bcolors.GREEN)

    utils.print_colored("[linear_regression][Generating figure...] start!",
                        utils.bcolors.YELLOW)
    graph_data["figure"]["layout"]["sliders"] = [graph_data["sliders"]]
    fig = go.Figure(graph_data["figure"])
    fig.show()
    utils.print_colored("[linear_regression][Generating figure...] finished!",
                        utils.bcolors.GREEN)
    utils.print_colored(
        "[linear_regression][Plotting linear regression...] finished!\n",
        utils.bcolors.GREEN)
Ejemplo n.º 10
0
def play():
    players_names, players_tokens = players.register_players()

    utils.print_colored("§B§rPlacar Inicial§0\n")
    system.print_stats(players_names, players_tokens)
    print("")

    round = 1
    while True:
        utils.print_colored(f"§B§rRODADA {round}§0\n")

        players_names, players_tokens, round_bets = bets.ask_bets(
            players_names, players_tokens)

        utils.print_colored("§B§rDANDO AS CARTAS...§0\n")

        round_cards = cards.draw_cards(players_names)
        cards_sum = cards.sum_players_cards(round_cards)

        cards.print_cards(players_names, round_cards)

        cards_round_winners = cards.get_winners(players_names, cards_sum)

        bet_round_winners = bets.get_winners(players_names, round_bets,
                                             cards_round_winners)

        bet_prizes = bets.get_prizes(players.get_real_players(players_names),
                                     round_bets, bet_round_winners,
                                     cards.deck_amount)

        for i in range(0, len(bet_prizes)):
            playername = players_names[i]
            prize_amount = bet_prizes[i]

            players_tokens[i] += prize_amount

            if (prize_amount > 0):
                utils.print_success(
                    f"{playername} ganhou a aposta e recebeu {prize_amount} fichas!"
                )

            if (prize_amount < 0):
                utils.print_danger(
                    f"{playername} perdeu a aposta e pagou {abs(prize_amount)} fichas!"
                )

        i = 0
        while True:
            if not i < len(players.get_real_players(players_names)):
                break

            if players_tokens[i] == 0:
                player_name = players_names[i]

                del players_names[i]
                del players_tokens[i]

                utils.print_warn(
                    f"{player_name} saiu do jogo com nenhuma ficha!")
                continue

            i += 1

        if not players.has_players(players_names):
            system.game_over()

        utils.print_colored("§B§rNovo placar§0\n")
        system.print_stats(players_names, players_tokens)
        print("")

        round += 1