Class: Dice::PolyhedronSet
- Inherits:
-
Object
- Object
- Dice::PolyhedronSet
- Defined in:
- lib/theory_of_probability.rb
Overview
Class represents a PolyhedronsSet
Instance Method Summary collapse
-
#initialize(arr) ⇒ PolyhedronSet
constructor
A new instance of PolyhedronSet.
-
#make_graph_by_plotter(x = percentage.size * 10, y = percentage.size * 10) ⇒ Object
creating a graph representing chances of getting points.
-
#percentage ⇒ Object
hash with chances of getting definite score.
-
#throw ⇒ Object
ability to throw a polyhedron set using hash of chances.
-
#to_s ⇒ Object
returns array of polyhedrons.
Constructor Details
#initialize(arr) ⇒ PolyhedronSet
Returns a new instance of PolyhedronSet.
106 107 108 109 |
# File 'lib/theory_of_probability.rb', line 106 def initialize(arr) @pons = parse_pons(arr).sort_by{|item| -item.csides} @percentage = count_chance_sum end |
Instance Method Details
#make_graph_by_plotter(x = percentage.size * 10, y = percentage.size * 10) ⇒ Object
creating a graph representing chances of getting points
138 139 140 141 142 143 144 |
# File 'lib/theory_of_probability.rb', line 138 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.(percentage, 1, color('red @ 1.0')) plotter.export(filename) end |
#percentage ⇒ Object
hash with chances of getting definite score
112 113 114 |
# File 'lib/theory_of_probability.rb', line 112 def percentage @percentage end |
#throw ⇒ Object
ability to throw a polyhedron set using hash of chances
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/theory_of_probability.rb', line 124 def throw sum = 0 r = rand @percentage.each do |item| sum += item[1] if sum >= r item[0] break end end end |
#to_s ⇒ Object
returns array of polyhedrons
118 119 120 |
# File 'lib/theory_of_probability.rb', line 118 def to_s @pons.map {|item| item.to_s} end |