lof223 commited on
Commit
a72f7df
·
verified ·
1 Parent(s): 4452a56

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import gradio as gr
3
+
4
+ # 游戏图案
5
+ SYMBOLS = ["鱼", "虾", "蟹", "葫芦", "鸡", "虎"]
6
+
7
+ # 赔率设置(简化示例:单图形赔率为命中次数,组合图形固定赔率5)
8
+ COMBO_PAYOUT = 5
9
+
10
+
11
+ def roll_dice():
12
+ # 模拟三个骰子
13
+ return [random.choice(SYMBOLS) for _ in range(3)]
14
+
15
+
16
+ def calculate_payout(bet_type, selections, bet_amount, result):
17
+ # 计算赔付
18
+ if bet_type == "单图形":
19
+ symbol = selections[0]
20
+ count = result.count(symbol)
21
+ payout = bet_amount * count
22
+ return payout, f"结果出现{count}次,赔付:{payout}"
23
+ else: # 组合图形
24
+ a, b = selections
25
+ # 判断是否同时出现
26
+ if a in result and b in result:
27
+ payout = bet_amount * COMBO_PAYOUT
28
+ return payout, f"同时出现 {a} & {b},赔付:{payout}"
29
+ else:
30
+ return 0, "未命中,赔付:0"
31
+
32
+
33
+ def play(bet_type, symbols, bet_amount):
34
+ # 解析选择
35
+ selections = symbols.split(",")
36
+ # 骰子结果
37
+ result = roll_dice()
38
+ payout, message = calculate_payout(bet_type, selections, bet_amount, result)
39
+ return " ".join(result), message
40
+
41
+ # 构建Gradio界面
42
+ demo = gr.Interface(
43
+ fn=play,
44
+ inputs=[
45
+ gr.Radio(["单图形", "组合图形"], label="下注类型"),
46
+ gr.Textbox(label="选择图案 (单图形: 单个, 组合图形: 用逗号分隔两个)", placeholder="如:鱼 或 虾,蟹"),
47
+ gr.Number(label="下注金额", value=10)
48
+ ],
49
+ outputs=[
50
+ gr.Textbox(label="骰子结果"),
51
+ gr.Textbox(label="结算消息")
52
+ ],
53
+ title="泰国鱼虾蟹骰子游戏 Demo",
54
+ description="基于骰子竞猜的小游戏,部署到 Hugging Face Spaces"
55
+ )
56
+
57
+ if __name__ == "__main__":
58
+ demo.launch()