diff --git a/files/classes/blackjack.py b/files/classes/blackjack.py
index 9774e3e3b..ffa8d6b58 100644
--- a/files/classes/blackjack.py
+++ b/files/classes/blackjack.py
@@ -12,8 +12,13 @@ def shuffle(x):
random.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 = shuffle([rank + suit for rank in ranks for suit in suits for _ in range(deck_count)])
+ deck = get_shuffled_deck()
p1, d1, p2, d2, *rest_of_deck = deck
return [p1, p2], [d1, d2], rest_of_deck
@@ -80,50 +85,20 @@ class Blackjack:
if player_value == 21 and dealer_value == 21:
status = 'push'
- self.apply_game_result(from_comment, wager, status, 1)
+ self.apply_game_result(from_comment, wager, status)
elif player_value == 21:
status = 'blackjack'
- self.apply_game_result(from_comment, wager, status, 1)
+ self.apply_game_result(from_comment, wager, status)
elif dealer_value == 21:
status = 'lost'
- self.apply_game_result(from_comment, wager, status, 1)
+ self.apply_game_result(from_comment, wager, status)
- from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager)
+ from_comment.blackjack_result = format_all(
+ player_hand, dealer_hand, rest_of_deck, status, wager)
- if self.casino_word in in_text:
- for word in in_text.split():
- if self.casino_word in word:
- try:
- wager = word[len(self.casino_word):]
- wager_value = int(wager)
- except: break
-
- if (wager_value < self.minimum_bet): break
- elif (wager_value > self.maximum_bet): break
- elif (wager_value > from_user.procoins): break
-
- from_user.procoins -= wager_value
- from_user.winnings -= wager_value
-
- player_hand, dealer_hand, rest_of_deck = deal_initial_cards()
- status = 'mbactive'
- player_value = get_hand_value(player_hand)
- dealer_value = get_hand_value(dealer_hand)
-
- if player_value == 21 and dealer_value == 21:
- status = 'push'
- self.apply_game_result(from_comment, wager, status, 2)
- elif player_value == 21:
- status = 'mbblackjack'
- self.apply_game_result(from_comment, wager, status, 2)
- elif dealer_value == 21:
- status = 'mblost'
- self.apply_game_result(from_comment, wager, status, 2)
-
- from_comment.blackjack_result = format_all(player_hand, dealer_hand, rest_of_deck, status, wager)
-
- def player_hit(self, from_comment, currency):
- player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split("_")
+ def player_hit(self, from_comment):
+ player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split(
+ "_")
player_hand = player_hand.split("/")
dealer_hand = dealer_hand.split("/")
deck = deck.split("/")
@@ -131,16 +106,18 @@ class Blackjack:
player_value = get_hand_value(player_hand)
if player_value == -1:
- if currency == 1: status = 'bust'
- else: status = 'mbbust'
- self.apply_game_result(from_comment, wager, status, currency)
+ status = 'bust'
+ self.apply_game_result(from_comment, wager, status)
- from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager)
+ from_comment.blackjack_result = format_all(
+ player_hand, dealer_hand, deck, status, wager)
- if (player_value == 21): self.player_stayed(from_comment, currency)
+ if (player_value == 21):
+ self.player_stayed(from_comment)
- def player_stayed(self, from_comment, currency):
- player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split("_")
+ def player_stayed(self, from_comment):
+ player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split(
+ "_")
player_hand = player_hand.split("/")
player_value = get_hand_value(player_hand)
dealer_hand = dealer_hand.split("/")
@@ -152,28 +129,29 @@ class Blackjack:
dealer_hand.append(next)
dealer_value = get_hand_value(dealer_hand)
-
if player_value > dealer_value or dealer_value == -1:
- if currency == 1: status = 'won'
- else: status = 'mbwon'
+ status = 'won'
elif dealer_value > player_value:
- if currency == 1: status = 'lost'
- else: status = 'mblost'
- else: status += 'push'
+ status = 'lost'
+ else:
+ status = 'push'
- from_comment.blackjack_result = format_all(player_hand, dealer_hand, deck, status, wager)
+ from_comment.blackjack_result = format_all(
+ player_hand, dealer_hand, deck, status, wager)
- self.apply_game_result(from_comment, wager, status, currency)
+ self.apply_game_result(from_comment, wager, status)
- def apply_game_result(self, from_comment, wager, result, currency):
+ def apply_game_result(self, from_comment, wager, result):
reward = 0
- if result.endswith('push'): reward = int(wager)
- elif result.endswith('won'): reward = int(wager) * 2
- elif result.endswith('blackjack'): reward = floor(int(wager) * (5/2))
+ if result == 'push':
+ reward = int(wager)
+ elif result == 'won':
+ reward = int(wager) * 2
+ elif result == 'blackjack':
+ reward = floor(int(wager) * (5/2))
if (reward > 0):
user = from_comment.author
- if currency == 1: user.coins += reward
- else: user.procoins += reward
+ user.coins += reward
user.winnings += reward
\ No newline at end of file
diff --git a/files/routes/comments.py b/files/routes/comments.py
index 5bb91b46d..47268260c 100644
--- a/files/routes/comments.py
+++ b/files/routes/comments.py
@@ -963,14 +963,10 @@ def handle_blackjack_action(cid, v):
action = request.values.get("action", "")
blackjack = Blackjack(g)
- blackjack_status = comment.blackjack_result.split('_')[3]
- if blackjack_status == 'mbactive': currency = 2
- elif blackjack_status == 'active': currency = 1
- else: abort(400)
-
- if action == 'hit': blackjack.player_hit(comment, currency)
- elif action == 'stay': blackjack.player_stayed(comment, currency)
- else: abort(400)
+ if action == 'hit':
+ blackjack.player_hit(comment)
+ elif action == 'stay':
+ blackjack.player_stayed(comment)
g.db.add(comment)
g.db.add(v)
diff --git a/files/templates/comments.html b/files/templates/comments.html
index 4a6767808..c0b9e27dc 100644
--- a/files/templates/comments.html
+++ b/files/templates/comments.html
@@ -182,7 +182,7 @@
{% set split_result = c.blackjack_result.split('_') %}
{% set blackjack_status = split_result[3] %}
{% set player_hand = split_result[0].replace('X', '10') %}
- {% set dealer_hand = split_result[1].split('/')[0] if blackjack_status.endswith('active') else split_result[1] %}
+ {% set dealer_hand = split_result[1].split('/')[0] if blackjack_status == 'active' else split_result[1] %}
{% set dealer_hand = dealer_hand.replace('X', '10') %}
{% set wager = split_result[4] %}
{% endif %}
@@ -259,25 +259,20 @@
{% endif %}
{% if c.blackjack_result %}
- {{player_hand}} vs. {{dealer_hand}}
- {% if blackjack_status.startswith('mb') %}
- {% set currency = 'Marseybux' %}
- {% else %}
- {% set currency = 'Coins' %}
- {% endif %}
- {% if 'active' in blackjack_status and v.id == c.author_id %}
-
-
+ {{player_hand}} vs. {{dealer_hand}}
+ {% if blackjack_status == 'active' and v.id == c.author_id %}
+
+
{% elif blackjack_status == 'push' %}
- Pushed.
- {% elif blackjack_status.endswith('bust') %}
- Bust. Lost {{wager}} {{currency}}.
- {% elif blackjack_status.endswith('lost') %}
- Lost {{wager}} {{currency}}.
- {% elif blackjack_status.endswith('won') %}
- Won {{wager}} {{currency}}.
- {% elif blackjack_status.endswith('blackjack') %}
- Blackjack! Won {{(wager|int * 3/2)|round(0, 'floor')|int}} {{currency}}.
+ Pushed.
+ {% elif blackjack_status == 'bust' %}
+ Bust. Lost {{wager}} Coins.
+ {% elif blackjack_status == 'lost' %}
+ Lost {{wager}} Coins.
+ {% elif blackjack_status == 'won' %}
+ Won {{wager}} Coins.
+ {% elif blackjack_status == 'blackjack' %}
+ Blackjack! Won {{(wager|int * 3/2)|round(0, 'floor')|int}} Coins.
{% endif %}
{% endif %}