Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blackjack error
#1
When it gets to damage calculation in my blackjack rpg thing, 2d2 + 3d6 somehow does 146 damage. Help!

#This is blackjack adventure
import random

global cards
global corpoint

strd2 = "d2"
strd4 = "d4"
strd6 = "d6"
strd8 = "d8"
strd10 = "d10"
strd12 = "d12"

cards = ["junk", "ace", "two", "three" , "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king"]
corpoint = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
#correlating point value^
def deckreset() :
    global deck
    deck = []
    deckset = 0
    while deckset < 4 :
        deck.append("ace")
        deck.append("two")
        deck.append("three")
        deck.append("four")
        deck.append("five")
        deck.append("six")
        deck.append("seven")
        deck.append("eight")
        deck.append("nine")
        deck.append("ten")
        deck.append("jack")
        deck.append("queen")
        deck.append("king")
        deckset += 1
#reset the deck^

def draw() :
    global carddrawn
    drawn = random.randint(1, 13)
    carddrawn = cards[drawn]
    value = corpoint[drawn]
    deck.remove(carddrawn)
    return value
#draw a card^

def battle(enemy, enemyhealth, conf) :
    
    ehealth = enemyhealth
    global etotal
    global epassed
    global elose
    global edead
    epassed = False
    elose = False

    global phealth
    global ppassed
    global plose
    global ptotal
    global pdead
    ppassed = False
    plose = False
    phealth = 200
    phit = False

    bidded = False

    while phealth >= 0 and ehealth >= 0 :
        diepool = ["d2", "d2"]
        lastbid = ["d2"]
        deckreset()
        ptotal = draw() + draw()
        etotal = draw() + draw()
        edead = False
        pdead = False
        
        while elose == False and plose == False and pdead == False and edead == False :
            print("HP: " + str(phealth))
            print("Enemy HP: " + str(ehealth))
            if ppassed == False or epassed == False :
                while ppassed == False and phit == False :
                    print("Your total is " + str(ptotal) + ". Would you like to pass or hit?")
                    answer = input()
                    if answer == "pass" :
                        ppassed = True
                    if answer == "hit" :
                        while bidded == False :
                            print("Last wager was " + str(lastbid) + ".")
                            print("Would you like to raise or match?")
                            raiseormatch = input()
                            if raiseormatch == "raise" :
                                print("What die type would you like to wager (ex. d12)?")
                                dtype = input()
                                print("How many dice would you like to roll?")
                                numrolled = int(input())
                                if numrolled <= 0 :
                                    print("You have to wager.")
                                elif dtype != "d2" and dtype != "d4" and dtype != "d6" and dtype != "d8" and dtype != "d10" and dtype != "d12" :
                                    print("That is not an available type.")
                                else :
                                    while numrolled > 0 :
                                        diepool.append(dtype)
                                        lastbid.append(dtype)
                                        numrolled -= 1
                                    more = input("Would you like to wager more?\n")
                                    if more == "no" :
                                        bidded = True
                                    elif more == "yes" :
                                        print("")
                                    else :
                                        print("I'll take that as a no.")
                                        bidded = True
                            if raiseormatch == "match" :
                                diepool.append(lastbid)
                                bidded = True
                        pointcheck = draw()
                        if carddrawn == "ace" or carddrawn == "eight" :
                            print("You drew an " + carddrawn + ".")
                        else :
                            print("You drew a " + carddrawn + ".")
                            ptotal += pointcheck
                        if carddrawn == "ace" :
                            pointcheck = int(input("Is the ace a 1 or an 11?"))
                            if pointcheck == 11 or pointcheck == 1 :
                                ptotal += pointcheck
                            else :
                                print("I'll take that as a 1.")
                                ptotal += 1
                        if carddrawn == "eight" :
                            ptotal += pointcheck
                        if ptotal == 21 :
                            print("Your total is 21.")
                            ppassed = True
                        if ptotal > 21 :
                            print("You lose.")
                            ppassed = True
                            plose = True
                        else :
                            print("Your total is " + str(ptotal) + ".")
                        phit = True
                    else :
                        print("That wasn't an option.")
                if epassed == False and elose == False and plose == False:
                        ehit = False
                        if etotal < conf :
                            print(enemy + " hits.")
                            etotal += draw()
                            diepool += lastbid
                            ehit = True
                        if etotal >= conf and ehit == False and etotal <= 21 :
                            print(enemy + " passes.")
                            epassed = True
                        if etotal > 21 :
                            print(enemy + " loses.")
                            elose = True
                phit = False
                bidded = False

            if elose == False and plose == False :
                if etotal < ptotal :
                    elose = True
                if ptotal <= etotal :
                    plose = True
                
            if elose == True :
                damage = 0
                for strd2 in diepool :
                    damage += d2()
                for strd4 in diepool :
                    damage += d4()
                for strd6 in diepool :
                    damage += d6()
                for strd8 in diepool :
                    damage += d8()
                for strd10 in diepool :
                    damage += d10()
                for strd12 in diepool :
                    damage += d12()
                print("damage = " + str(damage))
                ehealth -= damage
                if ehealth <= 0 :
                    edead = True

            if plose == True :
                damage = 0
                for strd2 in diepool :
                    damage += d2()
                for strd4 in diepool :
                    damage += d4()
                for strd6 in diepool :
                    damage += d6()
                for strd8 in diepool :
                    damage += d8()
                for strd10 in diepool :
                    damage += d10()
                for strd12 in diepool :
                    damage += d12()
                print(damage)
                phealth -= damage
                if phealth <= 0 :
                    pdead = True
        plose = False
        ppassed = False
        elose = False
        epassed = False
            
            
def d2() :
    return random.randint(1, 2)
def d4() :
    return random.randint(1, 4)
def d6() :
    return random.randint(1, 6)
def d8() :
    return random.randint(1, 8)
def d10() :
    return random.randint(1, 10)
def d12() :
    return random.randint(1, 12)
#Dice(this is not going to go too well.)


print("A kobold poker challenges you!")
battle("kobold poker", 100, 21)
if edead == True :
    print("You won!")
if pdead == True :
    print("You died.")
    
if pdead == False :
    print("A gamblin challenges you!")
    battle("gamblin", 120, 19)
    if edead == True :
        print("You won!")
    if pdead == True :
        print("You died.")

if pdead == False :
    print("The Deckromancer challenges you!")
    battle("The Deckromancer", 200, 16)
    if edead == True :
        print("You won!")
    if pdead == True :
        print("You died.")

if pdead == False:
    print("「ZA HANDO」 challenges you!")
    battle("「ZA HANDO」", 500, 18)
    if edead == True :
        print("You won!")
    if pdead == True :
        print("You died.")

if pdead == False :
    print("RNG Dragon challenges you!")
    battle("RNG Dragon", 1000, 15)
    if edead == True :
        print("You won! You beat the game!")
    if pdead == True :
        print("You died. So close.")
Reply


Messages In This Thread
Blackjack error - by BlueClaw - Oct-03-2019, 02:42 PM
RE: Blackjack error - by Larz60+ - Oct-03-2019, 03:10 PM
RE: Blackjack error - by ichabod801 - Oct-03-2019, 03:26 PM
RE: Blackjack error - by BlueClaw - Oct-03-2019, 07:37 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020