How to use GamesDice to produce stats for fixed size dice pool
# Related to: http://rpg.stackexchange.com/questions/37270/how-can-i-get-anydice-to-determine-these-odds | |
require 'games_dice' | |
die_types = [ 4, 6, 8, 10, 12, 20 ] | |
die_types.each_cons(2) do |type_lower, type_upper| | |
(0..6).each do |num_upper| | |
num_lower = 6 - num_upper | |
# We want 6d20, but we don't want repetition | |
next if num_upper == 6 && type_upper != 20 | |
# Generate dice description. GamesDice does not treat e.g. "0d6" as valid. | |
# The "m4" is a way of coding: Score 0 by default, or 1 when result is 4 or higher | |
dice_text = case num_upper | |
when 0 then "#{num_lower}d#{type_lower}m4" | |
when 6 then "#{num_upper}d#{type_upper}m4" | |
else "#{num_lower}d#{type_lower}m4 + #{num_upper}d#{type_upper}m4" | |
end | |
# Creates a GamesDice::Dice object | |
dice_pool = GamesDice.create dice_text | |
# Output heading then probabilities | |
puts "\n#{dice_text.gsub(/m4/,'')}, target 4+" | |
probs = dice_pool.probabilities | |
(1..6).each do |successes| | |
print " #{successes}:#{sprintf('%5.1f', probs.p_ge(successes) * 100)}%" | |
end | |
puts | |
end | |
end |
This comment has been minimized.
This comment has been minimized.
\Would this be an option for working out Probability of being able to purchase a card in my custom die system? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
I'm happy to answer questions about this script here, or on StackOverflow.