forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2022-02-07 15:58:49 +02:00
parent 123a993779
commit 80b3b6b6a8
1 changed files with 95 additions and 120 deletions

View File

@ -13,12 +13,8 @@ def shuffle(x):
return x return x
def get_shuffled_deck():
return shuffle([rank + suit for rank in ranks for suit in suits for _ in range(deck_count)])
def deal_initial_cards(): def deal_initial_cards():
deck = get_shuffled_deck() deck = shuffle([rank + suit for rank in ranks for suit in suits for _ in range(deck_count)])
p1, d1, p2, d2, *rest_of_deck = deck p1, d1, p2, d2, *rest_of_deck = deck
return [p1, p2], [d1, d2], rest_of_deck return [p1, p2], [d1, d2], rest_of_deck
@ -73,19 +69,13 @@ class Blackjack:
try: try:
wager = word[len(command_word):] wager = word[len(command_word):]
wager_value = int(wager) wager_value = int(wager)
except: except: break
break
if (wager_value < self.minimum_bet): if (wager_value < self.minimum_bet): break
break elif (wager_value > self.maximum_bet): break
elif (wager_value > self.maximum_bet):
break
elif (wager_value <= currency_value): elif (wager_value <= currency_value):
setattr(from_user, currency_prop,
currency_value - wager_value)
if currency_prop == "coins": setattr(from_user, currency_prop, currency_value - wager_value)
from_user.winnings -= wager_value
player_hand, dealer_hand, rest_of_deck = deal_initial_cards() player_hand, dealer_hand, rest_of_deck = deal_initial_cards()
status = 'active' status = 'active'
@ -94,23 +84,18 @@ class Blackjack:
if player_value == 21 and dealer_value == 21: if player_value == 21 and dealer_value == 21:
status = 'push' status = 'push'
self.apply_game_result( self.apply_game_result(from_comment, wager, status, currency_prop)
from_comment, wager, status, currency_prop)
elif player_value == 21: elif player_value == 21:
status = 'blackjack' status = 'blackjack'
self.apply_game_result( self.apply_game_result(from_comment, wager, status, currency_prop)
from_comment, wager, status, currency_prop)
elif dealer_value == 21: elif dealer_value == 21:
status = 'lost' status = 'lost'
self.apply_game_result( self.apply_game_result(from_comment, wager, status, currency_prop)
from_comment, wager, status, currency_prop)
from_comment.blackjack_result = format_all( from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager, currency_prop)
player_hand, dealer_hand, rest_of_deck, status, wager, currency_prop)
def player_hit(self, from_comment): def player_hit(self, from_comment):
player_hand, dealer_hand, deck, status, wager, kind = from_comment.blackjack_result.split( player_hand, dealer_hand, deck, status, wager, kind = from_comment.blackjack_result.split("_")
"_")
player_hand = player_hand.split("/") player_hand = player_hand.split("/")
dealer_hand = dealer_hand.split("/") dealer_hand = dealer_hand.split("/")
deck = deck.split("/") deck = deck.split("/")
@ -121,15 +106,12 @@ class Blackjack:
status = 'bust' status = 'bust'
self.apply_game_result(from_comment, wager, status, kind) self.apply_game_result(from_comment, wager, status, kind)
from_comment.blackjack_result = format_all( from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager, kind)
player_hand, dealer_hand, deck, status, wager, kind)
if (player_value == 21): if (player_value == 21): self.player_stayed(from_comment)
self.player_stayed(from_comment)
def player_stayed(self, from_comment): def player_stayed(self, from_comment):
player_hand, dealer_hand, deck, status, wager, kind = from_comment.blackjack_result.split( player_hand, dealer_hand, deck, status, wager, kind = from_comment.blackjack_result.split("_")
"_")
player_hand = player_hand.split("/") player_hand = player_hand.split("/")
player_value = get_hand_value(player_hand) player_value = get_hand_value(player_hand)
dealer_hand = dealer_hand.split("/") dealer_hand = dealer_hand.split("/")
@ -141,15 +123,11 @@ class Blackjack:
dealer_hand.append(next) dealer_hand.append(next)
dealer_value = get_hand_value(dealer_hand) dealer_value = get_hand_value(dealer_hand)
if player_value > dealer_value or dealer_value == -1: if player_value > dealer_value or dealer_value == -1: status = 'won'
status = 'won' elif dealer_value > player_value: status = 'lost'
elif dealer_value > player_value: else: status = 'push'
status = 'lost'
else:
status = 'push'
from_comment.blackjack_result = format_all( from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager, kind)
player_hand, dealer_hand, deck, status, wager, kind)
self.apply_game_result(from_comment, wager, status, kind) self.apply_game_result(from_comment, wager, status, kind)
@ -158,12 +136,9 @@ class Blackjack:
user = from_comment.author user = from_comment.author
reward = -1 reward = -1
if result == 'push': if result == 'push': reward = 0
reward = 0 elif result == 'won': reward = wager_value
elif result == 'won': elif result == 'blackjack': reward = floor(wager_value * 3/2)
reward = wager_value
elif result == 'blackjack':
reward = floor(wager_value * 3/2)
if (reward > -1): if (reward > -1):
currency_value = int(getattr(user, kind, 0)) currency_value = int(getattr(user, kind, 0))