forked from MarseyWorld/MarseyWorld
xcv
parent
123a993779
commit
80b3b6b6a8
|
@ -13,12 +13,8 @@ def shuffle(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():
|
||||
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
|
||||
return [p1, p2], [d1, d2], rest_of_deck
|
||||
|
||||
|
@ -73,19 +69,13 @@ class Blackjack:
|
|||
try:
|
||||
wager = word[len(command_word):]
|
||||
wager_value = int(wager)
|
||||
except:
|
||||
break
|
||||
except: break
|
||||
|
||||
if (wager_value < self.minimum_bet):
|
||||
break
|
||||
elif (wager_value > self.maximum_bet):
|
||||
break
|
||||
if (wager_value < self.minimum_bet): break
|
||||
elif (wager_value > self.maximum_bet): break
|
||||
elif (wager_value <= currency_value):
|
||||
setattr(from_user, currency_prop,
|
||||
currency_value - wager_value)
|
||||
|
||||
if currency_prop == "coins":
|
||||
from_user.winnings -= wager_value
|
||||
setattr(from_user, currency_prop, currency_value - wager_value)
|
||||
|
||||
player_hand, dealer_hand, rest_of_deck = deal_initial_cards()
|
||||
status = 'active'
|
||||
|
@ -94,23 +84,18 @@ class Blackjack:
|
|||
|
||||
if player_value == 21 and dealer_value == 21:
|
||||
status = 'push'
|
||||
self.apply_game_result(
|
||||
from_comment, wager, status, currency_prop)
|
||||
self.apply_game_result(from_comment, wager, status, currency_prop)
|
||||
elif player_value == 21:
|
||||
status = 'blackjack'
|
||||
self.apply_game_result(
|
||||
from_comment, wager, status, currency_prop)
|
||||
self.apply_game_result(from_comment, wager, status, currency_prop)
|
||||
elif dealer_value == 21:
|
||||
status = 'lost'
|
||||
self.apply_game_result(
|
||||
from_comment, wager, status, currency_prop)
|
||||
self.apply_game_result(from_comment, wager, status, currency_prop)
|
||||
|
||||
from_comment.blackjack_result = format_all(
|
||||
player_hand, dealer_hand, rest_of_deck, status, wager, currency_prop)
|
||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager, currency_prop)
|
||||
|
||||
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("/")
|
||||
dealer_hand = dealer_hand.split("/")
|
||||
deck = deck.split("/")
|
||||
|
@ -121,15 +106,12 @@ class Blackjack:
|
|||
status = 'bust'
|
||||
self.apply_game_result(from_comment, wager, status, kind)
|
||||
|
||||
from_comment.blackjack_result = format_all(
|
||||
player_hand, dealer_hand, deck, status, wager, kind)
|
||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager, kind)
|
||||
|
||||
if (player_value == 21):
|
||||
self.player_stayed(from_comment)
|
||||
if (player_value == 21): self.player_stayed(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_value = get_hand_value(player_hand)
|
||||
dealer_hand = dealer_hand.split("/")
|
||||
|
@ -141,15 +123,11 @@ class Blackjack:
|
|||
dealer_hand.append(next)
|
||||
dealer_value = get_hand_value(dealer_hand)
|
||||
|
||||
if player_value > dealer_value or dealer_value == -1:
|
||||
status = 'won'
|
||||
elif dealer_value > player_value:
|
||||
status = 'lost'
|
||||
else:
|
||||
status = 'push'
|
||||
if player_value > dealer_value or dealer_value == -1: status = 'won'
|
||||
elif dealer_value > player_value: status = 'lost'
|
||||
else: status = 'push'
|
||||
|
||||
from_comment.blackjack_result = format_all(
|
||||
player_hand, dealer_hand, deck, status, wager, kind)
|
||||
from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager, kind)
|
||||
|
||||
self.apply_game_result(from_comment, wager, status, kind)
|
||||
|
||||
|
@ -158,12 +136,9 @@ class Blackjack:
|
|||
user = from_comment.author
|
||||
reward = -1
|
||||
|
||||
if result == 'push':
|
||||
reward = 0
|
||||
elif result == 'won':
|
||||
reward = wager_value
|
||||
elif result == 'blackjack':
|
||||
reward = floor(wager_value * 3/2)
|
||||
if result == 'push': reward = 0
|
||||
elif result == 'won': reward = wager_value
|
||||
elif result == 'blackjack': reward = floor(wager_value * 3/2)
|
||||
|
||||
if (reward > -1):
|
||||
currency_value = int(getattr(user, kind, 0))
|
||||
|
|
Loading…
Reference in New Issue