简体   繁体   中英

Python - randint() returns empty range, crashing error

I've been able to duplicate this error multiple times in my poker program and tried various unsuccessful solutions. Here's the latest:

Traceback (most recent call last):
  File "C:\Users\Pangloss\Desktop\tgchanpoker\poker.py", line 1868, in <module>
    if __name__ == '__main__': main()
  File "C:\Users\Pangloss\Desktop\tgchanpoker\poker.py", line 1866, in main
    mainGame = Game(opponent)
  File "C:\Users\Pangloss\Desktop\tgchanpoker\poker.py", line 1443, in __init__
    if randint(1,betCheck+(10-handValue[1]))<5 or gameStage == "bettingStay":
  File "C:\Python27\lib\random.py", line 241, in randint
    return self.randrange(a, b+1)
  File "C:\Python27\lib\random.py", line 217, in randrange
    raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width)
ValueError: empty range for randrange() (1,-7, -8)

And here's the relevant code:

                    handValue = checkHand(opponent.cards.cards)
                    if gameStage == "betting" or gameStage == "final" or gameStage == "finalresponding":
                        betCheck = 18-handValue[1]-round(betAmount/(setMax/5))+opponent.brashness
                    elif gameStage == "extendedFinal":
                        betCheck = 16-handValue[1]-round(betAmount/(setMax/5))+opponent.brashness-(pot/100)
                    else:
                        betCheck = 16-handValue[1]-round(betAmount/(setMax/5))+opponent.brashness
                    foldCheck = 16-handValue[1]-round(betAmount/(setMax/3))+opponent.brashness+(pot/100)
                    if randint(1,betCheck+(10-handValue[1]))<5 or gameStage == "bettingStay":

Check your value of betCheck+(10-handValue[1]) . From the traceback, it is -8.

this code

randint(1,betCheck+(10-handValue[1]))

is giving you this

randrange(1,-7,-8)

This means that betCheck+(10-handValue[1]) is giving you -8

That range will not give you any number at all, because betCheck+(10-handValue[1])) is a negative number and the range is invalid

You need to examine the code that sets betcheck and handvalue[1] to see why it is so negative

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM