⚡ Improving blackjack
This commit is contained in:
@ -197,26 +197,11 @@ def blackjackHit(channel,user,handNumber = 0):
|
|||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if user in data["blackjack games"][channel]["user hands"]:
|
if user in data["blackjack games"][channel]["user hands"]:
|
||||||
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
|
|
||||||
hand = data["blackjack games"][channel]["user hands"][user]
|
|
||||||
handNumber = 0
|
|
||||||
else:
|
|
||||||
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"]
|
|
||||||
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."
|
|
||||||
else:
|
|
||||||
logThis(user+" tried to hit without specifying which hand")
|
|
||||||
return "You have to specify the hand you're hitting with."
|
|
||||||
|
|
||||||
|
hand, handNumber = getHandNumber(data["blackjack games"][channel]["user hands"][user],handNumber)
|
||||||
|
print(hand)
|
||||||
|
|
||||||
|
if hand != None:
|
||||||
if data["blackjack games"][channel]["round"] > 0:
|
if data["blackjack games"][channel]["round"] > 0:
|
||||||
if hand["hit"] == False:
|
if hand["hit"] == False:
|
||||||
if hand["standing"] == False:
|
if hand["standing"] == False:
|
||||||
@ -241,23 +226,7 @@ def blackjackHit(channel,user,handNumber = 0):
|
|||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
response = "accept"
|
response = "accept"
|
||||||
roundDone = True
|
roundDone = isRoundDone(data["blackjack games"][channel])
|
||||||
|
|
||||||
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 response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
||||||
else:
|
else:
|
||||||
@ -269,6 +238,9 @@ def blackjackHit(channel,user,handNumber = 0):
|
|||||||
else:
|
else:
|
||||||
logThis(user+" tried to hit on the 0th round")
|
logThis(user+" tried to hit on the 0th round")
|
||||||
return "You can't hit before you see your cards"
|
return "You can't hit before you see your cards"
|
||||||
|
else:
|
||||||
|
logThis(user+" didn't specify a hand")
|
||||||
|
return "You need to specify a hand"
|
||||||
else:
|
else:
|
||||||
logThis(user+" tried to hit without being in the game")
|
logThis(user+" tried to hit without being in the game")
|
||||||
return "You have to enter the game before you can hit"
|
return "You have to enter the game before you can hit"
|
||||||
@ -279,27 +251,10 @@ def blackjackDouble(channel,user,handNumber = 0):
|
|||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
|
if user in data["blackjack games"][channel]["user hands"]:
|
||||||
hand = data["blackjack games"][channel]["user hands"][user]
|
hand, handNumber = getHandNumber(data["blackjack games"][channel]["user hands"][user],handNumber)
|
||||||
handNumber = 0
|
|
||||||
else:
|
|
||||||
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"]
|
|
||||||
elif handNumber == 4:
|
|
||||||
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.",""
|
|
||||||
|
|
||||||
|
|
||||||
|
if hand != None:
|
||||||
if data["blackjack games"][channel]["round"] > 0:
|
if data["blackjack games"][channel]["round"] > 0:
|
||||||
if hand["hit"] == False:
|
if hand["hit"] == False:
|
||||||
if hand["standing"] == False:
|
if hand["standing"] == False:
|
||||||
@ -333,24 +288,7 @@ def blackjackDouble(channel,user,handNumber = 0):
|
|||||||
with open("resources/games/games.json", "w") as f:
|
with open("resources/games/games.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
roundDone = True
|
roundDone = isRoundDone(data["blackjack games"][channel])
|
||||||
|
|
||||||
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 "Adding another "+str(bet)+" GwendoBucks to "+getName(user)+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
return "Adding another "+str(bet)+" GwendoBucks to "+getName(user)+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
||||||
else:
|
else:
|
||||||
@ -368,6 +306,12 @@ def blackjackDouble(channel,user,handNumber = 0):
|
|||||||
else:
|
else:
|
||||||
logThis(user+" tried to double on the 0th round")
|
logThis(user+" tried to double on the 0th round")
|
||||||
return "You can't double down before you see your cards",""
|
return "You can't double down before you see your cards",""
|
||||||
|
else:
|
||||||
|
logThis(user+" didn't specify a hand")
|
||||||
|
return "You need to specify which hand"
|
||||||
|
else:
|
||||||
|
logThis(user+" tried to double without being in the game")
|
||||||
|
return "You can't double when you're not in the game",""
|
||||||
|
|
||||||
# When players try to stand
|
# When players try to stand
|
||||||
def blackjackStand(channel,user,handNumber = 0):
|
def blackjackStand(channel,user,handNumber = 0):
|
||||||
@ -375,26 +319,10 @@ def blackjackStand(channel,user,handNumber = 0):
|
|||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if user in data["blackjack games"][channel]["user hands"]:
|
if user in data["blackjack games"][channel]["user hands"]:
|
||||||
if data["blackjack games"][channel]["user hands"][user]["split"] == 0:
|
|
||||||
hand = data["blackjack games"][channel]["user hands"][user]
|
|
||||||
handNumber = 0
|
|
||||||
else:
|
|
||||||
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"]
|
|
||||||
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."
|
|
||||||
else:
|
|
||||||
logThis(user+" tried to hit without specifying which hand")
|
|
||||||
return "You have to specify the hand you're hitting with."
|
|
||||||
|
|
||||||
|
hand, handNumber = getHandNumber(data["blackjack games"][channel]["user hands"][user],handNumber)
|
||||||
|
|
||||||
|
if hand != None:
|
||||||
if data["blackjack games"][channel]["round"] > 0:
|
if data["blackjack games"][channel]["round"] > 0:
|
||||||
if hand["hit"] == False:
|
if hand["hit"] == False:
|
||||||
if hand["standing"] == False:
|
if hand["standing"] == False:
|
||||||
@ -403,23 +331,7 @@ def blackjackStand(channel,user,handNumber = 0):
|
|||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
response = "accept"
|
response = "accept"
|
||||||
roundDone = True
|
roundDone = isRoundDone(data["blackjack games"][channel])
|
||||||
|
|
||||||
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 response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
||||||
else:
|
else:
|
||||||
@ -431,6 +343,9 @@ def blackjackStand(channel,user,handNumber = 0):
|
|||||||
else:
|
else:
|
||||||
logThis(user+" tried to stand on the first round")
|
logThis(user+" tried to stand on the first round")
|
||||||
return "You can't stand before you see your cards"
|
return "You can't stand before you see your cards"
|
||||||
|
else:
|
||||||
|
logThis(user+" didn't specify a hand")
|
||||||
|
return "You need to specify which hand"
|
||||||
else:
|
else:
|
||||||
logThis(user+" tried to stand without being in the game")
|
logThis(user+" tried to stand without being in the game")
|
||||||
return "You have to enter the game before you can stand"
|
return "You have to enter the game before you can stand"
|
||||||
@ -526,23 +441,7 @@ def blackjackSplit(channel,user,handNumber = 0):
|
|||||||
with open("resources/games/games.json", "w") as f:
|
with open("resources/games/games.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
roundDone = True
|
roundDone = isRoundDone(data["blackjack games"][channel])
|
||||||
|
|
||||||
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 "+getName(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"])
|
return "Splitting "+getName(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:
|
else:
|
||||||
@ -745,3 +644,46 @@ def calcWinnings(hand, dealerValue, topLevel, dealerBlackjack, dealerBusted):
|
|||||||
reason += reasonTemp
|
reason += reasonTemp
|
||||||
|
|
||||||
return winnings, netWinnings, reason
|
return winnings, netWinnings, reason
|
||||||
|
|
||||||
|
def getHandNumber(user,handNumber):
|
||||||
|
try:
|
||||||
|
hand = None
|
||||||
|
|
||||||
|
if user["split"] == 0:
|
||||||
|
hand = user
|
||||||
|
handNumber = 0
|
||||||
|
else:
|
||||||
|
if handNumber != 0:
|
||||||
|
if handNumber == 1:
|
||||||
|
hand = user
|
||||||
|
elif handNumber == 2:
|
||||||
|
hand = user["other hand"]
|
||||||
|
elif handNumber == 3:
|
||||||
|
hand = user["third hand"]
|
||||||
|
elif handNumber == 4:
|
||||||
|
hand = user["fourth hand"]
|
||||||
|
|
||||||
|
return hand, handNumber
|
||||||
|
except:
|
||||||
|
logThis("Problem with getHandNumber() (error code 1322)")
|
||||||
|
|
||||||
|
def isRoundDone(game):
|
||||||
|
roundDone = True
|
||||||
|
|
||||||
|
for person in game["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 roundDone
|
||||||
|
@ -36,7 +36,7 @@ def drawImage(channel):
|
|||||||
for x in range(len(hands)):
|
for x in range(len(hands)):
|
||||||
key, value = list(hands.items())[x]
|
key, value = list(hands.items())[x]
|
||||||
key = getName(key)
|
key = getName(key)
|
||||||
logThis("drawing "+key+"'s hand")
|
#logThis("Drawing "+key+"'s hand")
|
||||||
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
|
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
|
||||||
try:
|
try:
|
||||||
if value["split"] == 3:
|
if value["split"] == 3:
|
||||||
|
@ -93,6 +93,7 @@
|
|||||||
1312 - Error in calcWinnings function
|
1312 - Error in calcWinnings function
|
||||||
1320 - Unspecified loop error
|
1320 - Unspecified loop error
|
||||||
1321 - Loop interrupted while waiting
|
1321 - Loop interrupted while waiting
|
||||||
|
1322 - Error with getHandNumber()
|
||||||
1330 - Unspecified continue error
|
1330 - Unspecified continue error
|
||||||
1331 - Error in testIfStanding()
|
1331 - Error in testIfStanding()
|
||||||
1340 - Error in drawing blackjack table
|
1340 - Error in drawing blackjack table
|
||||||
|
Reference in New Issue
Block a user