funcasino 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- funcasino/__init__.py +0 -0
- funcasino/__main__.py +69 -0
- funcasino/blackjack.py +269 -0
- funcasino/card_art.py +46 -0
- funcasino/cointoss.py +104 -0
- funcasino/craps.py +183 -0
- funcasino/deck.py +48 -0
- funcasino/roulette.py +370 -0
- funcasino/slots.py +248 -0
- funcasino/stats.py +37 -0
- funcasino/wallet.py +28 -0
- funcasino/war.py +131 -0
- funcasino-0.0.1.dist-info/METADATA +365 -0
- funcasino-0.0.1.dist-info/RECORD +17 -0
- funcasino-0.0.1.dist-info/WHEEL +5 -0
- funcasino-0.0.1.dist-info/licenses/LICENSE +674 -0
- funcasino-0.0.1.dist-info/top_level.txt +1 -0
funcasino/__init__.py
ADDED
|
File without changes
|
funcasino/__main__.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from funcasino.wallet import Wallet
|
|
2
|
+
from funcasino.slots import Slots
|
|
3
|
+
from funcasino.cointoss import CoinToss
|
|
4
|
+
from funcasino.craps import Craps
|
|
5
|
+
from funcasino.blackjack import Blackjack
|
|
6
|
+
from funcasino.war import War
|
|
7
|
+
from funcasino.roulette import Roulette
|
|
8
|
+
from funcasino.stats import show_stats
|
|
9
|
+
|
|
10
|
+
LINE = " " + "─" * 39
|
|
11
|
+
|
|
12
|
+
def show_menu(balance):
|
|
13
|
+
print()
|
|
14
|
+
print(" ♠ ♥ ♦ ♣ F U N C A S I N O ♣ ♦ ♥ ♠")
|
|
15
|
+
print(LINE)
|
|
16
|
+
print(f" Balance: ${balance}")
|
|
17
|
+
print()
|
|
18
|
+
print(" 1 ▸ Slots 2 ▸ Coin Toss")
|
|
19
|
+
print(" 3 ▸ Craps 4 ▸ Blackjack")
|
|
20
|
+
print(" 5 ▸ War 6 ▸ Roulette")
|
|
21
|
+
print(" 7 ▸ Stats Q ▸ Quit")
|
|
22
|
+
print(LINE)
|
|
23
|
+
|
|
24
|
+
def main():
|
|
25
|
+
wallet = Wallet(100)
|
|
26
|
+
slots = Slots(wallet)
|
|
27
|
+
cointoss = CoinToss(wallet)
|
|
28
|
+
craps = Craps(wallet)
|
|
29
|
+
blackjack = Blackjack(wallet)
|
|
30
|
+
war = War(wallet)
|
|
31
|
+
roulette = Roulette(wallet=wallet)
|
|
32
|
+
|
|
33
|
+
games = {
|
|
34
|
+
"1": slots.play,
|
|
35
|
+
"2": cointoss.play,
|
|
36
|
+
"3": craps.play,
|
|
37
|
+
"4": blackjack.play,
|
|
38
|
+
"5": war.play_round,
|
|
39
|
+
"6": roulette.run,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
game_stats = {
|
|
43
|
+
"Slots": slots,
|
|
44
|
+
"Coin Toss": cointoss,
|
|
45
|
+
"Craps": craps,
|
|
46
|
+
"Blackjack": blackjack,
|
|
47
|
+
"War": war,
|
|
48
|
+
"Roulette": roulette,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
while wallet.balance > 0:
|
|
52
|
+
show_menu(wallet.balance)
|
|
53
|
+
choice = input(" Choose a game: ").lower()
|
|
54
|
+
if choice == "q":
|
|
55
|
+
break
|
|
56
|
+
if choice in games:
|
|
57
|
+
games[choice]()
|
|
58
|
+
elif choice == "7":
|
|
59
|
+
show_stats(game_stats, wallet)
|
|
60
|
+
input(" Press Enter to continue: ")
|
|
61
|
+
else:
|
|
62
|
+
print(" Please enter a valid option.")
|
|
63
|
+
|
|
64
|
+
show_stats(game_stats, wallet)
|
|
65
|
+
if wallet.balance <= 0:
|
|
66
|
+
print("Thank you for your generous donation to the house!")
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
main()
|
funcasino/blackjack.py
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
from funcasino.wallet import Wallet
|
|
2
|
+
from funcasino.deck import Deck
|
|
3
|
+
import time
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
class Blackjack:
|
|
7
|
+
def __init__(self, wallet=None):
|
|
8
|
+
self.wallet = wallet or Wallet()
|
|
9
|
+
self.wins = 0
|
|
10
|
+
self.losses = 0
|
|
11
|
+
self.pushes = 0
|
|
12
|
+
self.max_hands = 4
|
|
13
|
+
|
|
14
|
+
def hand_value(self, hand):
|
|
15
|
+
total = sum(card.blackjack_value() for card in hand)
|
|
16
|
+
aces = sum(card.rank == "A" for card in hand)
|
|
17
|
+
|
|
18
|
+
while total > 21 and aces > 0:
|
|
19
|
+
total -= 10
|
|
20
|
+
aces -= 1
|
|
21
|
+
|
|
22
|
+
return total
|
|
23
|
+
|
|
24
|
+
def display_table(self, dealer_hand, hands, active_index=None, reveal_dealer=False):
|
|
25
|
+
os.system("cls" if os.name == "nt" else "clear")
|
|
26
|
+
print("\n--- Dealer ---")
|
|
27
|
+
|
|
28
|
+
if reveal_dealer:
|
|
29
|
+
for card in dealer_hand:
|
|
30
|
+
print(card)
|
|
31
|
+
print("Dealer Value:", self.hand_value(dealer_hand))
|
|
32
|
+
else:
|
|
33
|
+
print(dealer_hand[0])
|
|
34
|
+
print("Unknown")
|
|
35
|
+
|
|
36
|
+
for index, hand in enumerate(hands):
|
|
37
|
+
mark = ""
|
|
38
|
+
if index == active_index:
|
|
39
|
+
mark = "(Current hand)"
|
|
40
|
+
|
|
41
|
+
print(f"\n--- Player Hand {index + 1}{mark} ---")
|
|
42
|
+
for card in hand["cards"]:
|
|
43
|
+
print(card)
|
|
44
|
+
|
|
45
|
+
print("Player Value:", self.hand_value(hand["cards"]))
|
|
46
|
+
print(f"Bet: ${hand['bet']}")
|
|
47
|
+
print("Status:", hand["status"])
|
|
48
|
+
|
|
49
|
+
def get_bet(self):
|
|
50
|
+
while True:
|
|
51
|
+
bet = input(f"Current Balance: ${self.wallet.balance}. Enter your bet: $")
|
|
52
|
+
|
|
53
|
+
if not bet.isdigit():
|
|
54
|
+
print("Invalid bet.")
|
|
55
|
+
continue
|
|
56
|
+
bet = int(bet)
|
|
57
|
+
|
|
58
|
+
if bet <= 0 or not self.wallet.can_afford(bet):
|
|
59
|
+
print("Invalid bet.")
|
|
60
|
+
continue
|
|
61
|
+
|
|
62
|
+
self.wallet.withdraw(bet)
|
|
63
|
+
break
|
|
64
|
+
|
|
65
|
+
return bet
|
|
66
|
+
|
|
67
|
+
def can_split(self, hand, hands):
|
|
68
|
+
cards = hand["cards"]
|
|
69
|
+
status = hand["status"]
|
|
70
|
+
bet = hand["bet"]
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
status == "Playing"
|
|
74
|
+
and len(cards) == 2
|
|
75
|
+
and cards[0].blackjack_value() == cards[1].blackjack_value()
|
|
76
|
+
and len(hands) < self.max_hands
|
|
77
|
+
and self.wallet.can_afford(bet)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def split_hand(self, hands, index, deck):
|
|
81
|
+
hand = hands[index]
|
|
82
|
+
first_card = hand["cards"][0]
|
|
83
|
+
second_card = hand["cards"][1]
|
|
84
|
+
bet = hand["bet"]
|
|
85
|
+
|
|
86
|
+
self.wallet.withdraw(bet)
|
|
87
|
+
|
|
88
|
+
status = ""
|
|
89
|
+
if first_card.rank == "A":
|
|
90
|
+
status = "Standing"
|
|
91
|
+
else:
|
|
92
|
+
status = "Playing"
|
|
93
|
+
|
|
94
|
+
hands[index] = {
|
|
95
|
+
"cards": [first_card, deck.deal()],
|
|
96
|
+
"bet": bet,
|
|
97
|
+
"status": status
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
hands.insert(index + 1, {
|
|
101
|
+
"cards": [second_card, deck.deal()],
|
|
102
|
+
"bet": bet,
|
|
103
|
+
"status": status
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
print(f"\n Player Hand {index + 1} split. The additional bet is ${bet}.")
|
|
107
|
+
|
|
108
|
+
def check_for_blackjack(self, dealer_hand, hands):
|
|
109
|
+
hand = hands[0]
|
|
110
|
+
player_blackjack = self.hand_value(hand["cards"]) == 21
|
|
111
|
+
dealer_blackjack = self.hand_value(dealer_hand) == 21
|
|
112
|
+
|
|
113
|
+
if not player_blackjack and not dealer_blackjack:
|
|
114
|
+
return False
|
|
115
|
+
else:
|
|
116
|
+
self.display_table(dealer_hand, hands, reveal_dealer=True)
|
|
117
|
+
|
|
118
|
+
if player_blackjack and dealer_blackjack:
|
|
119
|
+
print("\nBoth player and dealer have blackjack. Push.")
|
|
120
|
+
self.pushes += 1
|
|
121
|
+
self.wallet.deposit(hand["bet"])
|
|
122
|
+
elif player_blackjack:
|
|
123
|
+
print("\nBlackjack! You win.")
|
|
124
|
+
self.wins += 1
|
|
125
|
+
self.wallet.deposit(hand["bet"] * 2.5)
|
|
126
|
+
else:
|
|
127
|
+
print("\nDealer has blackjack. You lose!")
|
|
128
|
+
self.losses += 1
|
|
129
|
+
|
|
130
|
+
return True
|
|
131
|
+
|
|
132
|
+
def play_player_hands(self, dealer_hand, hands, deck):
|
|
133
|
+
index = 0
|
|
134
|
+
|
|
135
|
+
while index < len(hands):
|
|
136
|
+
hand = hands[index]
|
|
137
|
+
|
|
138
|
+
if hand["status"] != "Playing":
|
|
139
|
+
index += 1
|
|
140
|
+
continue
|
|
141
|
+
|
|
142
|
+
value = self.hand_value(hand["cards"])
|
|
143
|
+
|
|
144
|
+
if value >= 21:
|
|
145
|
+
hand["status"] = "Bust" if value > 21 else "Standing"
|
|
146
|
+
self.display_table(dealer_hand, hands, index)
|
|
147
|
+
index += 1
|
|
148
|
+
continue
|
|
149
|
+
|
|
150
|
+
self.display_table(dealer_hand, hands, index)
|
|
151
|
+
|
|
152
|
+
print("\nWhat do you choose to do?")
|
|
153
|
+
print("1. Hit")
|
|
154
|
+
print("2. Stand")
|
|
155
|
+
if self.can_split(hand, hands):
|
|
156
|
+
print("3. Split")
|
|
157
|
+
|
|
158
|
+
choice = input("Select an option: ")
|
|
159
|
+
if choice == "1":
|
|
160
|
+
hand["cards"].append(deck.deal())
|
|
161
|
+
elif choice == "2":
|
|
162
|
+
hand["status"] = "Standing"
|
|
163
|
+
index += 1
|
|
164
|
+
elif choice == "3" and self.can_split(hand, hands):
|
|
165
|
+
self.split_hand(hands, index, deck)
|
|
166
|
+
else:
|
|
167
|
+
print("Invalid option.")
|
|
168
|
+
|
|
169
|
+
def play_dealer_hand(self, dealer_hand, hands, deck):
|
|
170
|
+
if all(self.hand_value(hand["cards"]) > 21 for hand in hands):
|
|
171
|
+
self.display_table(dealer_hand, hands, reveal_dealer=True)
|
|
172
|
+
return
|
|
173
|
+
|
|
174
|
+
while True:
|
|
175
|
+
self.display_table(dealer_hand, hands, reveal_dealer=True)
|
|
176
|
+
time.sleep(1.5)
|
|
177
|
+
|
|
178
|
+
value = self.hand_value(dealer_hand)
|
|
179
|
+
if value > 21:
|
|
180
|
+
print("\nDealer busts!")
|
|
181
|
+
return
|
|
182
|
+
if value >= 17:
|
|
183
|
+
print("\nDealer stands.")
|
|
184
|
+
return
|
|
185
|
+
print("\nDealer hits.")
|
|
186
|
+
time.sleep(1)
|
|
187
|
+
dealer_hand.append(deck.deal())
|
|
188
|
+
|
|
189
|
+
def settle_all_hands(self, dealer_hand, hands):
|
|
190
|
+
dealer_value = self.hand_value(dealer_hand)
|
|
191
|
+
|
|
192
|
+
for index, hand in enumerate(hands):
|
|
193
|
+
value = self.hand_value(hand["cards"])
|
|
194
|
+
bet = hand["bet"]
|
|
195
|
+
print(f"\nPlayer Hand {index + 1} ({value}):")
|
|
196
|
+
|
|
197
|
+
if value > 21:
|
|
198
|
+
print("Bust! You lose.")
|
|
199
|
+
self.losses += 1
|
|
200
|
+
hand["status"] = "Lost"
|
|
201
|
+
elif dealer_value > 21 or value > dealer_value:
|
|
202
|
+
print("You win.")
|
|
203
|
+
self.wins += 1
|
|
204
|
+
self.wallet.deposit(bet * 2)
|
|
205
|
+
hand["status"] = "Won"
|
|
206
|
+
elif value < dealer_value:
|
|
207
|
+
print("Dealer wins.")
|
|
208
|
+
self.losses += 1
|
|
209
|
+
hand["status"] = "Lost"
|
|
210
|
+
else:
|
|
211
|
+
print("Both hands equal. Push.")
|
|
212
|
+
self.pushes += 1
|
|
213
|
+
self.wallet.deposit(bet)
|
|
214
|
+
hand["status"] = "Push"
|
|
215
|
+
|
|
216
|
+
def play_round(self):
|
|
217
|
+
bet = self.get_bet()
|
|
218
|
+
|
|
219
|
+
deck = Deck(8)
|
|
220
|
+
deck.shuffle()
|
|
221
|
+
|
|
222
|
+
dealer_hand = [deck.deal(), deck.deal()]
|
|
223
|
+
hands = [{
|
|
224
|
+
"cards": [deck.deal(), deck.deal()],
|
|
225
|
+
"bet": bet,
|
|
226
|
+
"status": "Playing"
|
|
227
|
+
}]
|
|
228
|
+
|
|
229
|
+
if self.check_for_blackjack(dealer_hand, hands):
|
|
230
|
+
return
|
|
231
|
+
|
|
232
|
+
self.play_player_hands(dealer_hand, hands, deck)
|
|
233
|
+
self.play_dealer_hand(dealer_hand, hands, deck)
|
|
234
|
+
self.settle_all_hands(dealer_hand, hands)
|
|
235
|
+
|
|
236
|
+
def show_stats(self):
|
|
237
|
+
total = self.wins + self.losses + self.pushes
|
|
238
|
+
win_rate = (self.wins / total * 100) if total else 0
|
|
239
|
+
|
|
240
|
+
print(f"\nWins: {self.wins}")
|
|
241
|
+
print(f"Losses: {self.losses}")
|
|
242
|
+
print(f"Pushes: {self.pushes}")
|
|
243
|
+
print(f"Win rate: {win_rate:.1f}%")
|
|
244
|
+
print(f"Balance: ${self.wallet.balance}")
|
|
245
|
+
|
|
246
|
+
def play(self):
|
|
247
|
+
while self.wallet.balance > 0:
|
|
248
|
+
print("\n--- BLACKJACK ---")
|
|
249
|
+
print("1. Play")
|
|
250
|
+
print("2. View Stats")
|
|
251
|
+
print("3. Quit")
|
|
252
|
+
|
|
253
|
+
choice = input("Select an option: ")
|
|
254
|
+
|
|
255
|
+
if choice == "1":
|
|
256
|
+
self.play_round()
|
|
257
|
+
elif choice == "2":
|
|
258
|
+
self.show_stats()
|
|
259
|
+
elif choice == "3":
|
|
260
|
+
break
|
|
261
|
+
else:
|
|
262
|
+
print("Invalid option.")
|
|
263
|
+
|
|
264
|
+
print("\nYou ran out of money. Thanks for playing!")
|
|
265
|
+
print("Here are your final stats!")
|
|
266
|
+
self.show_stats()
|
|
267
|
+
|
|
268
|
+
if __name__ == "__main__":
|
|
269
|
+
Blackjack().play()
|
funcasino/card_art.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
SUIT_SYMBOLS = {
|
|
2
|
+
"Hearts": "♥",
|
|
3
|
+
"Diamonds": "♦",
|
|
4
|
+
"Clubs": "♣",
|
|
5
|
+
"Spades": "♠",
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
CARD_BACK = (
|
|
9
|
+
"┌─────────┐",
|
|
10
|
+
"│░░░░░░░░░│",
|
|
11
|
+
"│░░░░░░░░░│",
|
|
12
|
+
"│░░░░░░░░░│",
|
|
13
|
+
"│░░░░░░░░░│",
|
|
14
|
+
"│░░░░░░░░░│",
|
|
15
|
+
"└─────────┘",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def card_lines(card):
|
|
20
|
+
suit = SUIT_SYMBOLS[card.suit]
|
|
21
|
+
rank = card.rank # "10" is 2 characters wide, so pad it with ljust/rjust
|
|
22
|
+
return (
|
|
23
|
+
"┌─────────┐",
|
|
24
|
+
f"│ {rank.ljust(2)} │",
|
|
25
|
+
"│ │",
|
|
26
|
+
f"│ {suit} │",
|
|
27
|
+
"│ │",
|
|
28
|
+
f"│ {rank.rjust(2)} │",
|
|
29
|
+
"└─────────┘",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def render_cards(*cards, gap=" "):
|
|
34
|
+
arts = [CARD_BACK if card is None else card_lines(card) for card in cards]
|
|
35
|
+
return "\n".join(gap.join(art[row] for art in arts) for row in range(len(CARD_BACK)))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def render_battle(player_card, dealer_card):
|
|
39
|
+
width = len(CARD_BACK[0])
|
|
40
|
+
left, right = card_lines(player_card), card_lines(dealer_card)
|
|
41
|
+
middle = len(left) // 2
|
|
42
|
+
rows = ["Player".center(width) + " " + "Dealer".center(width)]
|
|
43
|
+
for i in range(len(left)):
|
|
44
|
+
gap = " vs " if i == middle else " "
|
|
45
|
+
rows.append(left[i] + gap + right[i])
|
|
46
|
+
return "\n".join(rows)
|
funcasino/cointoss.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import sys
|
|
3
|
+
import time
|
|
4
|
+
from funcasino.wallet import Wallet
|
|
5
|
+
|
|
6
|
+
class CoinToss:
|
|
7
|
+
def __init__(self, wallet=None):
|
|
8
|
+
self.wallet = wallet or Wallet()
|
|
9
|
+
self.wins = 0
|
|
10
|
+
self.losses = 0
|
|
11
|
+
self.history = []
|
|
12
|
+
|
|
13
|
+
def animate_flip(self, result, num_frames=12):
|
|
14
|
+
print("Flipping coin...")
|
|
15
|
+
|
|
16
|
+
frames = ["HEADS", "TAILS"]
|
|
17
|
+
start = frames.index(result.upper()) - (num_frames - 1)
|
|
18
|
+
|
|
19
|
+
for i in range(num_frames):
|
|
20
|
+
frame = frames[(start + i) % 2]
|
|
21
|
+
sys.stdout.write(f"\r🪙 {frame} ")
|
|
22
|
+
sys.stdout.flush()
|
|
23
|
+
time.sleep(0.1 + i * 0.025)
|
|
24
|
+
|
|
25
|
+
print()
|
|
26
|
+
|
|
27
|
+
def flip_coin(self):
|
|
28
|
+
return random.choice(["heads", "tails"])
|
|
29
|
+
|
|
30
|
+
def place_bet(self):
|
|
31
|
+
while True:
|
|
32
|
+
try:
|
|
33
|
+
bet = int(input(f"Balance: ${self.wallet.balance}. Enter bet: $"))
|
|
34
|
+
|
|
35
|
+
if 0 < bet <= self.wallet.balance:
|
|
36
|
+
return bet
|
|
37
|
+
|
|
38
|
+
print("Invalid bet amount.")
|
|
39
|
+
|
|
40
|
+
except ValueError:
|
|
41
|
+
print("Please enter a valid number.")
|
|
42
|
+
|
|
43
|
+
def play_round(self):
|
|
44
|
+
bet = self.place_bet()
|
|
45
|
+
|
|
46
|
+
choice = input("Heads or tails: ").lower()
|
|
47
|
+
|
|
48
|
+
while choice not in ["heads", "tails"]:
|
|
49
|
+
choice = input("Please enter heads or tails: ").lower()
|
|
50
|
+
|
|
51
|
+
result = self.flip_coin()
|
|
52
|
+
self.animate_flip(result)
|
|
53
|
+
|
|
54
|
+
print(f"The coin landed on {result.upper()}!")
|
|
55
|
+
|
|
56
|
+
if choice == result:
|
|
57
|
+
self.wallet.deposit(bet)
|
|
58
|
+
self.wins += 1
|
|
59
|
+
print(f"You won ${bet}!")
|
|
60
|
+
else:
|
|
61
|
+
self.wallet.withdraw(bet)
|
|
62
|
+
self.losses += 1
|
|
63
|
+
print(f"You lost ${bet}!")
|
|
64
|
+
|
|
65
|
+
self.history.append({
|
|
66
|
+
"bet": bet,
|
|
67
|
+
"choice": choice,
|
|
68
|
+
"result": result,
|
|
69
|
+
"balance": self.wallet.balance
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
def show_stats(self):
|
|
73
|
+
total = self.wins + self.losses
|
|
74
|
+
win_rate = (self.wins / total * 100) if total else 0
|
|
75
|
+
|
|
76
|
+
print(f"\nWins: {self.wins}")
|
|
77
|
+
print(f"Losses: {self.losses}")
|
|
78
|
+
print(f"Win rate: {win_rate:.1f}%")
|
|
79
|
+
print(f"Balance: ${self.wallet.balance}")
|
|
80
|
+
|
|
81
|
+
def play(self):
|
|
82
|
+
while self.wallet.balance > 0:
|
|
83
|
+
print("\n--- COIN TOSS ---")
|
|
84
|
+
print("1. Play")
|
|
85
|
+
print("2. View Stats")
|
|
86
|
+
print("3. Quit")
|
|
87
|
+
|
|
88
|
+
choice = input("Select an option: ")
|
|
89
|
+
|
|
90
|
+
if choice == "1":
|
|
91
|
+
self.play_round()
|
|
92
|
+
elif choice == "2":
|
|
93
|
+
self.show_stats()
|
|
94
|
+
elif choice == "3":
|
|
95
|
+
break
|
|
96
|
+
else:
|
|
97
|
+
print("Invalid option.")
|
|
98
|
+
|
|
99
|
+
print("Thanks for playing!")
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
if __name__ == "__main__":
|
|
103
|
+
game = CoinToss()
|
|
104
|
+
game.play()
|
funcasino/craps.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import random
|
|
2
|
+
from funcasino.wallet import Wallet
|
|
3
|
+
import sys
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
dice_art = {
|
|
7
|
+
1: ("┌─────────┐",
|
|
8
|
+
"│ │",
|
|
9
|
+
"│ ● │",
|
|
10
|
+
"│ │",
|
|
11
|
+
"└─────────┘"),
|
|
12
|
+
2: ("┌─────────┐",
|
|
13
|
+
"│ ● │",
|
|
14
|
+
"│ │",
|
|
15
|
+
"│ ● │",
|
|
16
|
+
"└─────────┘"),
|
|
17
|
+
3: ("┌─────────┐",
|
|
18
|
+
"│ ● │",
|
|
19
|
+
"│ ● │",
|
|
20
|
+
"│ ● │",
|
|
21
|
+
"└─────────┘"),
|
|
22
|
+
4: ("┌─────────┐",
|
|
23
|
+
"│ ● ● │",
|
|
24
|
+
"│ │",
|
|
25
|
+
"│ ● ● │",
|
|
26
|
+
"└─────────┘"),
|
|
27
|
+
5: ("┌─────────┐",
|
|
28
|
+
"│ ● ● │",
|
|
29
|
+
"│ ● │",
|
|
30
|
+
"│ ● ● │",
|
|
31
|
+
"└─────────┘"),
|
|
32
|
+
6: ("┌─────────┐",
|
|
33
|
+
"│ ● ● │",
|
|
34
|
+
"│ ● ● │",
|
|
35
|
+
"│ ● ● │",
|
|
36
|
+
"└─────────┘")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class Craps:
|
|
40
|
+
def __init__(self, wallet=None):
|
|
41
|
+
self.wallet = wallet or Wallet()
|
|
42
|
+
self.wins = 0
|
|
43
|
+
self.losses = 0
|
|
44
|
+
|
|
45
|
+
def print_dice(self, dice1, dice2):
|
|
46
|
+
# these are all for the animation
|
|
47
|
+
for i in range(5):
|
|
48
|
+
d1 = random.randint(1,6)
|
|
49
|
+
d2 = random.randint(1,6)
|
|
50
|
+
for line in range(5):
|
|
51
|
+
print(dice_art[d1][line] + " " + dice_art[d2][line])
|
|
52
|
+
sys.stdout.write("\033[5A") # moves the cursor back up 5 lines each time so the dice animate in place
|
|
53
|
+
time.sleep(0.1 + i * 0.01)
|
|
54
|
+
|
|
55
|
+
#prints the actual result
|
|
56
|
+
for line in range(5):
|
|
57
|
+
print(dice_art[dice1][line] + " " + dice_art[dice2][line])
|
|
58
|
+
|
|
59
|
+
def roll_dice(self):
|
|
60
|
+
dice1 = random.randint(1, 6)
|
|
61
|
+
dice2 = random.randint(1, 6)
|
|
62
|
+
self.print_dice(dice1, dice2)
|
|
63
|
+
return dice1, dice2, dice1 + dice2
|
|
64
|
+
|
|
65
|
+
def place_bet(self):
|
|
66
|
+
while True:
|
|
67
|
+
try:
|
|
68
|
+
bet = int(input(f"Balance: ${self.wallet.balance}. Enter bet: $"))
|
|
69
|
+
|
|
70
|
+
if 0 < bet <= self.wallet.balance:
|
|
71
|
+
self.wallet.withdraw(bet)
|
|
72
|
+
return bet
|
|
73
|
+
|
|
74
|
+
print("Invalid bet amount.")
|
|
75
|
+
|
|
76
|
+
except ValueError:
|
|
77
|
+
print("Please enter a valid number.")
|
|
78
|
+
|
|
79
|
+
def play_round(self):
|
|
80
|
+
bet = self.place_bet()
|
|
81
|
+
|
|
82
|
+
input("Press Enter to roll the dice!")
|
|
83
|
+
dice1, dice2, sum1 = self.roll_dice()
|
|
84
|
+
print(f"Your total is {sum1}")
|
|
85
|
+
|
|
86
|
+
#first round, either 2x, 0x, or advances
|
|
87
|
+
if sum1 in (7, 11):
|
|
88
|
+
self.wallet.deposit(2*bet)
|
|
89
|
+
self.wins+=1
|
|
90
|
+
print(f"Natural {sum1}! You won ${2*bet}!")
|
|
91
|
+
return
|
|
92
|
+
elif sum1 in (2, 3, 12):
|
|
93
|
+
self.losses+=1
|
|
94
|
+
print(f"Craps ({sum1})! You lost ${bet}!")
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
point = sum1
|
|
98
|
+
print(f"Your point is now: {point}. Try to hit {point} before rolling a 7!")
|
|
99
|
+
|
|
100
|
+
#second round, multipliers based on how hard it is to get your number
|
|
101
|
+
if sum1 in (4,10):
|
|
102
|
+
multiplier = 3
|
|
103
|
+
elif sum1 in (5,9):
|
|
104
|
+
multiplier = 2.5
|
|
105
|
+
else:
|
|
106
|
+
multiplier = 2.2
|
|
107
|
+
|
|
108
|
+
print(f"Want to place an extra bet on {point}?")
|
|
109
|
+
print(f"If you win, your extra bet pay out {multiplier}x and added on top of your original payout!")
|
|
110
|
+
decision = input("[Y/N]: ")
|
|
111
|
+
decision = decision.strip().lower()
|
|
112
|
+
|
|
113
|
+
while decision not in ["y", "n"]:
|
|
114
|
+
decision = input("Please enter 'y' or 'n' to make your decision: ")
|
|
115
|
+
decision = decision.strip().lower()
|
|
116
|
+
|
|
117
|
+
if decision == "y":
|
|
118
|
+
if self.wallet.balance == 0:
|
|
119
|
+
print ("You have no money to add!")
|
|
120
|
+
extra = False
|
|
121
|
+
else:
|
|
122
|
+
extra = True
|
|
123
|
+
extra_bet = self.place_bet()
|
|
124
|
+
else:
|
|
125
|
+
extra = False
|
|
126
|
+
|
|
127
|
+
while True:
|
|
128
|
+
input("Press Enter to roll again!")
|
|
129
|
+
dice1, dice2, sum2 = self.roll_dice()
|
|
130
|
+
|
|
131
|
+
if sum2 == point:
|
|
132
|
+
self.wins+=1
|
|
133
|
+
if extra == True:
|
|
134
|
+
payout = round(2*bet+multiplier*extra_bet)
|
|
135
|
+
self.wallet.deposit(payout)
|
|
136
|
+
print(f"You rolled {dice1} and {dice2} ({sum2}) , Since you bet extra and you hit your number! You won ${payout}!")
|
|
137
|
+
else:
|
|
138
|
+
self.wallet.deposit(2*bet)
|
|
139
|
+
print(f"You rolled {dice1} and {dice2} ({sum2}) , You hit your number! You won ${2*bet}!")
|
|
140
|
+
return
|
|
141
|
+
|
|
142
|
+
if sum2 == 7:
|
|
143
|
+
self.losses+=1
|
|
144
|
+
if extra == True:
|
|
145
|
+
print(f"You rolled {dice1} and {dice2} (7) , You sevened out unfortunately. You lost ${bet+extra_bet}!")
|
|
146
|
+
else:
|
|
147
|
+
print(f"You rolled {dice1} and {dice2} (7) , You sevened out unfortunately. You lost ${bet}!")
|
|
148
|
+
return
|
|
149
|
+
|
|
150
|
+
print(f"You rolled {sum2} ({dice1} and {dice2}), not {point} or 7. Rerolling...")
|
|
151
|
+
|
|
152
|
+
def show_stats(self):
|
|
153
|
+
total = self.wins + self.losses
|
|
154
|
+
win_rate = (self.wins / total * 100) if total else 0
|
|
155
|
+
print("\n--- CRAPS STATS ---")
|
|
156
|
+
print(f"Wins: {self.wins}")
|
|
157
|
+
print(f"Losses: {self.losses}")
|
|
158
|
+
print(f"Win rate: {win_rate:.1f}%")
|
|
159
|
+
print(f"Balance: ${self.wallet.balance}")
|
|
160
|
+
input("Press Enter to exit: ")
|
|
161
|
+
|
|
162
|
+
def play(self):
|
|
163
|
+
while self.wallet.balance > 0:
|
|
164
|
+
print("\n--- CRAPS ---")
|
|
165
|
+
print("1. Play")
|
|
166
|
+
print("2. Stats")
|
|
167
|
+
print("3. Quit")
|
|
168
|
+
choice = input("Select an option: ")
|
|
169
|
+
|
|
170
|
+
if choice == "1":
|
|
171
|
+
self.play_round()
|
|
172
|
+
elif choice == "2":
|
|
173
|
+
self.show_stats()
|
|
174
|
+
elif choice == "3":
|
|
175
|
+
break
|
|
176
|
+
else:
|
|
177
|
+
print("Invalid option.")
|
|
178
|
+
|
|
179
|
+
print("Thanks for playing!")
|
|
180
|
+
|
|
181
|
+
if __name__ == "__main__":
|
|
182
|
+
game = Craps()
|
|
183
|
+
game.play()
|