본문 바로가기
Python/Python Examples

[Python Examples / Temp] 몬테카를로 카지노 주사위

by Henry Cho 2024. 1. 11.
728x90

몬테카를로 카지노 주사위

포스트 난이도: HOO_Middle


# Example Code

import random
import matplotlib.pyplot as plt

# Function to simulate die roll
def rolldice():
    dice = random.randint(1, 100)
    if dice <= 51:
        return False
    elif dice > 51:
        return True

# Modified function for the play to return funds after each play
def play_mod(total_funds, wager_amount, total_plays):
    Funds = []

    for play in range(1, total_plays + 1):
        if rolldice():
            total_funds += wager_amount
        else:
            total_funds -= wager_amount
        Funds.append(total_funds)

    return Funds

# Finding the best number of bets for the highest ending fund
best_fund = -float('inf')  # Initialize with a very low value
best_num_bets = 0
final_funds_for_each_bet = []

# Testing for up to 100 bets
for num_bets in range(1, 101):
    final_funds = play_mod(10000, 100, num_bets)
    final_fund = final_funds[-1]
    final_funds_for_each_bet.append(final_fund)

    if final_fund > best_fund:
        best_fund = final_fund
        best_num_bets = num_bets

# Output
print("Highest Ending Fund: $", best_fund, "achieved with", best_num_bets, "bets")

# Plotting
plt.plot(range(1, 101), final_funds_for_each_bet)
plt.ylabel('Player Money in $')
plt.xlabel('Number of bets')
plt.title('Final Funds after each Number of Bets')
plt.show()

 


# github Link

[Temp]

 


 

728x90

댓글