Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,12 +43,11 @@ def flip_coin():
|
|
43 |
is_heads = random.random() < coin['winrate']
|
44 |
if is_heads:
|
45 |
game_state['balance'] += coin['value']
|
|
|
|
|
|
|
46 |
game_state['flips_left'] -= 1
|
47 |
|
48 |
-
# Apply coin ability if it exists
|
49 |
-
if 'ability' in coin:
|
50 |
-
ability_effect(coin['ability'])
|
51 |
-
|
52 |
return jsonify({
|
53 |
'result': 'H' if is_heads else 'T',
|
54 |
'balance': game_state['balance'],
|
@@ -76,7 +75,7 @@ def generate_coin():
|
|
76 |
price (higher than 10),
|
77 |
value (higher than 0.1),
|
78 |
winrate (between 0.5 and 0.8),
|
79 |
-
|
80 |
|
81 |
Example:
|
82 |
{
|
@@ -85,7 +84,7 @@ def generate_coin():
|
|
85 |
"price": 15,
|
86 |
"value": 0.2,
|
87 |
"winrate": 0.65,
|
88 |
-
"
|
89 |
}
|
90 |
"""
|
91 |
|
@@ -126,24 +125,22 @@ def reset_game():
|
|
126 |
return jsonify({'success': True})
|
127 |
|
128 |
def validate_coin(coin):
|
129 |
-
required_keys = ['name', 'color', 'price', 'value', 'winrate', '
|
130 |
return all(key in coin for key in required_keys) and \
|
131 |
isinstance(coin['name'], str) and \
|
132 |
isinstance(coin['color'], str) and coin['color'].startswith('#') and \
|
133 |
isinstance(coin['price'], (int, float)) and coin['price'] > 10 and \
|
134 |
isinstance(coin['value'], (int, float)) and coin['value'] > 0.1 and \
|
135 |
isinstance(coin['winrate'], (int, float)) and 0.5 <= coin['winrate'] <= 0.8 and \
|
136 |
-
isinstance(coin['
|
137 |
-
|
138 |
-
def
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
pass
|
146 |
-
# Add more ability effects as needed
|
147 |
|
148 |
if __name__ == '__main__':
|
149 |
app.run(host='0.0.0.0', port=7860)
|
|
|
43 |
is_heads = random.random() < coin['winrate']
|
44 |
if is_heads:
|
45 |
game_state['balance'] += coin['value']
|
46 |
+
# Apply coin bonus if it exists
|
47 |
+
if coin['bonus'] != 'none':
|
48 |
+
apply_bonus(coin['bonus'])
|
49 |
game_state['flips_left'] -= 1
|
50 |
|
|
|
|
|
|
|
|
|
51 |
return jsonify({
|
52 |
'result': 'H' if is_heads else 'T',
|
53 |
'balance': game_state['balance'],
|
|
|
75 |
price (higher than 10),
|
76 |
value (higher than 0.1),
|
77 |
winrate (between 0.5 and 0.8),
|
78 |
+
bonus (a bonus effect that triggers on successful flips, e.g., '+2 flips_left', '+0.5 balance', 'none')
|
79 |
|
80 |
Example:
|
81 |
{
|
|
|
84 |
"price": 15,
|
85 |
"value": 0.2,
|
86 |
"winrate": 0.65,
|
87 |
+
"bonus": "+2 flips_left"
|
88 |
}
|
89 |
"""
|
90 |
|
|
|
125 |
return jsonify({'success': True})
|
126 |
|
127 |
def validate_coin(coin):
|
128 |
+
required_keys = ['name', 'color', 'price', 'value', 'winrate', 'bonus']
|
129 |
return all(key in coin for key in required_keys) and \
|
130 |
isinstance(coin['name'], str) and \
|
131 |
isinstance(coin['color'], str) and coin['color'].startswith('#') and \
|
132 |
isinstance(coin['price'], (int, float)) and coin['price'] > 10 and \
|
133 |
isinstance(coin['value'], (int, float)) and coin['value'] > 0.1 and \
|
134 |
isinstance(coin['winrate'], (int, float)) and 0.5 <= coin['winrate'] <= 0.8 and \
|
135 |
+
isinstance(coin['bonus'], str)
|
136 |
+
|
137 |
+
def apply_bonus(bonus):
|
138 |
+
if bonus.startswith('+'):
|
139 |
+
value, attribute = bonus.split()[0][1:], bonus.split()[1]
|
140 |
+
if attribute == 'flips_left':
|
141 |
+
game_state['flips_left'] += int(value)
|
142 |
+
elif attribute == 'balance':
|
143 |
+
game_state['balance'] += float(value)
|
|
|
|
|
144 |
|
145 |
if __name__ == '__main__':
|
146 |
app.run(host='0.0.0.0', port=7860)
|