awacke1 commited on
Commit
8b4d5c0
1 Parent(s): 71fc926

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -32
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import os
3
  import csv
@@ -55,7 +56,6 @@ def start_game():
55
 
56
  game_deck, dealer, player, game_play = start_game()
57
 
58
-
59
  def display_pro_tip(player, dealer):
60
  player_total = sum(card.rank for card in player.cards)
61
 
@@ -92,12 +92,6 @@ def calculate_hand_total(hand):
92
  total = sum(card.rank for card in hand)
93
  return total
94
 
95
- def calculate_probability(player_total, dealer_upcard):
96
- # Placeholder probability calculation
97
- # Replace with actual probability calculation based on player's total and dealer's upcard
98
- probability = (21 - player_total) / (21 - dealer_upcard) * 100
99
- return probability
100
-
101
  st.title('🃏Blackjack Simulator AI♠2️⃣1️⃣')
102
 
103
  if st.button('New hand?'):
@@ -112,7 +106,6 @@ dealer_images = st.empty()
112
  result = st.empty()
113
  pro_tip = st.empty()
114
  betting_strategy = st.empty()
115
- probability_table = st.empty()
116
 
117
  while True:
118
  game_play.update()
@@ -126,39 +119,22 @@ while True:
126
  betting_strategy.write(display_betting_strategy(player, dealer))
127
 
128
  player_total = calculate_hand_total(player.cards)
129
- dealer_upcard = dealer.cards[0].rank if dealer.cards else 0
130
-
131
- probability = calculate_probability(player_total, dealer_upcard)
132
- probability_table.table(
133
- [["Player's Total", "Dealer's Upcard", "Probability of Winning"]],
134
- [[str(player_total), str(dealer_upcard), f"{probability:.2f}%"]]
135
- )
136
 
137
- if player_total == 21 or not player.possible_actions:
138
  break
139
 
140
- if 'Hit' in player.possible_actions or 'Double Down' in player.possible_actions or 'Stand' in player.possible_actions:
141
- action = player_action.radio("Choose your action", ("👋 Hit", "⏬ Double Down", "🚫 Stand"), key=f"action_{len(player.cards)}")
142
 
143
  if action == "👋 Hit":
144
  player.player_hit(game_deck, game_play)
145
  elif action == "⏬ Double Down":
146
  player.double_down(game_deck, game_play)
147
- elif action == "🚫 Stand":
148
- player.stand(game_play)
149
- break
150
 
151
- if done_button.button("✅ Done", key=f"done_{len(player.cards)}"):
 
 
152
  player.stand(game_play)
153
- break
154
 
155
- # Dealer's turn
156
- while calculate_hand_total(dealer.cards) < 17:
157
- dealer.dealer_hit(game_deck)
158
 
159
- game_play.update()
160
- player_stats.write(player)
161
- player_images.image([Image.open(card.image_location) for card in player.cards], width=100)
162
- dealer_stats.write(dealer)
163
- dealer_images.image([Image.open(card.image_location) for card in dealer.cards], width=100)
164
- result.write(game_play)
 
1
+
2
  import streamlit as st
3
  import os
4
  import csv
 
56
 
57
  game_deck, dealer, player, game_play = start_game()
58
 
 
59
  def display_pro_tip(player, dealer):
60
  player_total = sum(card.rank for card in player.cards)
61
 
 
92
  total = sum(card.rank for card in hand)
93
  return total
94
 
 
 
 
 
 
 
95
  st.title('🃏Blackjack Simulator AI♠2️⃣1️⃣')
96
 
97
  if st.button('New hand?'):
 
106
  result = st.empty()
107
  pro_tip = st.empty()
108
  betting_strategy = st.empty()
 
109
 
110
  while True:
111
  game_play.update()
 
119
  betting_strategy.write(display_betting_strategy(player, dealer))
120
 
121
  player_total = calculate_hand_total(player.cards)
122
+ dealer_total = calculate_hand_total(dealer.cards)
 
 
 
 
 
 
123
 
124
+ if player_total == 21 or dealer_total == 21 or not player.possible_actions:
125
  break
126
 
127
+ if 'Hit' in player.possible_actions or 'Double Down' in player.possible_actions:
128
+ action = player_action.radio("Choose your action", ("👋 Hit", "⏬ Double Down"), key=f"action_{len(player.cards)}")
129
 
130
  if action == "👋 Hit":
131
  player.player_hit(game_deck, game_play)
132
  elif action == "⏬ Double Down":
133
  player.double_down(game_deck, game_play)
 
 
 
134
 
135
+ if done_button.button("✅ Done", key=f"done_{len(player.cards)}"):
136
+ player.stand(game_play)
137
+ else:
138
  player.stand(game_play)
 
139
 
 
 
 
140