forked from rDrama/rDrama
master
parent
f122f289b9
commit
394f8d0381
|
@ -12,8 +12,13 @@ def shuffle(x):
|
||||||
random.shuffle(x)
|
random.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 = 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
|
p1, d1, p2, d2, *rest_of_deck = deck
|
||||||
return [p1, p2], [d1, d2], rest_of_deck
|
return [p1, p2], [d1, d2], rest_of_deck
|
||||||
|
|
||||||
|
@ -80,50 +85,20 @@ 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(from_comment, wager, status, 1)
|
self.apply_game_result(from_comment, wager, status)
|
||||||
elif player_value == 21:
|
elif player_value == 21:
|
||||||
status = 'blackjack'
|
status = 'blackjack'
|
||||||
self.apply_game_result(from_comment, wager, status, 1)
|
self.apply_game_result(from_comment, wager, status)
|
||||||
elif dealer_value == 21:
|
elif dealer_value == 21:
|
||||||
status = 'lost'
|
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:
|
def player_hit(self, from_comment):
|
||||||
for word in in_text.split():
|
player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.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("_")
|
|
||||||
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("/")
|
||||||
|
@ -131,16 +106,18 @@ class Blackjack:
|
||||||
player_value = get_hand_value(player_hand)
|
player_value = get_hand_value(player_hand)
|
||||||
|
|
||||||
if player_value == -1:
|
if player_value == -1:
|
||||||
if currency == 1: status = 'bust'
|
status = 'bust'
|
||||||
else: status = 'mbbust'
|
self.apply_game_result(from_comment, wager, status)
|
||||||
self.apply_game_result(from_comment, wager, status, currency)
|
|
||||||
|
|
||||||
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):
|
def player_stayed(self, from_comment):
|
||||||
player_hand, dealer_hand, deck, status, wager = from_comment.blackjack_result.split("_")
|
player_hand, dealer_hand, deck, status, wager = 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("/")
|
||||||
|
@ -152,28 +129,29 @@ 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:
|
||||||
if currency == 1: status = 'won'
|
status = 'won'
|
||||||
else: status = 'mbwon'
|
|
||||||
elif dealer_value > player_value:
|
elif dealer_value > player_value:
|
||||||
if currency == 1: status = 'lost'
|
status = 'lost'
|
||||||
else: status = 'mblost'
|
else:
|
||||||
else: status += 'push'
|
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
|
reward = 0
|
||||||
|
|
||||||
if result.endswith('push'): reward = int(wager)
|
if result == 'push':
|
||||||
elif result.endswith('won'): reward = int(wager) * 2
|
reward = int(wager)
|
||||||
elif result.endswith('blackjack'): reward = floor(int(wager) * (5/2))
|
elif result == 'won':
|
||||||
|
reward = int(wager) * 2
|
||||||
|
elif result == 'blackjack':
|
||||||
|
reward = floor(int(wager) * (5/2))
|
||||||
|
|
||||||
if (reward > 0):
|
if (reward > 0):
|
||||||
user = from_comment.author
|
user = from_comment.author
|
||||||
if currency == 1: user.coins += reward
|
user.coins += reward
|
||||||
else: user.procoins += reward
|
|
||||||
user.winnings += reward
|
user.winnings += reward
|
|
@ -963,14 +963,10 @@ def handle_blackjack_action(cid, v):
|
||||||
action = request.values.get("action", "")
|
action = request.values.get("action", "")
|
||||||
blackjack = Blackjack(g)
|
blackjack = Blackjack(g)
|
||||||
|
|
||||||
blackjack_status = comment.blackjack_result.split('_')[3]
|
if action == 'hit':
|
||||||
if blackjack_status == 'mbactive': currency = 2
|
blackjack.player_hit(comment)
|
||||||
elif blackjack_status == 'active': currency = 1
|
elif action == 'stay':
|
||||||
else: abort(400)
|
blackjack.player_stayed(comment)
|
||||||
|
|
||||||
if action == 'hit': blackjack.player_hit(comment, currency)
|
|
||||||
elif action == 'stay': blackjack.player_stayed(comment, currency)
|
|
||||||
else: abort(400)
|
|
||||||
|
|
||||||
g.db.add(comment)
|
g.db.add(comment)
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
|
|
@ -182,7 +182,7 @@
|
||||||
{% set split_result = c.blackjack_result.split('_') %}
|
{% set split_result = c.blackjack_result.split('_') %}
|
||||||
{% set blackjack_status = split_result[3] %}
|
{% set blackjack_status = split_result[3] %}
|
||||||
{% set player_hand = split_result[0].replace('X', '10') %}
|
{% 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 dealer_hand = dealer_hand.replace('X', '10') %}
|
||||||
{% set wager = split_result[4] %}
|
{% set wager = split_result[4] %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -259,25 +259,20 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if c.blackjack_result %}
|
{% if c.blackjack_result %}
|
||||||
<em>{{player_hand}} vs. {{dealer_hand}}</em>
|
<em>{{player_hand}} vs. {{dealer_hand}}</em>
|
||||||
{% if blackjack_status.startswith('mb') %}
|
{% if blackjack_status == 'active' and v.id == c.author_id %}
|
||||||
{% set currency = 'Marseybux' %}
|
<button class="btn btn-success small" style="text-transform: uppercase; padding: 2px;" onclick="handle_blackjack_action('{{c.id}}', 'hit')">Hit</button>
|
||||||
{% else %}
|
<button class="btn btn-danger small" style="text-transform: uppercase; padding: 2px;" onclick="handle_blackjack_action('{{c.id}}', 'stay')">Stay</button>
|
||||||
{% set currency = 'Coins' %}
|
|
||||||
{% endif %}
|
|
||||||
{% if 'active' in blackjack_status 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' %}
|
{% elif blackjack_status == 'push' %}
|
||||||
<strong>Pushed.</strong>
|
<strong>Pushed.</strong>
|
||||||
{% elif blackjack_status.endswith('bust') %}
|
{% elif blackjack_status == 'bust' %}
|
||||||
<strong>Bust. Lost {{wager}} {{currency}}.</strong>
|
<strong>Bust. Lost {{wager}} Coins.</strong>
|
||||||
{% elif blackjack_status.endswith('lost') %}
|
{% elif blackjack_status == 'lost' %}
|
||||||
<strong>Lost {{wager}} {{currency}}.</strong>
|
<strong>Lost {{wager}} Coins.</strong>
|
||||||
{% elif blackjack_status.endswith('won') %}
|
{% elif blackjack_status == 'won' %}
|
||||||
<strong>Won {{wager}} {{currency}}.</strong>
|
<strong>Won {{wager}} Coins.</strong>
|
||||||
{% elif blackjack_status.endswith('blackjack') %}
|
{% elif blackjack_status == 'blackjack' %}
|
||||||
<strong>Blackjack! Won <span id="blackjack-result-{{c.id}}">{{(wager|int * 3/2)|round(0, 'floor')|int}}</span> {{currency}}.</strong>
|
<strong>Blackjack! Won <span id="blackjack-result-{{c.id}}">{{(wager|int * 3/2)|round(0, 'floor')|int}}</span> Coins.</strong>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue