Skip to content

Instantly share code, notes, and snippets.

@ElectricCoffee
Last active April 20, 2019 23:56
Show Gist options
  • Save ElectricCoffee/a0aa97cce51d2b1f1cd161becccc1916 to your computer and use it in GitHub Desktop.
Save ElectricCoffee/a0aa97cce51d2b1f1cd161becccc1916 to your computer and use it in GitHub Desktop.
Inspired by the Razzle Dazzle ScamNation video on YouTube: https://www.youtube.com/watch?v=527F51qTcTg This models the dice version of the game.
# Inspired by the Razzle Dazzle scam on YouTube: https://www.youtube.com/watch?v=527F51qTcTg
# Note that this always assumes fair play
##
# Keeps track of the outcome of any given dice roll
# +points+ is how many points a given field is worth
# +prize+ is how many prizes are being added to your current pool of prizes
# +cost_mult+ is the cost multiplier of a given spot
class Outcome
attr_reader :points, :prize, :cost_mult
def initialize (points: 0, prize: 0, cost_mult: 1)
@points = points
@prize = prize
@cost_mult = cost_mult
end
end
##
# Simple dice roller. Rolls a die with a number between 1 and 6
def roll
(1..6).to_a.sample
end
##
# Returns an outcome based on the board shown in the video
def razzle_dazzle(num)
case num
when 8, 9, 47, 48
Outcome.new(points: 100)
when 10, 12, 13, 43, 44, 46
Outcome.new(points: 50)
when 11, 45
Outcome.new(points: 30)
when 14, 42
Outcome.new(points: 20)
when 15, 41
Outcome.new(points: 15)
when 16
Outcome.new(points: 10)
when 17, 39, 40
Outcome.new(points: 5)
when 18..21, 35..38
Outcome.new(prize: 1)
when 29
Outcome.new(prize: 1, cost_mult: 2)
when 22..28, 30..34
Outcome.new # adds no points and no prizes, and keeps the multiplier the same
end
end
#
# Rolls 8 dice and passes the sum into the +razzle_dazzle+ function
def dazzle()
sum = 8.times.map { roll }.sum
razzle_dazzle sum
end
money_spent = 0
total_prizes = 0
points_accumulated = 0
cost_of_play = 1
rounds_played = 0
total_wins = 0
times_doubled = 0
##
# Loop until at least 100 points have been accumulated
loop do
rounds_played += 1
money_spent += cost_of_play
outcome = dazzle()
# Comment out this line to follow the spending:
# puts "cost of play: #{cost_of_play}, money spent: #{money_spent}"
total_prizes += outcome.prize
points_accumulated += outcome.points
cost_of_play *= outcome.cost_mult
# A win here is just whenever the points increase; getting another prize is just a bonus
total_wins += 1 if outcome.points > 0
times_doubled += 1 if outcome.cost_mult > 1
break if points_accumulated >= 100
end
# add thousands separators to money_spent
money_spent = money_spent.to_s.gsub(/(?<=\d)(?=(?:\d{3})+\z)/, ',')
win_rate = (total_wins.to_f / rounds_played.to_f * 100.0).round(2)
puts "#{points_accumulated}pts. after #{rounds_played} rounds played.",
"$#{money_spent} spent.",
"#{total_prizes} prizes accumulated.",
"#{win_rate}% win-rate.",
"Cost was doubled #{times_doubled} times."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment