#!/usr/bin/env python import sys, random # finds the highest occuring roll (should almost always be 7) def common_roll(history): highest = (0,0) for k in history: if history[k] > highest[1]: highest = (k, history[k]) return highest def roll(history): r = random.randint(1, 6) + random.randint(1, 6) if r not in history: history[r] = 0 history[r] += 1 return r def craps(history, num): wins = 0 losses = 0 rolls = [] for x in xrange(num): point = 0 r = roll(history) n_rolls = 1 if r in (2, 3, 12): losses += 1 elif r in (7, 11): wins += 1 else: point = r r = roll(history) n_rolls += 1 while r not in (point, 7): r = roll(history) n_rolls += 1 if r == point: wins += 1 elif r == 7: losses += 1 rolls.append(n_rolls) return (wins, losses), rolls if __name__ == '__main__': n = int(sys.argv[1]) history = {} wl, rolls = craps(history,n) print 'Most common roll (roll, occurances): %d: %d' % common_roll(history) print 'Average winning percentage: {}%'.format(float(wl[0]) / n * 100) print 'Average number of rolls in a game: {}'.format( sum(rolls) / float(len(rolls))) print 'Maximum rolls: {}'.format(max(rolls))