Last active
May 17, 2020 19:10
-
-
Save neilslater/f97fd34394e7c8969cb1 to your computer and use it in GitHub Desktop.
How to use GamesDice to produce stats for fixed size dice pool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
\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
I'm happy to answer questions about this script here, or on StackOverflow.