awacke1 commited on
Commit
4abf612
1 Parent(s): 650dd18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -28
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import os
3
  import csv
@@ -88,6 +89,10 @@ def display_betting_strategy(player, dealer):
88
  else:
89
  return ""
90
 
 
 
 
 
91
  st.title('🃏Blackjack Simulator AI♠2️⃣1️⃣')
92
 
93
  if st.button('New hand?'):
@@ -95,40 +100,14 @@ if st.button('New hand?'):
95
 
96
  player_stats = st.empty()
97
  player_images = st.empty()
98
- player_hit_option = st.empty()
99
- player_double_down_option = st.empty()
100
- player_stand_option = st.empty()
101
  dealer_stats = st.empty()
102
  dealer_images = st.empty()
103
  result = st.empty()
104
  pro_tip = st.empty()
105
  betting_strategy = st.empty()
106
 
107
- def calculate_hand_total(hand):
108
- total = sum(card.rank for card in hand)
109
- return total
110
-
111
  while True:
112
- if 'Hit' in player.possible_actions:
113
- if player_hit_option.button('Hit'):
114
- player.player_hit(game_deck, game_play)
115
- if 'Hit' not in player.possible_actions:
116
- player_hit_option.empty()
117
-
118
- if 'Double Down' in player.possible_actions:
119
- if player_double_down_option.button('Double Down'):
120
- player.double_down(game_deck, game_play)
121
- player_double_down_option.empty()
122
- player_hit_option.empty()
123
- player_stand_option.empty()
124
-
125
- if 'Stand' in player.possible_actions:
126
- if player_stand_option.button('Stand'):
127
- player.stand(game_play)
128
- player_hit_option.empty()
129
- player_double_down_option.empty()
130
- player_stand_option.empty()
131
-
132
  game_play.update()
133
  player_stats.write(player)
134
  player_images.image([Image.open(card.image_location) for card in player.cards], width=100)
@@ -143,4 +122,13 @@ while True:
143
  dealer_total = calculate_hand_total(dealer.cards)
144
 
145
  if player_total == 21 or dealer_total == 21 or not player.possible_actions:
146
- break
 
 
 
 
 
 
 
 
 
 
1
+
2
  import streamlit as st
3
  import os
4
  import csv
 
89
  else:
90
  return ""
91
 
92
+ def calculate_hand_total(hand):
93
+ total = sum(card.rank for card in hand)
94
+ return total
95
+
96
  st.title('🃏Blackjack Simulator AI♠2️⃣1️⃣')
97
 
98
  if st.button('New hand?'):
 
100
 
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()
107
  pro_tip = st.empty()
108
  betting_strategy = st.empty()
109
 
 
 
 
 
110
  while True:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  game_play.update()
112
  player_stats.write(player)
113
  player_images.image([Image.open(card.image_location) for card in player.cards], width=100)
 
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
+ 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)