📝 Commenting and formatting
This commit is contained in:
@ -7,15 +7,14 @@ from shutil import copyfile
|
||||
from funcs import logThis, replaceMultiple
|
||||
from . import money, blackjackDraw
|
||||
|
||||
deckAmount = 4
|
||||
|
||||
def shuffle():
|
||||
# Shuffles the blackjack cards
|
||||
def blackjackShuffle(decks):
|
||||
logThis("Shuffling the blackjack deck")
|
||||
|
||||
with open("resources/games/deckofCards.txt","r") as f:
|
||||
deck = f.read()
|
||||
|
||||
allDecks = deck.split("\n") * 4
|
||||
allDecks = deck.split("\n") * decks
|
||||
random.shuffle(allDecks)
|
||||
data = "\n".join(allDecks)
|
||||
|
||||
@ -24,6 +23,7 @@ def shuffle():
|
||||
|
||||
return
|
||||
|
||||
# Calculates the value of a blackjack hand
|
||||
def calcHandValue(hand : list):
|
||||
logThis("Calculating hand value")
|
||||
values = [0]
|
||||
@ -51,13 +51,13 @@ def calcHandValue(hand : list):
|
||||
|
||||
return handValue
|
||||
|
||||
# Draws a card from the deck
|
||||
def drawCard():
|
||||
logThis("drawing a card")
|
||||
with open("resources/games/blackjackCards.txt","r") as f:
|
||||
cards = f.read().split("\n")
|
||||
|
||||
drawnCard = cards[0]
|
||||
cards = cards[1:]
|
||||
drawnCard = cards.pop(0)
|
||||
data = "\n".join(cards)
|
||||
|
||||
with open("resources/games/blackjackCards.txt","w") as f:
|
||||
@ -65,6 +65,7 @@ def drawCard():
|
||||
|
||||
return drawnCard
|
||||
|
||||
# Dealer draws a card and checks if they should draw another one
|
||||
def dealerDraw(channel):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
@ -85,6 +86,7 @@ def dealerDraw(channel):
|
||||
|
||||
return done
|
||||
|
||||
# Goes to the next round and calculates some stuff
|
||||
def blackjackContinue(channel):
|
||||
logThis("Continuing blackjack game")
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
@ -163,6 +165,7 @@ def blackjackContinue(channel):
|
||||
firstRoundMessage = ""
|
||||
return "You have 30 seconds to either hit or stand with \"!blackjack hit\" or \"!blackjack stand\""+firstRoundMessage+". It's assumed you're standing if you don't make a choice.", False, done
|
||||
|
||||
# When players try to hit
|
||||
def blackjackHit(channel,user,handNumber = 0):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
@ -216,6 +219,7 @@ def blackjackHit(channel,user,handNumber = 0):
|
||||
return "You can't hit before you see your cards"
|
||||
|
||||
|
||||
# When players try to double down
|
||||
def blackjackDouble(channel,user,handNumber = 0):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
@ -287,6 +291,7 @@ def blackjackDouble(channel,user,handNumber = 0):
|
||||
logThis(user+" tried to double on the 0th round")
|
||||
return "You can't double down before you see your cards"
|
||||
|
||||
# When players try to stand
|
||||
def blackjackStand(channel,user,handNumber = 0):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
@ -310,6 +315,7 @@ def blackjackStand(channel,user,handNumber = 0):
|
||||
logThis(user+" tried to stand on the first round")
|
||||
return "You can't stand before you see your cards"
|
||||
|
||||
# When players try to split
|
||||
def blackjackSplit(channel,user):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
@ -374,6 +380,7 @@ def blackjackSplit(channel,user):
|
||||
logThis(user+" tried to split on the 0th round")
|
||||
return "You can't split before you see your cards"
|
||||
|
||||
# Player enters the game and draws a hand
|
||||
def blackjackPlayerDrawHand(channel,user,bet):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
@ -431,6 +438,7 @@ def blackjackPlayerDrawHand(channel,user,bet):
|
||||
logThis("There is no game going on in "+channel)
|
||||
return "There is no game going on in this channel"
|
||||
|
||||
# Starts a game of blackjack
|
||||
def blackjackStart(channel:str):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
@ -456,6 +464,7 @@ def blackjackStart(channel:str):
|
||||
logThis("There is already a blackjack game going on in "+channel)
|
||||
return "There's already a blackjack game going on. Try again in a few minutes."
|
||||
|
||||
# Ends the game and calculates winnings
|
||||
def blackjackFinish(channel):
|
||||
finalWinnings = "*Final Winnings:*\n"
|
||||
|
||||
@ -480,6 +489,7 @@ def blackjackFinish(channel):
|
||||
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["bet"]
|
||||
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) > dealerValue:
|
||||
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["bet"]
|
||||
reason = "(highest value)"
|
||||
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) == dealerValue:
|
||||
reason = "(pushed)"
|
||||
winnings += data["blackjack games"][channel]["user hands"][user]["bet"]
|
||||
|
Reference in New Issue
Block a user