Spaces:
Runtime error
Runtime error
Upload streamlit_app.py
Browse files- src/streamlit_app.py +30 -75
src/streamlit_app.py
CHANGED
|
@@ -1,20 +1,20 @@
|
|
| 1 |
|
| 2 |
import streamlit as st
|
| 3 |
-
import random
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
import hmac
|
| 6 |
import hashlib
|
| 7 |
|
| 8 |
-
st.set_page_config(page_title="Stake Dice Strategy
|
| 9 |
-
st.title("π² Stake Dice Strategy Simulator
|
| 10 |
|
| 11 |
st.sidebar.header("Simulation Settings")
|
| 12 |
-
initial_balance = st.sidebar.number_input("Starting Balance (USD)", value=200.0
|
| 13 |
base_bet = st.sidebar.number_input("Base Bet (USD)", value=0.0001, step=0.0001, format="%.4f")
|
| 14 |
-
num_bets = st.sidebar.number_input("Number of Bets
|
| 15 |
-
num_runs = st.sidebar.number_input("Number of
|
| 16 |
-
|
| 17 |
-
random.seed(
|
| 18 |
|
| 19 |
st.sidebar.markdown("---")
|
| 20 |
st.sidebar.subheader("π Provably Fair Dice (Optional)")
|
|
@@ -35,113 +35,68 @@ def roll_dice(nonce):
|
|
| 35 |
roll = (random.random() * 10001) / 100
|
| 36 |
return min(round(roll, 5), 100.00000)
|
| 37 |
|
| 38 |
-
def
|
| 39 |
balance = initial_balance
|
| 40 |
bet = base_bet
|
| 41 |
win_chance = 2.02
|
| 42 |
multiplier = (100 - house_edge) / win_chance
|
| 43 |
-
loss_count = 0
|
| 44 |
-
win_count = 0
|
| 45 |
-
max_bet = bet
|
| 46 |
-
max_balance = balance
|
| 47 |
-
min_balance = balance
|
| 48 |
-
data = []
|
| 49 |
-
profit = 0.0
|
| 50 |
win_streak = 0
|
| 51 |
-
|
|
|
|
| 52 |
max_bet_cap = initial_balance * 0.2
|
| 53 |
-
stop_bet_cap = max_bet_cap
|
| 54 |
|
|
|
|
| 55 |
for i in range(num_bets):
|
| 56 |
-
if balance < bet or bet >
|
| 57 |
break
|
|
|
|
| 58 |
roll = roll_dice(i + run_id * num_bets)
|
| 59 |
-
is_win = roll < win_chance if
|
| 60 |
|
| 61 |
result = {
|
| 62 |
"Run": run_id,
|
| 63 |
"Round": i + 1,
|
| 64 |
"Bet": bet,
|
| 65 |
"Roll": roll,
|
| 66 |
-
"Over/Under":
|
| 67 |
}
|
| 68 |
|
| 69 |
if is_win:
|
| 70 |
win = bet * multiplier
|
| 71 |
balance += win - bet
|
| 72 |
-
|
| 73 |
-
win_count += 1
|
| 74 |
win_streak += 1
|
| 75 |
loss_count = 0
|
| 76 |
|
| 77 |
-
if
|
| 78 |
-
if
|
| 79 |
-
bet = base_bet
|
| 80 |
-
elif win_streak % 2 == 0:
|
| 81 |
-
bet = min(bet * 1.3, max_bet_cap)
|
| 82 |
-
else:
|
| 83 |
-
bet = base_bet
|
| 84 |
-
|
| 85 |
-
win_chance = 5.00 if profit < -100 else 2.02
|
| 86 |
-
|
| 87 |
-
if win_streak % 2 == 0:
|
| 88 |
-
over_under_mode = "Over" if over_under_mode == "Under" else "Under"
|
| 89 |
-
|
| 90 |
else:
|
| 91 |
balance -= bet
|
| 92 |
-
profit -= bet
|
| 93 |
loss_count += 1
|
| 94 |
win_streak = 0
|
| 95 |
if loss_count % 10 == 0:
|
| 96 |
bet *= 2
|
| 97 |
|
| 98 |
bet = min(bet, max_bet_cap)
|
| 99 |
-
max_bet = max(max_bet, bet)
|
| 100 |
-
max_balance = max(max_balance, balance)
|
| 101 |
-
min_balance = min(min_balance, balance)
|
| 102 |
-
|
| 103 |
result["Balance"] = round(balance, 4)
|
| 104 |
-
result["Win Chance"] = win_chance
|
| 105 |
result["Result"] = "Win" if is_win else "Loss"
|
| 106 |
data.append(result)
|
| 107 |
|
| 108 |
df = pd.DataFrame(data)
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
"Profit": round(balance - initial_balance, 4),
|
| 113 |
-
"Max Bet": round(max_bet, 6),
|
| 114 |
-
"Wins": win_count,
|
| 115 |
-
"Losses": len(df) - win_count,
|
| 116 |
-
"Win Rate (%)": round((win_count / len(df)) * 100, 2) if len(df) > 0 else 0,
|
| 117 |
-
"Max Balance": round(max_balance, 4),
|
| 118 |
-
"Min Balance": round(min_balance, 4),
|
| 119 |
-
"Drawdown": round(max_balance - min_balance, 4),
|
| 120 |
-
}
|
| 121 |
-
return df, summary
|
| 122 |
-
|
| 123 |
-
# Run simulations
|
| 124 |
-
st.subheader("π Multi-Run Strategy Comparison")
|
| 125 |
all_data = []
|
| 126 |
-
all_summary = []
|
| 127 |
|
| 128 |
for run in range(1, num_runs + 1):
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
df_orig["Strategy"] = "Original"
|
| 133 |
-
df_impr["Strategy"] = "Improved"
|
| 134 |
-
sum_orig["Strategy"] = "Original"
|
| 135 |
-
sum_impr["Strategy"] = "Improved"
|
| 136 |
-
|
| 137 |
-
all_data.extend([df_orig, df_impr])
|
| 138 |
-
all_summary.extend([sum_orig, sum_impr])
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
|
| 143 |
-
st.
|
| 144 |
-
st.download_button("π₯ Download Full Simulation CSV", full_data_df.to_csv(index=False), file_name="dice_dual_simulation.csv")
|
| 145 |
|
| 146 |
-
with st.expander("π Show
|
| 147 |
-
st.dataframe(
|
|
|
|
| 1 |
|
| 2 |
import streamlit as st
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
+
import random
|
| 5 |
import hmac
|
| 6 |
import hashlib
|
| 7 |
|
| 8 |
+
st.set_page_config(page_title="Stake Dice Strategy - v2.3", layout="wide")
|
| 9 |
+
st.title("π² Stake Dice Auto Strategy Simulator - v2.3 (Manual-Only Features)")
|
| 10 |
|
| 11 |
st.sidebar.header("Simulation Settings")
|
| 12 |
+
initial_balance = st.sidebar.number_input("Starting Balance (USD)", value=200.0)
|
| 13 |
base_bet = st.sidebar.number_input("Base Bet (USD)", value=0.0001, step=0.0001, format="%.4f")
|
| 14 |
+
num_bets = st.sidebar.number_input("Number of Bets", value=5000, step=1000)
|
| 15 |
+
num_runs = st.sidebar.number_input("Number of Runs", value=5, step=1)
|
| 16 |
+
random_seed = st.sidebar.number_input("Random Seed", value=42, step=1)
|
| 17 |
+
random.seed(random_seed)
|
| 18 |
|
| 19 |
st.sidebar.markdown("---")
|
| 20 |
st.sidebar.subheader("π Provably Fair Dice (Optional)")
|
|
|
|
| 35 |
roll = (random.random() * 10001) / 100
|
| 36 |
return min(round(roll, 5), 100.00000)
|
| 37 |
|
| 38 |
+
def simulate_v23(run_id):
|
| 39 |
balance = initial_balance
|
| 40 |
bet = base_bet
|
| 41 |
win_chance = 2.02
|
| 42 |
multiplier = (100 - house_edge) / win_chance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
win_streak = 0
|
| 44 |
+
loss_count = 0
|
| 45 |
+
over_under = "Under"
|
| 46 |
max_bet_cap = initial_balance * 0.2
|
|
|
|
| 47 |
|
| 48 |
+
data = []
|
| 49 |
for i in range(num_bets):
|
| 50 |
+
if balance < bet or bet > max_bet_cap:
|
| 51 |
break
|
| 52 |
+
|
| 53 |
roll = roll_dice(i + run_id * num_bets)
|
| 54 |
+
is_win = roll < win_chance if over_under == "Under" else roll > (100 - win_chance)
|
| 55 |
|
| 56 |
result = {
|
| 57 |
"Run": run_id,
|
| 58 |
"Round": i + 1,
|
| 59 |
"Bet": bet,
|
| 60 |
"Roll": roll,
|
| 61 |
+
"Over/Under": over_under
|
| 62 |
}
|
| 63 |
|
| 64 |
if is_win:
|
| 65 |
win = bet * multiplier
|
| 66 |
balance += win - bet
|
| 67 |
+
bet = base_bet
|
|
|
|
| 68 |
win_streak += 1
|
| 69 |
loss_count = 0
|
| 70 |
|
| 71 |
+
if win_streak % 2 == 0:
|
| 72 |
+
over_under = "Over" if over_under == "Under" else "Under"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
else:
|
| 74 |
balance -= bet
|
|
|
|
| 75 |
loss_count += 1
|
| 76 |
win_streak = 0
|
| 77 |
if loss_count % 10 == 0:
|
| 78 |
bet *= 2
|
| 79 |
|
| 80 |
bet = min(bet, max_bet_cap)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
result["Balance"] = round(balance, 4)
|
|
|
|
| 82 |
result["Result"] = "Win" if is_win else "Loss"
|
| 83 |
data.append(result)
|
| 84 |
|
| 85 |
df = pd.DataFrame(data)
|
| 86 |
+
return df
|
| 87 |
+
|
| 88 |
+
st.subheader("π Simulation Result")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
all_data = []
|
|
|
|
| 90 |
|
| 91 |
for run in range(1, num_runs + 1):
|
| 92 |
+
df = simulate_v23(run)
|
| 93 |
+
df["Strategy"] = "Improved v2.3 (Manual Only)"
|
| 94 |
+
all_data.append(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
+
result_df = pd.concat(all_data, ignore_index=True)
|
| 97 |
+
st.dataframe(result_df)
|
| 98 |
|
| 99 |
+
st.download_button("π₯ Download CSV", data=result_df.to_csv(index=False), file_name="stake_dice_v23_simulation.csv")
|
|
|
|
| 100 |
|
| 101 |
+
with st.expander("π Show Full Log"):
|
| 102 |
+
st.dataframe(result_df)
|