🐛 Splitting

This commit is contained in:
Nikolaj Danger
2020-08-04 15:08:36 +02:00
parent 1c2b800d9c
commit 9db8ba3dcd
4 changed files with 256 additions and 263 deletions

View File

@ -132,61 +132,12 @@ def blackjackContinue(channel):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
logThis("Testing if all are standing")
for user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["hit"] == False:
data["blackjack games"][channel]["user hands"][user]["standing"] = True
if data["blackjack games"][channel]["user hands"][user]["standing"] == False:
allStanding = False
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["doubled"]:
data["blackjack games"][channel]["user hands"][user]["standing"] = True
else:
preAllStanding = False
data["blackjack games"][channel]["user hands"][user]["hit"] = False
if data["blackjack games"][channel]["user hands"][user]["split"] > 0:
if data["blackjack games"][channel]["user hands"][user]["other hand"]["hit"] == False:
data["blackjack games"][channel]["user hands"][user]["other hand"]["standing"] = True
if data["blackjack games"][channel]["user hands"][user]["other hand"]["standing"] == False:
allStanding = False
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["other hand"]["doubled"]:
data["blackjack games"][channel]["user hands"][user]["other hand"]["standing"] = True
else:
preAllStanding = False
data["blackjack games"][channel]["user hands"][user]["other hand"]["hit"] = False
if data["blackjack games"][channel]["user hands"][user]["split"] > 1:
if data["blackjack games"][channel]["user hands"][user]["third hand"]["hit"] == False:
data["blackjack games"][channel]["user hands"][user]["third hand"]["standing"] = True
if data["blackjack games"][channel]["user hands"][user]["third hand"]["standing"] == False:
allStanding = False
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["third hand"]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["third hand"]["doubled"]:
data["blackjack games"][channel]["user hands"][user]["third hand"]["standing"] = True
else:
preAllStanding = False
data["blackjack games"][channel]["user hands"][user]["third hand"]["hit"] = False
if data["blackjack games"][channel]["user hands"][user]["split"] > 2:
if data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hit"] == False:
data["blackjack games"][channel]["user hands"][user]["fourth hand"]["standing"] = True
if data["blackjack games"][channel]["user hands"][user]["fourth hand"]["standing"] == False:
allStanding = False
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["fourth hand"]["doubled"]:
data["blackjack games"][channel]["user hands"][user]["fourth hand"]["standing"] = True
else:
preAllStanding = False
data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hit"] = False
try:
data["blackjack games"][channel]["user hands"][user], allStanding, preAllStanding = testIfStanding(data["blackjack games"][channel]["user hands"][user],allStanding,preAllStanding,True)
except:
logThis("Error in testing if all are standing (error code 1331)")
if allStanding:
data["blackjack games"][channel]["all standing"] = True
@ -196,7 +147,10 @@ def blackjackContinue(channel):
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
blackjackDraw.drawImage(channel)
try:
blackjackDraw.drawImage(channel)
except:
logThis("Error drawing blackjack table (error code 1340)")
if allStanding:
if done == False:
@ -212,6 +166,31 @@ def blackjackContinue(channel):
firstRoundMessage = ""
return "You have 2 minutes 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
def testIfStanding(hand,allStanding,preAllStanding,topLevel):
if hand["hit"] == False:
hand["standing"] = True
if hand["standing"] == False:
allStanding = False
if calcHandValue(hand["hand"]) >= 21 or hand["doubled"]:
hand["standing"] = True
else:
preAllStanding = False
hand["hit"] = False
if topLevel:
if hand["split"] >= 1:
hand["other hand"], allstanding, preAllStanding = testIfStanding(hand["other hand"],allStanding,preAllStanding,False)
if hand["split"] >= 2:
hand["third hand"], allstanding, preAllStanding = testIfStanding(hand["third hand"],allStanding,preAllStanding,False)
if hand["split"] >= 3:
hand["fourth hand"], allstanding, preAllStanding = testIfStanding(hand["fourth hand"],allStanding,preAllStanding,False)
return hand, allStanding, preAllStanding
# When players try to hit
def blackjackHit(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
@ -311,7 +290,7 @@ def blackjackDouble(channel,user,handNumber = 0):
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 3:
elif handNumber == 4:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
else:
logThis(user+" tried to double without specifying which hand")