Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
from components import GamePlay, Player, Dealer, Deck
|
4 |
+
|
5 |
+
|
6 |
+
# Game settings
|
7 |
+
number_of_decks = 6
|
8 |
+
blackjack_multiplier = 1.5
|
9 |
+
|
10 |
+
|
11 |
+
# Initialize player, dealer, deck and game play. Cache these variables
|
12 |
+
@st.cache(allow_output_mutation=True, suppress_st_warning=True)
|
13 |
+
def start_game():
|
14 |
+
game_deck = Deck(number_of_decks)
|
15 |
+
dealer = Dealer()
|
16 |
+
player = Player()
|
17 |
+
game_play = GamePlay(player, dealer, game_deck, blackjack_multiplier)
|
18 |
+
return game_deck, dealer, player, game_play
|
19 |
+
|
20 |
+
|
21 |
+
game_deck, dealer, player, game_play = start_game()
|
22 |
+
|
23 |
+
st.title('BlackJack Simulator')
|
24 |
+
|
25 |
+
if st.button('New hand?'):
|
26 |
+
game_play.deal_in()
|
27 |
+
|
28 |
+
|
29 |
+
player_stats = st.empty()
|
30 |
+
player_images = st.empty()
|
31 |
+
player_hit_option = st.empty()
|
32 |
+
player_double_down_option = st.empty()
|
33 |
+
player_stand_option = st.empty()
|
34 |
+
dealer_stats = st.empty()
|
35 |
+
dealer_images = st.empty()
|
36 |
+
result = st.empty()
|
37 |
+
|
38 |
+
|
39 |
+
if 'Hit' in player.possible_actions:
|
40 |
+
if player_hit_option.button('Hit'):
|
41 |
+
player.player_hit(game_deck, game_play)
|
42 |
+
if 'Hit' not in player.possible_actions:
|
43 |
+
player_hit_option.empty()
|
44 |
+
if 'Double Down' in player.possible_actions:
|
45 |
+
if player_double_down_option.button('Double Down'):
|
46 |
+
player.double_down(game_deck, game_play)
|
47 |
+
player_double_down_option.empty()
|
48 |
+
player_hit_option.empty()
|
49 |
+
player_stand_option.empty()
|
50 |
+
if 'Stand' in player.possible_actions:
|
51 |
+
if player_stand_option.button('Stand'):
|
52 |
+
player.stand(game_play)
|
53 |
+
player_hit_option.empty()
|
54 |
+
player_double_down_option.empty()
|
55 |
+
player_stand_option.empty()
|
56 |
+
|
57 |
+
|
58 |
+
game_play.update()
|
59 |
+
player_stats.write(player)
|
60 |
+
player_images.image([Image.open(card.image_location)
|
61 |
+
for card in player.cards], width=100)
|
62 |
+
dealer_stats.write(dealer)
|
63 |
+
dealer_images.image([Image.open(card.image_location)
|
64 |
+
for card in dealer.cards], width=100)
|
65 |
+
result.write(game_play)
|