awacke1 commited on
Commit
32c96cc
1 Parent(s): 4abf612

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -35
app.py CHANGED
@@ -45,7 +45,6 @@ def store_message(name: str, message: str):
45
  commit_url = repo.push_to_hub()
46
  return generate_html()
47
 
48
-
49
  # Initialize player, dealer, deck and game play. Cache these variables
50
  @st.cache(allow_output_mutation=True, suppress_st_warning=True)
51
  def start_game():
@@ -58,36 +57,10 @@ def start_game():
58
  game_deck, dealer, player, game_play = start_game()
59
 
60
  def display_pro_tip(player, dealer):
61
- player_total = sum(card.rank for card in player.cards)
62
-
63
- if dealer.cards:
64
- dealer_upcard = dealer.cards[0].rank
65
- else:
66
- dealer_upcard = 0
67
-
68
- if player_total <= 11:
69
- return "Pro Tip: With a total of 11 or less, it's generally advisable to hit."
70
- elif player_total == 12 and dealer_upcard <= 3:
71
- return "Pro Tip: With a total of 12 and the dealer showing 3 or less, consider hitting."
72
- elif player_total >= 17:
73
- return "Pro Tip: With a total of 17 or more, it's usually best to stand."
74
- else:
75
- return ""
76
 
77
  def display_betting_strategy(player, dealer):
78
- player_total = sum(card.rank for card in player.cards)
79
-
80
- if dealer.cards:
81
- dealer_upcard = dealer.cards[0].rank
82
- else:
83
- dealer_upcard = 0
84
-
85
- if player_total <= 11:
86
- return "Betting Strategy: Consider increasing your bet when your total is 11 or less."
87
- elif player_total >= 17 and dealer_upcard <= 6:
88
- return "Betting Strategy: Consider increasing your bet when you have a strong hand and the dealer has a weak upcard."
89
- else:
90
- return ""
91
 
92
  def calculate_hand_total(hand):
93
  total = sum(card.rank for card in hand)
@@ -101,6 +74,7 @@ if st.button('New hand?'):
101
  player_stats = st.empty()
102
  player_images = st.empty()
103
  player_action = st.empty()
 
104
  dealer_stats = st.empty()
105
  dealer_images = st.empty()
106
  result = st.empty()
@@ -124,11 +98,17 @@ while True:
124
  if player_total == 21 or dealer_total == 21 or not player.possible_actions:
125
  break
126
 
127
- action = player_action.radio("Choose your action", ("👋 Hit", "⏹️ Stand", "⏬ Double Down"), key=f"action_{len(player.cards)}")
 
 
 
 
 
 
128
 
129
- if action == "👋 Hit":
130
- player.player_hit(game_deck, game_play)
131
- elif action == "⏹️ Stand":
132
  player.stand(game_play)
133
- elif action == "⏬ Double Down":
134
- player.double_down(game_deck, game_play)
 
45
  commit_url = repo.push_to_hub()
46
  return generate_html()
47
 
 
48
  # Initialize player, dealer, deck and game play. Cache these variables
49
  @st.cache(allow_output_mutation=True, suppress_st_warning=True)
50
  def start_game():
 
57
  game_deck, dealer, player, game_play = start_game()
58
 
59
  def display_pro_tip(player, dealer):
60
+ # ... (same as before)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  def display_betting_strategy(player, dealer):
63
+ # ... (same as before)
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  def calculate_hand_total(hand):
66
  total = sum(card.rank for card in hand)
 
74
  player_stats = st.empty()
75
  player_images = st.empty()
76
  player_action = st.empty()
77
+ done_button = st.empty()
78
  dealer_stats = st.empty()
79
  dealer_images = st.empty()
80
  result = st.empty()
 
98
  if player_total == 21 or dealer_total == 21 or not player.possible_actions:
99
  break
100
 
101
+ if 'Hit' in player.possible_actions or 'Double Down' in player.possible_actions:
102
+ action = player_action.radio("Choose your action", ("👋 Hit", "⏬ Double Down"), key=f"action_{len(player.cards)}")
103
+
104
+ if action == "👋 Hit":
105
+ player.player_hit(game_deck, game_play)
106
+ elif action == "⏬ Double Down":
107
+ player.double_down(game_deck, game_play)
108
 
109
+ if done_button.button("✅ Done", key=f"done_{len(player.cards)}"):
110
+ player.stand(game_play)
111
+ else:
112
  player.stand(game_play)
113
+
114
+