Advertisement
Guest User

Mass Effect Quasar

a guest
Jul 6th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.14 KB | None | 0 0
  1. @wins = 0
  2. @losses = 0
  3.  
  4. def add_one_to_eight(current)
  5.     current + rand(1..8)
  6. end
  7.  
  8. def add_four_to_seven(current)
  9.     current + rand(4..7)
  10. end
  11.  
  12. def payout(num)
  13.     payout = case num
  14.     when 20
  15.         400
  16.     when 19
  17.         300
  18.     when 18
  19.         250
  20.     when 17
  21.         200
  22.     when 16
  23.         100
  24.     when 15
  25.          50
  26.     end
  27.     @profit = @profit + payout
  28.     @wins = @wins + 1
  29. end
  30.  
  31. def play
  32.     @profit = @profit - 200
  33.     current = rand(1..5)
  34.     do_turn(current)
  35. end
  36.  
  37. def do_turn(current)
  38.     if [1,2,6,7,8,13,14,15].include?(current)
  39.         current = add_four_to_seven(current)
  40.         do_turn(current)
  41.     elsif [3,4,5,9,10,11,12,16].include?(current)
  42.         current = add_one_to_eight(current)
  43.         do_turn(current)
  44.     elsif [17,18,19,20].include?(current)
  45.         payout(current)
  46.     else
  47.         @losses = @losses + 1
  48.     end
  49. end
  50.  
  51. def begin_quasar
  52.     @profit = 0
  53.     games = 1000 # number of games to simulate
  54.     i = 0
  55.  
  56.     while i < games
  57.         puts i
  58.         play
  59.         i = i + 1
  60.     end
  61.  
  62.     puts "\n Final profit: " + @profit.to_s
  63.     puts " Wins:   " + @wins.to_s + " " + ((@wins.to_f/games.to_f) * 100.to_f).floor.to_s + "%"
  64.     puts " losses: " + @losses.to_s + " " + ((@losses.to_f/games.to_f) * 100.to_f).floor.to_s + "%"
  65. end
  66.  
  67. begin_quasar
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement