class Silicium::Dice::PolyhedronSet
Class represents a PolyhedronsSet percentage - hash with chances of getting definite score
Public Class Methods
new(arr)
click to toggle source
# File lib/theory_of_probability.rb, line 118 def initialize(arr) @pons = parse_pons(arr).sort_by{|item| -item.csides} @percentage = count_chance_sum end
Public Instance Methods
make_graph_by_plotter(x = percentage.size * 10, y = percentage.size * 10)
click to toggle source
creating a graph representing chances of getting points
# File lib/theory_of_probability.rb, line 150 def make_graph_by_plotter(x = percentage.size * 10, y = percentage.size * 10) filename = 'tmp/percentage.png' File.delete(filename) if File.exist?(filename) plotter = Image.new(x, y) plotter.bar_chart(percentage, 1, color('red @ 1.0')) plotter.export(filename) end
percentage()
click to toggle source
# File lib/theory_of_probability.rb, line 123 def percentage @percentage end
throw()
click to toggle source
ability to throw a polyhedron's set using hash of chances
# File lib/theory_of_probability.rb, line 136 def throw sum = 0 r = rand @percentage.each do |item| sum += item[1] if sum > r item[0] break end end end
to_s()
click to toggle source
returns array of polyhedrons
# File lib/theory_of_probability.rb, line 129 def to_s res = @pons.map {|item| item.to_s} res end