tayy786 commited on
Commit
49a5907
Β·
verified Β·
1 Parent(s): 0e2d7a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -0
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as ui
2
+ import random
3
+ import time
4
+
5
+ # List of cards and their numerical values for comparison
6
+ CARDS = [
7
+ {"suit": "β™ ", "rank": "A", "val": 1}, {"suit": "β™ ", "rank": "2", "val": 2},
8
+ {"suit": "β™ ", "rank": "J", "val": 11}, {"suit": "β™ ", "rank": "Q", "val": 12}, {"suit": "β™ ", "rank": "K", "val": 13},
9
+ {"suit": "♦", "rank": "A", "val": 1}, {"suit": "♦", "rank": "10", "val": 10},
10
+ {"suit": "β™₯", "rank": "K", "val": 13}, {"suit": "♣", "rank": "Q", "val": 12}
11
+ ]
12
+
13
+ def load_game_session(request: ui.Request):
14
+ """Captures and displays the tracking/referral parameters from the URL"""
15
+ params = request.query_params
16
+ game_id = params.get("from_gameid", "Not Provided")
17
+ channel = params.get("channelCode", "Default/Direct")
18
+
19
+ welcome_msg = f"❀️ Welcome to the Club! | Channel: {channel} | Referral Agent ID: {game_id}"
20
+ return welcome_msg, 1000 # Starts player with 1000 virtual chips
21
+
22
+ def play_round(bet_type, bet_amount, current_balance):
23
+ if bet_amount > current_balance or current_balance <= 0:
24
+ return current_balance, "❌ Insufficient chips! Please reset balance.", "", ""
25
+
26
+ # 1. Deduct Bet
27
+ current_balance -= bet_amount
28
+
29
+ # 2. Deal Cards randomly
30
+ dragon_card = random.choice(CARDS)
31
+ tiger_card = random.choice(CARDS)
32
+
33
+ # 3. Determine Winner
34
+ if dragon_card["val"] > tiger_card["val"]:
35
+ winner = "Dragon"
36
+ elif tiger_card["val"] > dragon_card["val"]:
37
+ winner = "Tiger"
38
+ else:
39
+ winner = "Tie"
40
+
41
+ # 4. Calculate Payout
42
+ win_msg = ""
43
+ if bet_type == winner:
44
+ if winner == "Tie":
45
+ payout = bet_amount * 9 # 1:8 payout for a tie
46
+ else:
47
+ payout = bet_amount * 2 # 1:1 payout for Dragon/Tiger
48
+ current_balance += payout
49
+ win_msg = f"πŸŽ‰ You Won! +{payout} chips!"
50
+ else:
51
+ win_msg = f"😒 You Lost! {winner} won this round."
52
+
53
+ dragon_display = f"{dragon_card['rank']}{dragon_card['suit']}"
54
+ tiger_display = f"{tiger_card['rank']}{tiger_card['suit']}"
55
+
56
+ game_summary = f"🎰 Result: {winner} Wins! | {win_msg}"
57
+
58
+ return current_balance, game_summary, dragon_display, tiger_display
59
+
60
+ # Custom CSS for standardizing casino board look
61
+ css = """
62
+ .card-box { font-size: 4rem; text-align: center; padding: 20px; border-radius: 10px; border: 2px dashed #ccc; background: #f9f9f9; min-height: 120px;}
63
+ .dragon-card { color: #d9534f; font-weight: bold; }
64
+ .tiger-card { color: #0275d8; font-weight: bold; }
65
+ .status-bar { font-weight: bold; background-color: #333; color: #fff; padding: 10px; border-radius: 5px; text-align: center;}
66
+ """
67
+
68
+ with ui.Blocks(css=css, title="Dragon Tiger Live Club") as demo:
69
+ # Hidden components to pass tracking attributes
70
+ tracking_banner = ui.Markdown(value="Loading application tracking parameters...", elem_classes=["status-bar"])
71
+
72
+ ui.Markdown("# πŸ‰ DRAGON TIGER CLUB πŸ…")
73
+
74
+ with ui.Row():
75
+ balance_stat = ui.Number(label="Your Chips Balance πŸͺ™", value=1000, interactive=False)
76
+ bet_amount_input = ui.Slider(minimum=10, maximum=500, step=10, value=50, label="Select Bet Amount")
77
+
78
+ with ui.Row():
79
+ bet_type_input = ui.Radio(["Dragon", "Tiger", "Tie"], value="Dragon", label="Place Your Bet On:")
80
+ deal_btn = ui.Button("♣️ PLACE BET & DEAL CARD ♦️", variant="primary")
81
+
82
+ with ui.Row():
83
+ with ui.Column():
84
+ ui.Markdown("### πŸ‰ DRAGON CARD")
85
+ dragon_output = ui.Markdown("❔", elem_classes=["card-box", "dragon-card"])
86
+ with ui.Column():
87
+ ui.Markdown("### πŸ… TIGER CARD")
88
+ tiger_output = ui.Markdown("❔", elem_classes=["card-box", "tiger-card"])
89
+
90
+ result_output = ui.Markdown("### Setup your bet and press Deal to begin play!", elem_id="result-box")
91
+ reset_btn = ui.Button("Reset Chips back to 1000", variant="secondary")
92
+
93
+ # App lifecycle logic
94
+ demo.load(fn=load_game_session, outputs=[tracking_banner, balance_stat])
95
+
96
+ deal_btn.click(
97
+ fn=play_round,
98
+ inputs=[bet_type_input, bet_amount_input, balance_stat],
99
+ outputs=[balance_stat, result_output, dragon_output, tiger_output]
100
+ )
101
+
102
+ reset_btn.click(fn=lambda: (1000, "Balance reset. Good luck!"), outputs=[balance_stat, result_output])
103
+
104
+ demo.launch()