Craps Python Source

(1/1)

Richard Marks:
Okay, if its not right then oh well.  :P
I did this in 5 minutes.
I'm no craps player. I just read wikipedia for the rules.
Have fun.
Code:

def RollDice():
import random
d1 = random.randint(1, 6)
d2 = random.randint(1, 6)
return int(d1 + d2)

def ComeOutRoll():
print 'Come-Out Roll'
roll = RollDice()
if roll in [7, 11]:
# natural win
print 'A Natural, You win!'
elif roll in [2,3,12]:
# craps lose
print 'Craps! You lose!'
elif roll in [4,5,6,8,9,10]:
# the point
print 'Point %d' % (roll)
Finished = False
while not Finished: Finished = ReRoll(roll)

def ReRoll(point):
roll = RollDice()
print ' Roll: %d' % (roll)
if not roll in [7, point]:
# lose
print 'Roll again!'
elif roll in [point]:
# point match
print 'Point-Match'
elif roll in [7]:
# seven-out lose
# game over
print 'Seven-Out!\nYou lose!\nGame Over!'
return True
return False

ComeOutRoll()

Navigation

[0] Message Index