From 0a1b382e1aa2ab8793e18beb95a45b80dfe144f0 Mon Sep 17 00:00:00 2001 From: Nikolaj Danger Date: Mon, 3 Aug 2020 13:39:11 +0200 Subject: [PATCH] :black_joker: Double splitting --- Gwendolyn.py | 317 +++++++++++++++---------------- funcs/games/blackjack.py | 355 +++++++++++++++++++++++++---------- funcs/games/blackjackDraw.py | 16 +- 3 files changed, 433 insertions(+), 255 deletions(-) diff --git a/Gwendolyn.py b/Gwendolyn.py index f8dec23..36e4f97 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -485,186 +485,189 @@ async def parseCommands(message,content): # Runs a game of Blackjack elif content.startswith("blackjack"): - try: - # Starts the game - if content == "blackjack" or content == "blackjack ": - cardsLeft = 0 - if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"): - with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f: - for _ in f: - cardsLeft += 1 - - # Shuffles if not enough cards - if cardsLeft < blackjackMinCards: - blackjackShuffle(blackjackDecks,str(message.channel)) - logThis("Shuffling the blackjack deck...",str(message.channel)) - await message.channel.send("Shuffling the deck...") - - new_message = blackjackStart(str(message.channel)) - if new_message == "started": - - new_message = "Blackjack game started. Use \""+commandPrefix+"blackjack bet [amount]\" to enter the game within the next 30 seconds." - await message.channel.send(new_message) - oldImage = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png")) - - with open("resources/games/oldImages/blackjack"+str(message.channel), "w") as f: - f.write(str(oldImage.id)) - - await asyncio.sleep(30) - - gamedone = False - - with open("resources/games/games.json", "r") as f: - data = json.load(f) - if len(data["blackjack games"][str(message.channel)]["user hands"]) == 0: - gamedone = True - await message.channel.send("No one entered the game. Ending the game.") - gameID = data["blackjack games"][str(message.channel)]["id"] - - # Loop of game rounds - if gamedone == False: - logThis("!blackjack calling blackjackLoop()",str(message.channel)) - await blackjackLoop(message.channel,1,gameID) - else: - new_message = blackjackFinish(str(message.channel)) - await message.channel.send(new_message) - else: - await message.channel.send(new_message) - - # Entering game and placing bet - elif content.startswith("blackjack bet"): - commands = content.split(" ") - try: - amount = int(commands[2]) - except: - logThis("I didn't understand that",str(message.channel)) - response = "I didn't understand that" - else: - response = blackjackPlayerDrawHand(str(message.channel),message.author.display_name,amount) - await message.channel.send(response) + #try: + # Starts the game + if content == "blackjack" or content == "blackjack ": + cardsLeft = 0 + if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"): + with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f: + for _ in f: + cardsLeft += 1 - # Hitting - elif content.startswith("blackjack hit"): - if content == "blackjack hit" or content == "blackjack hit ": - response = blackjackHit(str(message.channel),message.author.display_name) - else: - commands = content.split(" ") - try: - handNumber = int(commands[2]) - except: - handNumber = 0 - response = blackjackHit(str(message.channel),message.author.display_name,handNumber) - - if response.startswith("accept"): - await message.add_reaction("👍") - try: - if response[6] == "T": - with open("resources/games/games.json", "r") as f: - gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] - logThis("Hit calling blackjackLoop()",str(message.channel)) - await blackjackLoop(message.channel,int(response[7:])+1,gameID) - except: - logThis("Something fucked up") - await message.channel.send("something fucked up",str(message.channel)) - else: - await message.channel.send(response) - - - # Standing - elif content.startswith("blackjack stand"): - if content == "blackjack hit" or content == "blackjack hit ": - response = blackjackStand(str(message.channel),message.author.display_name) - else: - commands = content.split(" ") - try: - handNumber = int(commands[2]) - except: - handNumber = 0 - response = blackjackStand(str(message.channel),message.author.display_name,handNumber) - - if response.startswith("accept"): - await message.add_reaction("👍") - try: - if response[6] == "T": - with open("resources/games/games.json", "r") as f: - gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] - logThis("Stand calling blackjackLoop()",str(message.channel)) - await blackjackLoop(message.channel,int(response[7:])+1,gameID) - except: - logThis("Something fucked up",str(message.channel)) - await message.channel.send("something fucked up") - else: - await message.channel.send(response) + # Shuffles if not enough cards + if cardsLeft < blackjackMinCards: + blackjackShuffle(blackjackDecks,str(message.channel)) + logThis("Shuffling the blackjack deck...",str(message.channel)) + await message.channel.send("Shuffling the deck...") - # Doubling bet - elif content.startswith("blackjack double"): + new_message = blackjackStart(str(message.channel)) + if new_message == "started": + + new_message = "Blackjack game started. Use \""+commandPrefix+"blackjack bet [amount]\" to enter the game within the next 30 seconds." + await message.channel.send(new_message) + oldImage = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png")) + + with open("resources/games/oldImages/blackjack"+str(message.channel), "w") as f: + f.write(str(oldImage.id)) + + await asyncio.sleep(30) + + gamedone = False + + with open("resources/games/games.json", "r") as f: + data = json.load(f) + if len(data["blackjack games"][str(message.channel)]["user hands"]) == 0: + gamedone = True + await message.channel.send("No one entered the game. Ending the game.") + gameID = data["blackjack games"][str(message.channel)]["id"] + + # Loop of game rounds + if gamedone == False: + logThis("!blackjack calling blackjackLoop()",str(message.channel)) + await blackjackLoop(message.channel,1,gameID) + else: + new_message = blackjackFinish(str(message.channel)) + await message.channel.send(new_message) + else: + await message.channel.send(new_message) + + # Entering game and placing bet + elif content.startswith("blackjack bet"): + commands = content.split(" ") + try: + amount = int(commands[2]) + except: + logThis("I didn't understand that",str(message.channel)) + response = "I didn't understand that" + else: + response = blackjackPlayerDrawHand(str(message.channel),message.author.display_name,amount) + await message.channel.send(response) + + # Hitting + elif content.startswith("blackjack hit"): + if content == "blackjack hit" or content == "blackjack hit ": + response = blackjackHit(str(message.channel),message.author.display_name) + else: commands = content.split(" ") try: handNumber = int(commands[2]) except: handNumber = 0 - response, roundDone = blackjackDouble(str(message.channel),message.author.display_name,handNumber) - - await message.channel.send(response) + response = blackjackHit(str(message.channel),message.author.display_name,handNumber) + if response.startswith("accept"): + await message.add_reaction("👍") try: - if roundDone[0] == "T": + if response[6] == "T": with open("resources/games/games.json", "r") as f: gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] - logThis("Double calling blackjackLoop()",str(message.channel)) - await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID) + logThis("Hit calling blackjackLoop()",str(message.channel)) + await blackjackLoop(message.channel,int(response[7:])+1,gameID) + except: + logThis("Something fucked up") + await message.channel.send("something fucked up",str(message.channel)) + else: + await message.channel.send(response) + + + # Standing + elif content.startswith("blackjack stand"): + if content == "blackjack hit" or content == "blackjack hit ": + response = blackjackStand(str(message.channel),message.author.display_name) + else: + commands = content.split(" ") + try: + handNumber = int(commands[2]) + except: + handNumber = 0 + response = blackjackStand(str(message.channel),message.author.display_name,handNumber) + + if response.startswith("accept"): + await message.add_reaction("👍") + try: + if response[6] == "T": + with open("resources/games/games.json", "r") as f: + gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] + logThis("Stand calling blackjackLoop()",str(message.channel)) + await blackjackLoop(message.channel,int(response[7:])+1,gameID) except: logThis("Something fucked up",str(message.channel)) await message.channel.send("something fucked up") - - # Splitting hand - elif content.startswith("blackjack split"): - response, roundDone = blackjackSplit(str(message.channel),message.author.display_name) - + else: await message.channel.send(response) + + # Doubling bet + elif content.startswith("blackjack double"): + commands = content.split(" ") + try: + handNumber = int(commands[2]) + except: + handNumber = 0 + response, roundDone = blackjackDouble(str(message.channel),message.author.display_name,handNumber) - #try: + await message.channel.send(response) + + try: + if roundDone[0] == "T": + with open("resources/games/games.json", "r") as f: + gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] + logThis("Double calling blackjackLoop()",str(message.channel)) + await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID) + except: + logThis("Something fucked up",str(message.channel)) + + # Splitting hand + elif content.startswith("blackjack split"): + commands = content.split(" ") + try: + handNumber = int(commands[2]) + except: + handNumber = 0 + response, roundDone = blackjackSplit(str(message.channel),message.author.display_name,handNumber) + + await message.channel.send(response) + + try: if roundDone[0] == "T": with open("resources/games/games.json", "r") as f: gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] logThis("Split calling blackjackLoop()",str(message.channel)) await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID) - #except: - # logThis("Something fucked up") - # await message.channel.send("something fucked up") - - # Returning current hi-lo value - elif content.startswith("blackjack hilo") and message.author.display_name == "Nikolaj": - if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"): - with open("resources/games/hilo/"+str(message.channel)+".txt", "r") as f: - data = f.read() - else: - data = "0" - await message.channel.send(data) - - # Shuffles the blackjack deck - elif content.startswith("blackjack shuffle"): - blackjackShuffle(blackjackDecks,str(message.channel)) - logThis("Shuffling the blackjack deck...",str(message.channel)) - await message.channel.send("Shuffling the deck...") - - - # Tells you the amount of cards left - elif content.startswith("blackjack cards"): - cardsLeft = 0 - if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"): - with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f: - for _ in f: - cardsLeft += 1 - - decksLeft = round(cardsLeft/52,1) - await message.channel.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks") + except: + logThis("Something fucked up") + # Returning current hi-lo value + elif content.startswith("blackjack hilo") and message.author.display_name == "Nikolaj": + if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"): + with open("resources/games/hilo/"+str(message.channel)+".txt", "r") as f: + data = f.read() else: - logThis("Not a command (error code 1301)") - await message.channel.send("I didn't quite understand that (error code 1301)") - except: - logThis("Something went wrong (error code 1300)") + data = "0" + await message.channel.send(data) + + # Shuffles the blackjack deck + elif content.startswith("blackjack shuffle"): + blackjackShuffle(blackjackDecks,str(message.channel)) + logThis("Shuffling the blackjack deck...",str(message.channel)) + await message.channel.send("Shuffling the deck...") + + + # Tells you the amount of cards left + elif content.startswith("blackjack cards"): + cardsLeft = 0 + if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"): + with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f: + for _ in f: + cardsLeft += 1 + + decksLeft = round(cardsLeft/52,1) + await message.channel.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks") + + else: + logThis("Not a command (error code 1301)") + await message.channel.send("I didn't quite understand that (error code 1301)") + #except: + # logThis("Something went wrong (error code 1300)") # Runs a game of four in a row elif content.startswith("fourinarow"): diff --git a/funcs/games/blackjack.py b/funcs/games/blackjack.py index e9f9a6d..8dbe3ff 100644 --- a/funcs/games/blackjack.py +++ b/funcs/games/blackjack.py @@ -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: diff --git a/funcs/games/blackjackDraw.py b/funcs/games/blackjackDraw.py index a39dbac..9c30901 100644 --- a/funcs/games/blackjackDraw.py +++ b/funcs/games/blackjackDraw.py @@ -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)