dice_stats 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/Dice_Set.rb +13 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49cf8ee02d9aa7ef9ee4abb3688726b713c9224b
4
- data.tar.gz: 650b608be6c55f0265820eff8422763e551ea977
3
+ metadata.gz: b9f6d1a0c998b07b539e685e61268aa6a226d138
4
+ data.tar.gz: 4d14abaaeb4367ba9de944faa4f0af38bb54271f
5
5
  SHA512:
6
- metadata.gz: 64229f6e1210d768cd6a78a718ec03e65ac71f4f58b673426f31b61a7f15fb557e887b510224ae1bd50905505d9a1af3d805c6c6456f261cca3bdff4fbb6dc4e
7
- data.tar.gz: e8552eaa73ee3f102e87f6a6325f1517da34f00d38862a6ca48a23718530645121338eb31f6941a2ff2581c1a107db3de4d0158ec66b49463f0c563d0a17d8ee
6
+ metadata.gz: 3d455e7a7290ce64409899f2cde961ee9f0022c45b4b1df28e6f5c66e42c8fcb12803de87c1ba70cd7d1ac963c66b46c2c229ab55765186dee592fc98830a457
7
+ data.tar.gz: 46807c1896347316554414e5e34242e2e0b3308c75e2284a9395f4729d365fd22f37d3df2cca76cef4ade8d883ef359a17d6b22e1aad7cba9f03874149965b88
data/lib/Dice_Set.rb CHANGED
@@ -83,7 +83,13 @@ module Dice_Stats
83
83
  sub_string_split = split_string[i].downcase.split('d')
84
84
 
85
85
  # Skip calculating the sub-die distribution if the total one is already cached
86
- @dice << Dice.new(sub_string_split[0].to_i, sub_string_split[1].to_i, (probability_distribution == nil))
86
+ number_of_dice = sub_string_split[0].to_i
87
+ dice_faces = sub_string_split[1].to_i
88
+
89
+ calculate_probability = (probability_distribution == nil) && (number_of_dice * dice_faces <= 1000)
90
+ @aborted_probability_distribution = true if !calculate_probability
91
+
92
+ @dice << Dice.new(number_of_dice, dice_faces, calculate_probability)
87
93
  elsif (split_string[i].to_i > 0)
88
94
  @constant += split_string[i].to_i
89
95
  else
@@ -96,7 +102,12 @@ module Dice_Stats
96
102
  if probability_distribution != nil
97
103
  @probability_distribution = probability_distribution
98
104
  else
99
- @probability_distribution = combine_probability_distributions
105
+ if @aborted_probability_distribution || (100_000 < @dice.inject(0) { |m,d| m + (d.sides * d.count) })
106
+ @probability_distribution = {}
107
+ @aborted_probability_distribution = true
108
+ else
109
+ @probability_distribution = combine_probability_distributions
110
+ end
100
111
  end
101
112
 
102
113
  if (@probability_distribution.inject(0) { |memo,(k,v)| memo + v }.round(3).to_f != 1.0)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dice_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Foy