Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to generate Apocalypse World failure, partial success, and success results.
collector = {}
STAT_BONUS_RANGE = (-2..3)
DIE_ONE = 6
DIE_TWO = 6
FAILURE_CEILING = 6
SUCCESS_FLOOR = 10
STAT_BONUS_RANGE.each do |stat_bonus|
collector[stat_bonus] ||= {}
(1..DIE_ONE).each do |die_one|
(1..DIE_TWO).each do |die_two|
status =
case stat_bonus + die_one + die_two
when (-10..FAILURE_CEILING) then :failure
when (SUCCESS_FLOOR..30) then :success
else
:partial_success
end
collector[stat_bonus][status] ||= 0
collector[stat_bonus][status] += 1
end
end
end
puts "<table>"
puts "<caption>#{DIE_ONE == DIE_TWO ? "Roll 2d#{DIE_ONE}" : "Roll 1d#{DIE_ONE} + 1d#{DIE_TWO}"}</caption>"
puts "<thead>"
puts "<tr><th>Bonus</th>"
puts "<th>Failure (#{FAILURE_CEILING}-)</th>"
puts "<th>Partial Success (#{FAILURE_CEILING+1}-#{SUCCESS_FLOOR-1})</th>"
puts "<th>Complete Success (#{SUCCESS_FLOOR})</th></tr>"
puts "</thead>"
puts "<tbody>"
collector.each do |stat_bonus, results|
puts "<tr>"
puts "<td>#{stat_bonus}</td>"
total = results.inject(0) {|m, (k,v)| m += v }
results.each do |result, count|
puts "<td>#{((count.to_f / total.to_f) * 1000).round.to_f / 10}%</td>"
end
puts "</tr>"
end
puts "</tbody>"
puts "</table>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.