Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @wins = 0
- @losses = 0
- def add_one_to_eight(current)
- current + rand(1..8)
- end
- def add_four_to_seven(current)
- current + rand(4..7)
- end
- def payout(num)
- payout = case num
- when 20
- 400
- when 19
- 300
- when 18
- 250
- when 17
- 200
- when 16
- 100
- when 15
- 50
- end
- @profit = @profit + payout
- @wins = @wins + 1
- end
- def play
- @profit = @profit - 200
- current = rand(1..5)
- do_turn(current)
- end
- def do_turn(current)
- if [1,2,6,7,8,13,14,15].include?(current)
- current = add_four_to_seven(current)
- do_turn(current)
- elsif [3,4,5,9,10,11,12,16].include?(current)
- current = add_one_to_eight(current)
- do_turn(current)
- elsif [17,18,19,20].include?(current)
- payout(current)
- else
- @losses = @losses + 1
- end
- end
- def begin_quasar
- @profit = 0
- games = 1000 # number of games to simulate
- i = 0
- while i < games
- puts i
- play
- i = i + 1
- end
- puts "\n Final profit: " + @profit.to_s
- puts " Wins: " + @wins.to_s + " " + ((@wins.to_f/games.to_f) * 100.to_f).floor.to_s + "%"
- puts " losses: " + @losses.to_s + " " + ((@losses.to_f/games.to_f) * 100.to_f).floor.to_s + "%"
- end
- begin_quasar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement