🃏 Double splitting

This commit is contained in:
Nikolaj Danger
2020-08-03 13:39:11 +02:00
parent 90f82f54c5
commit 0a1b382e1a
3 changed files with 433 additions and 255 deletions

View File

@ -146,7 +146,7 @@ def blackjackContinue(channel):
data["blackjack games"][channel]["user hands"][user]["hit"] = False
if data["blackjack games"][channel]["user hands"][user]["split"]:
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
@ -160,6 +160,34 @@ def blackjackContinue(channel):
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
if allStanding:
data["blackjack games"][channel]["all standing"] = True
with open("resources/games/games.json", "w") as f:
@ -190,17 +218,19 @@ def blackjackHit(channel,user,handNumber = 0):
data = json.load(f)
if user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
otherHand = True
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 4:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
else:
logThis(user+" tried to hit without specifying which hand")
return "You have to specify the hand you're hitting with."
@ -219,8 +249,12 @@ def blackjackHit(channel,user,handNumber = 0):
if handValue > 21:
hand["busted"] = True
if otherHand:
if handNumber == 2:
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
elif handNumber == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = hand
elif handNumber == 4:
data["blackjack games"][channel]["user hands"][user]["fourth hand"] = hand
else:
data["blackjack games"][channel]["user hands"][user] = hand
@ -234,10 +268,18 @@ def blackjackHit(channel,user,handNumber = 0):
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"]:
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" is already standing")
@ -258,31 +300,31 @@ def blackjackDouble(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
correctRound = 1
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
otherHand = True
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
else:
logThis(user+" tried to double without specifying which hand")
return "You have to specify the hand you're doubling down.",""
else:
logThis(user+" tried to double without specifying which hand")
return "You have to specify the hand you're doubling down.",""
correctRound = 2
if data["blackjack games"][channel]["round"] > 0:
if hand["hit"] == False:
if hand["standing"] == False:
if data["blackjack games"][channel]["round"] == correctRound:
if len(hand["hand"]) == 2:
bet = hand["bet"]
if money.checkBalance(user) >= bet:
money.addMoney(user,-1 * bet)
@ -300,8 +342,12 @@ def blackjackDouble(channel,user,handNumber = 0):
if handValue > 21:
hand["busted"] = True
if otherHand:
if handNumber == 2:
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
elif handNumber == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = hand
elif handNumber == 4:
data["blackjack games"][channel]["user hands"][user]["fourth hand"] = hand
else:
data["blackjack games"][channel]["user hands"][user] = hand
@ -314,10 +360,18 @@ def blackjackDouble(channel,user,handNumber = 0):
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"]:
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return "Adding another "+str(bet)+" GwendoBucks to "+user+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
@ -342,17 +396,19 @@ def blackjackStand(channel,user,handNumber = 0):
data = json.load(f)
if user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["split"] == False:
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
handNumber = 0
else:
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
otherHand = False
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
otherHand = True
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
elif handNumber == 4:
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
else:
logThis(user+" tried to hit without specifying which hand")
return "You have to specify the hand you're hitting with."
@ -374,10 +430,18 @@ def blackjackStand(channel,user,handNumber = 0):
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"]:
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" is already standing")
@ -393,79 +457,136 @@ def blackjackStand(channel,user,handNumber = 0):
return "You have to enter the game before you can stand"
# When players try to split
def blackjackSplit(channel,user):
def blackjackSplit(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
if data["blackjack games"][channel]["round"] > 0:
if data["blackjack games"][channel]["user hands"][user]["hit"] == False:
if data["blackjack games"][channel]["user hands"][user]["standing"] == False:
if data["blackjack games"][channel]["round"] == 1:
firstCard = calcHandValue([data["blackjack games"][channel]["user hands"][user]["hand"][0]])
secondCard = calcHandValue([data["blackjack games"][channel]["user hands"][user]["hand"][1]])
if firstCard == secondCard:
bet = data["blackjack games"][channel]["user hands"][user]["bet"]
if money.checkBalance(user) >= bet:
money.addMoney(user,-1 * bet)
with open("resources/games/games.json", "r") as f:
data = json.load(f)
data["blackjack games"][channel]["user hands"][user]["hit"] = True
data["blackjack games"][channel]["user hands"][user]["other hand"]["hit"] = True
data["blackjack games"][channel]["user hands"][user]["split"] = True
data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"] = data["blackjack games"][channel]["user hands"][user]["bet"]
data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"].append(data["blackjack games"][channel]["user hands"][user]["hand"].pop(1))
data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"].append(drawCard(channel))
data["blackjack games"][channel]["user hands"][user]["hand"].append(drawCard(channel))
handValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"])
otherHandValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"])
if handValue > 21:
data["blackjack games"][channel]["user hands"][user]["busted"] = True
elif handValue == 21:
data["blackjack games"][channel]["user hands"][user]["blackjack"] = True
if otherHandValue > 21:
data["blackjack games"][channel]["user hands"][user]["other hand"]["busted"] = True
elif otherHandValue == 21:
data["blackjack games"][channel]["user hands"][user]["other hand"]["blackjack"] = True
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
roundDone = True
for person in data["blackjack games"][channel]["user hands"].values():
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"]:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
return "Splitting "+user+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" doesn't have enough GwendoBucks")
return "You don't have enough GwendoBucks",""
else:
logThis(user+" tried to split 2 different cards")
return "Your cards need to have the same value to split",""
else:
logThis(user+" tried to split on round "+data["blackjack games"][channel]["round"])
return "You can only split on the first round",""
else:
logThis(user+" is already standing")
return "You can't split when you're standing",""
else:
logThis(user+" has already hit this round")
return "You've already hit this round",""
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
hand = data["blackjack games"][channel]["user hands"][user]
newHand = data["blackjack games"][channel]["user hands"][user]["other hand"]
handNumber = 0
otherHand = 2
else:
logThis(user+" tried to split on the 0th round")
return "You can't split before you see your cards",""
if handNumber != 0:
if handNumber == 1:
hand = data["blackjack games"][channel]["user hands"][user]
elif handNumber == 2:
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
elif handNumber == 3:
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
else:
logThis(user+" tried to hit without specifying which hand")
return "You have to specify the hand you're hitting with."
if data["blackjack games"][channel]["user hands"][user]["split"] == 1:
newHand = data["blackjack games"][channel]["user hands"][user]["third hand"]
otherHand = 3
else:
newHand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
otherHand = 4
else:
logThis(user+" tried to split without specifying which hand")
return "You have to specify the hand you're splitting.",""
if data["blackjack games"][channel]["user hands"][user]["split"] < 3:
if data["blackjack games"][channel]["round"] != 0:
if hand["hit"] == False:
if hand["standing"] == False:
if len(hand["hand"]) == 2:
firstCard = calcHandValue([hand["hand"][0]])
secondCard = calcHandValue([hand["hand"][1]])
if firstCard == secondCard:
bet = hand["bet"]
if money.checkBalance(user) >= bet:
money.addMoney(user,-1 * bet)
with open("resources/games/games.json", "r") as f:
data = json.load(f)
hand["hit"] = True
newHand["hit"] = True
newHand = {
"hand":[],"bet":0,"standing":False,"busted":False,
"blackjack":False,"hit":True,"doubled":False}
newHand["bet"] = hand["bet"]
newHand["hand"].append(hand["hand"].pop(1))
newHand["hand"].append(drawCard(channel))
hand["hand"].append(drawCard(channel))
handValue = calcHandValue(hand["hand"])
otherHandValue = calcHandValue(newHand["hand"])
if handValue > 21:
hand["busted"] = True
elif handValue == 21:
han["blackjack"] = True
if otherHandValue > 21:
newHand["busted"] = True
elif otherHandValue == 21:
newHand["blackjack"] = True
if handNumber == 2:
data["blackjack games"][channel]["user hands"][user]["other hand"] = hand
elif handNumber == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = hand
else:
data["blackjack games"][channel]["user hands"][user] = hand
if otherHand == 3:
data["blackjack games"][channel]["user hands"][user]["third hand"] = newHand
elif otherHand == 4:
data["blackjack games"][channel]["user hands"][user]["fourth hand"] = newHand
else:
data["blackjack games"][channel]["user hands"][user]["other hand"] = newHand
data["blackjack games"][channel]["user hands"][user]["split"] += 1
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
roundDone = True
for person in data["blackjack games"][channel]["user hands"].values():
if person["hit"] == False and person["standing"] == False:
roundDone = False
if person["split"] > 0:
if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False:
roundDone = False
if person["split"] > 1:
if person["third hand"]["hit"] == False and person["third hand"]["standing"] == False:
roundDone = False
if person["split"] > 2:
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
roundDone = False
return "Splitting "+user+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
else:
logThis(user+" doesn't have enough GwendoBucks")
return "You don't have enough GwendoBucks",""
else:
logThis(user+" tried to split 2 different cards")
return "Your cards need to have the same value to split",""
else:
logThis(user+" tried to split later than they could")
return "You can only split on the first round",""
else:
logThis(user+" is already standing")
return "You can't split when you're standing",""
else:
logThis(user+" has already hit this round")
return "You've already hit this round",""
else:
logThis(user+" tried to split on the 0th round")
return "You can't split before you see your cards",""
else:
logThis(user+" tried to split more than three times")
return "You can only split 3 times",""
# Player enters the game and draws a hand
def blackjackPlayerDrawHand(channel,user,bet):
@ -491,15 +612,11 @@ def blackjackPlayerDrawHand(channel,user,bet):
if handValue == 21:
data["blackjack games"][channel]["user hands"][user] = {"hand":playerHand,
"bet":bet,"standing":False,"busted":False,"blackjack":True,"hit":True,
"doubled":False,"split":False,"other hand":{
"hand":[],"bet":0,"standing":False,"busted":False,"blackjack":False,"hit":True,
"doubled":False}}
"doubled":False,"split":0,"other hand":{},"third hand":{},"fourth hand":{}}
else:
data["blackjack games"][channel]["user hands"][user] = {"hand":playerHand,
"bet":bet,"standing":False,"busted":False,"blackjack":False,"hit":True,
"doubled":False,"split":False,"other hand":{
"hand":[],"bet":0,"standing":False,"busted":False,"blackjack":False,"hit":True,
"doubled":False}}
"doubled":False,"split":0,"other hand":{},"third hand":{},"fourth hand":{}}
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
@ -585,7 +702,7 @@ def blackjackFinish(channel):
reason = "(highest value)"
if data["blackjack games"][channel]["user hands"][user]["split"]:
if data["blackjack games"][channel]["user hands"][user]["split"] > 0:
winnings -= data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
if data["blackjack games"][channel]["user hands"][user]["other hand"]["blackjack"] and data["blackjack games"][channel]["dealer blackjack"] == False:
reason += "(blackjack)"
@ -607,6 +724,50 @@ def blackjackFinish(channel):
else:
reason += "(highest value)"
if data["blackjack games"][channel]["user hands"][user]["split"] > 1:
winnings -= data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"]
if data["blackjack games"][channel]["user hands"][user]["third hand"]["blackjack"] and data["blackjack games"][channel]["dealer blackjack"] == False:
reason += "(blackjack)"
winnings += math.floor(2.5 * data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"])
elif data["blackjack games"][channel]["dealer blackjack"]:
reason += "(dealer blackjack)"
elif data["blackjack games"][channel]["user hands"][user]["third hand"]["busted"]:
reason += "(busted)"
else:
if data["blackjack games"][channel]["dealer busted"]:
reason += "(dealer busted)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["third hand"]["hand"]) > dealerValue:
reason += "(highest value)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["third hand"]["hand"]) == dealerValue:
reason += "(pushed)"
winnings += data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"]
else:
reason += "(highest value)"
if data["blackjack games"][channel]["user hands"][user]["split"] > 2:
winnings -= data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"]
if data["blackjack games"][channel]["user hands"][user]["fourth hand"]["blackjack"] and data["blackjack games"][channel]["dealer blackjack"] == False:
reason += "(blackjack)"
winnings += math.floor(2.5 * data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"])
elif data["blackjack games"][channel]["dealer blackjack"]:
reason += "(dealer blackjack)"
elif data["blackjack games"][channel]["user hands"][user]["fourth hand"]["busted"]:
reason += "(busted)"
else:
if data["blackjack games"][channel]["dealer busted"]:
reason += "(dealer busted)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hand"]) > dealerValue:
reason += "(highest value)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hand"]) == dealerValue:
reason += "(pushed)"
winnings += data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"]
else:
reason += "(highest value)"
if winnings < 0:

View File

@ -33,7 +33,21 @@ def drawImage(channel):
key, value = list(hands.items())[x]
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
if value["split"]:
if value["split"] == 3:
table.paste(userHand,(32-borderSmol+(384*placement[x]),280-borderSmol),userHand)
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),420-borderSmol),userOtherHand)
userThirdHand = drawHand(value["third hand"]["hand"],False,value["third hand"]["busted"],value["third hand"]["blackjack"])
table.paste(userThirdHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userOtherHand)
userFourthHand = drawHand(value["fourth hand"]["hand"],False,value["fourth hand"]["busted"],value["fourth hand"]["blackjack"])
table.paste(userFourthHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
elif value["split"] == 2:
table.paste(userHand,(32-borderSmol+(384*placement[x]),420-borderSmol),userHand)
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userOtherHand)
userThirdHand = drawHand(value["third hand"]["hand"],False,value["third hand"]["busted"],value["third hand"]["blackjack"])
table.paste(userThirdHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
elif value["split"] == 1:
table.paste(userHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userHand)
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)