Created
November 16, 2015 15:26
-
-
Save eng/4f3ae82b417dc1e3e317 to your computer and use it in GitHub Desktop.
Craps!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@roll = [] | |
@pass_line_wins = 0 | |
@pass_line_losses = 0 | |
def roll_finished | |
puts @roll.inspect | |
puts "Pass line wins #{@pass_line_wins}, pass line losses #{@pass_line_losses}" | |
@roll = [] | |
end | |
def new_roll(point=nil) | |
@d1 = rand(6) + 1 | |
@d2 = rand(6) + 1 | |
@roll << [@d1, @d2] | |
total = @d1 + @d2 | |
if point.nil? # come out roll | |
if [7, 11].include?(total) | |
# pass line win | |
@pass_line_wins += 1 | |
roll_finished | |
elsif [2, 3, 12].include?(total) | |
# pass line lose | |
@pass_line_losses += 1 | |
roll_finished | |
else | |
# point established | |
new_roll(total) | |
end | |
else | |
if total == 7 | |
# pass line lose | |
@pass_line_losses += 1 | |
roll_finished | |
elsif total == point | |
# pass line win | |
@pass_line_wins += 1 | |
roll_finished | |
else | |
new_roll(point) | |
end | |
end | |
end | |
10000.times { new_roll } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment