File size: 2,351 Bytes
cf58256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import streamlit as st
import random
from collections import Counter

# Set up the Streamlit app
st.set_page_config(page_title="Bầu Cua Tôm Cá", layout="centered")
st.title("Bầu Cua Tôm Cá")

# Set font and colors
st.markdown(
    """
    <style>
    .stButton>button {
        font-size: 16px;
        background-color: #FF0000;
        color: #FFFFFF;
    }
    .stSelectbox, .stRadio {
        font-size: 16px;
    }
    .stText {
        font-size: 16px;
        color: #000000;
    }
    </style>
    """,
    unsafe_allow_html=True
)

# UI elements
shake_count = st.selectbox("Số lần lắc", ["1000", "50", "100", "500"])
shake_info = st.empty()
result_label = st.empty()

dice_faces = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"]
default_faces = ["Cá", "Gà", "Nai"]
selected_faces = []

for i in range(3):
    selected_faces.append(st.radio(f"Chọn mặt {i+1}", dice_faces, index=dice_faces.index(default_faces[i])))

# Opposite and adjacent faces (not used in Streamlit version)
opposite_faces = {
    "Bầu": "Cua",
    "Cua": "Bầu",
    "Nai": "Tôm",
    "Tôm": "Nai",
    "Gà": "Cá",
    "Cá": "Gà"
}

adjacent_faces = {
    "Bầu": ["Tôm", "Gà", "Nai", "Cá"],
    "Cá": ["Bầu", "Nai", "Cua", "Tôm"],
    "Gà": ["Bầu", "Tôm", "Cua", "Nai"],
    "Tôm": ["Bầu", "Cá", "Cua", "Gà"],
    "Nai": ["Bầu", "Gà", "Cua", "Cá"],
    "Cua": ["Tôm", "Cá", "Nai", "Gà"]
}

def predict_result():
    outcomes = ["Bầu", "Cua", "Tôm", "Cá", "Gà", "Nai"]
    shake_count_int = int(shake_count)
    
    if len(selected_faces) == 3:
        results = [random.choice(outcomes) for _ in range(shake_count_int)]
        result_counts = Counter(results)
        sorted_results = sorted(result_counts.items(), key=lambda x: x[1], reverse=True)
        
        result_text = "Kết quả:\n"
        for outcome, count in sorted_results:
            result_text += f"{outcome}: {count} ({count/shake_count_int:.2%})\n"
        
        result_label.text(result_text)
        shake_info.text(f"Số lần lắc: {shake_count}")
    else:
        result_label.text("Vui lòng chọn 3 mặt đầu tiên.")

def reset_results():
    result_label.text("Kết quả: ")
    shake_info.text("Số lần lắc: 0")

# Buttons
if st.button("Lắc"):
    predict_result()

if st.button("Reset"):
    reset_results()