awacke1 commited on
Commit
ee80c61
1 Parent(s): 54e8962

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -67
app.py CHANGED
@@ -1,8 +1,8 @@
1
-
2
  import streamlit as st
3
  import os
4
  import csv
5
  import huggingface_hub
 
6
  from PIL import Image
7
  from components import GamePlay, Player, Dealer, Deck
8
  from huggingface_hub import Repository, hf_hub_download, upload_file
@@ -56,42 +56,6 @@ def start_game():
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
-
62
- if dealer.cards:
63
- dealer_upcard = dealer.cards[0].rank
64
- else:
65
- dealer_upcard = 0
66
-
67
- if player_total <= 11:
68
- return "Pro Tip: With a total of 11 or less, it's generally advisable to hit."
69
- elif player_total == 12 and dealer_upcard <= 3:
70
- return "Pro Tip: With a total of 12 and the dealer showing 3 or less, consider hitting."
71
- elif player_total >= 17:
72
- return "Pro Tip: With a total of 17 or more, it's usually best to stand."
73
- else:
74
- return ""
75
-
76
- def display_betting_strategy(player, dealer):
77
- player_total = sum(card.rank for card in player.cards)
78
-
79
- if dealer.cards:
80
- dealer_upcard = dealer.cards[0].rank
81
- else:
82
- dealer_upcard = 0
83
-
84
- if player_total <= 11:
85
- return "Betting Strategy: Consider increasing your bet when your total is 11 or less."
86
- elif player_total >= 17 and dealer_upcard <= 6:
87
- return "Betting Strategy: Consider increasing your bet when you have a strong hand and the dealer has a weak upcard."
88
- else:
89
- return ""
90
-
91
- def calculate_hand_total(hand):
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?'):
@@ -99,42 +63,43 @@ if st.button('New hand?'):
99
 
100
  player_stats = st.empty()
101
  player_images = st.empty()
102
- player_action = st.empty()
103
- done_button = 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)
114
- dealer_stats.write(dealer)
115
- dealer_images.image([Image.open(card.image_location) for card in dealer.cards], width=100)
116
- result.write(game_play)
117
-
118
- pro_tip.write(display_pro_tip(player, dealer))
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
 
 
 
1
  import streamlit as st
2
  import os
3
  import csv
4
  import huggingface_hub
5
+
6
  from PIL import Image
7
  from components import GamePlay, Player, Dealer, Deck
8
  from huggingface_hub import Repository, hf_hub_download, upload_file
 
56
 
57
  game_deck, dealer, player, game_play = start_game()
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  st.title('🃏Blackjack Simulator AI♠2️⃣1️⃣')
60
 
61
  if st.button('New hand?'):
 
63
 
64
  player_stats = st.empty()
65
  player_images = st.empty()
66
+ player_hit_option = st.empty()
67
+ player_double_down_option = st.empty()
68
+ player_stand_option = st.empty()
69
  dealer_stats = st.empty()
70
  dealer_images = st.empty()
71
  result = st.empty()
 
 
72
 
73
+ if 'Hit' in player.possible_actions:
74
+ if player_hit_option.button('Hit'):
75
+ player.player_hit(game_deck, game_play)
76
+ if 'Hit' not in player.possible_actions:
77
+ player_hit_option.empty()
78
+
79
+ if 'Double Down' in player.possible_actions:
80
+ if player_double_down_option.button('Double Down'):
81
+ player.double_down(game_deck, game_play)
82
+ player_double_down_option.empty()
83
+ player_hit_option.empty()
84
+ player_stand_option.empty()
85
+
86
+ if 'Stand' in player.possible_actions:
87
+ if player_stand_option.button('Stand'):
88
+ player.stand(game_play)
89
+ player_hit_option.empty()
90
+ player_double_down_option.empty()
91
+ player_stand_option.empty()
92
 
93
+ game_play.update()
94
+ player_stats.write(player)
95
+ player_images.image([Image.open(card.image_location)
96
+ for card in player.cards], width=100)
97
+ dealer_stats.write(dealer)
98
+ dealer_images.image([Image.open(card.image_location)
99
+ for card in dealer.cards], width=100)
100
+
101
+ result.write(game_play)
102
 
 
 
 
 
103
 
 
 
 
 
104
 
105