forked from MarseyWorld/MarseyWorld
master
parent
f122f289b9
commit
394f8d0381
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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 %}
|
||||
|
@ -260,24 +260,19 @@
|
|||
|
||||
{% if c.blackjack_result %}
|
||||
<em>{{player_hand}} vs. {{dealer_hand}}</em>
|
||||
{% if blackjack_status.startswith('mb') %}
|
||||
{% set currency = 'Marseybux' %}
|
||||
{% else %}
|
||||
{% set currency = 'Coins' %}
|
||||
{% endif %}
|
||||
{% if 'active' in blackjack_status and v.id == c.author_id %}
|
||||
{% if blackjack_status == 'active' and v.id == c.author_id %}
|
||||
<button class="btn btn-success small" style="text-transform: uppercase; padding: 2px;" onclick="handle_blackjack_action('{{c.id}}', 'hit')">Hit</button>
|
||||
<button class="btn btn-danger small" style="text-transform: uppercase; padding: 2px;" onclick="handle_blackjack_action('{{c.id}}', 'stay')">Stay</button>
|
||||
{% elif blackjack_status == 'push' %}
|
||||
<strong>Pushed.</strong>
|
||||
{% elif blackjack_status.endswith('bust') %}
|
||||
<strong>Bust. Lost {{wager}} {{currency}}.</strong>
|
||||
{% elif blackjack_status.endswith('lost') %}
|
||||
<strong>Lost {{wager}} {{currency}}.</strong>
|
||||
{% elif blackjack_status.endswith('won') %}
|
||||
<strong>Won {{wager}} {{currency}}.</strong>
|
||||
{% elif blackjack_status.endswith('blackjack') %}
|
||||
<strong>Blackjack! Won <span id="blackjack-result-{{c.id}}">{{(wager|int * 3/2)|round(0, 'floor')|int}}</span> {{currency}}.</strong>
|
||||
{% elif blackjack_status == 'bust' %}
|
||||
<strong>Bust. Lost {{wager}} Coins.</strong>
|
||||
{% elif blackjack_status == 'lost' %}
|
||||
<strong>Lost {{wager}} Coins.</strong>
|
||||
{% elif blackjack_status == 'won' %}
|
||||
<strong>Won {{wager}} Coins.</strong>
|
||||
{% elif blackjack_status == 'blackjack' %}
|
||||
<strong>Blackjack! Won <span id="blackjack-result-{{c.id}}">{{(wager|int * 3/2)|round(0, 'floor')|int}}</span> Coins.</strong>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue