NOGDUS

Articles, Tutorials, and other things. => General Game Programming => : Richard Marks October 29, 2007, 01:22:27 PM



: Craps Python Source
: Richard Marks October 29, 2007, 01:22:27 PM
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.
:
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()


Sorry, the copyright must be in the template.
Please notify this forum's administrator that this site is missing the copyright message for SMF so they can rectify the situation. Display of copyright is a legal requirement. For more information on this please visit the Simple Machines website.