randprize 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGRkNzRjYjNhNDg0YWFjYTI4Y2JmMmYzMjIyOWM1NWJmN2YyM2U3Yw==
4
+ ODZjZmE4Zjk1M2IyOTUzOTI4YmQwZTM0YmRmNzM5MzQ4YTZiNjM4OA==
5
5
  data.tar.gz: !binary |-
6
- NDlkYTQ5YjY1MTU4Zjk3Nzk0ODNiZWVmZmQ3ZGI2M2E0NDJjZmIyZQ==
6
+ ODRjMTY4ZTExMDAxMzkwNDVkMGRmMzEwYTE3ZWE5Yjc0YzZkNTY4OA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDJjMTkwNTUwNzI3ODdiZWMxNTg3OGZlNWIzYTFmZWNhZDQ0NzlmZDBiZWNk
10
- YTM4ZTdkOGE5ZTJkOTllNWY2ZjNhMmM5ZDhkOGIyOGMxZmIzMGY1YjQ0Mzg0
11
- NWU0NDI1NzdmYzU3NzM5YTA3NmJiZGU0Zjg5ZjI4NjQ2YzJhMDE=
9
+ Mjg2YjQ3ZGUyZWE5YTUxODY4YzI4MWNiYzNjM2NjZDMwOGQzZWNlNjcyNzQx
10
+ ODI3MWRjOTg3ZTFmZjQ2MDgwMmRkY2E2MzMyYWNhNmExMGU0Y2U5MDUyOGY1
11
+ ODY3MDVhMGRlMzVjOGExM2EyMmJhN2Q5ZjE0NjZkM2MwYjNiZjc=
12
12
  data.tar.gz: !binary |-
13
- YTAyNzNjYWJmMzVmYjMzZTQwZjMwN2UwNTIxMDgwZWQ4MzMzMDYwYWUxZTMy
14
- YjYzZjhlNGQzOWQ4NjJiMWZlZDczMWQ0YTY3OGZjZTNjYWZjMWFjNDkxYzY4
15
- YWMzZmEwY2NiMmEyMzY5N2I5NGI0Y2IzODIwYzE5MzAyZjE1NWU=
13
+ YTA4N2I5ZDE0NGEzNmMxMTlmZjAzYmYwNmQzOGZlYTJmZThlY2M1MWUyNjE0
14
+ ZDM3YWU2MDY2NzQzNDc4NTcyMWFjMThhZWU1NzAxOGU3NDI4YmNlZGU2ZTc1
15
+ ZWVkN2I0OWJmZTg2NzQ0NTRmMmFmOGU5OGRlNDFiMmY2NTIwNmI=
data/Gemfile CHANGED
@@ -1 +1,4 @@
1
- gem "codeclimate-test-reporter"
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "codeclimate-test-reporter", group: :test, require: nil
4
+ gem "multi_json"
@@ -0,0 +1,23 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ randprize (0.1.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ codeclimate-test-reporter (0.1.1)
10
+ simplecov (>= 0.7.1, < 1.0.0)
11
+ multi_json (1.8.0)
12
+ simplecov (0.7.1)
13
+ multi_json (~> 1.0)
14
+ simplecov-html (~> 0.7.1)
15
+ simplecov-html (0.7.1)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ codeclimate-test-reporter
22
+ multi_json
23
+ randprize!
data/README.md CHANGED
@@ -14,7 +14,7 @@ Prize Hash with odds
14
14
  1.upto(6) {|i| @dice[i.to_s]= {'odds'=> 6,'name'=>"rolled #{i}",'value'=>i} }
15
15
  @large={ "GP"=> {'odds'=> 100,'name'=>'grandprize','value'=>50000},"H"=> {'odds'=> 'REMAINING','name'=>'win heads','value'=>1}}
16
16
 
17
- The REMAINING flag fills in rest of prize deck with the value
17
+ The REMAINING flag fills in rest of prize deck with the value and should have value 0 for prize statistics
18
18
 
19
19
  Usage
20
20
  =======
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'randprize'
4
+ @headstails={ "T"=> {'odds'=> 2,'name'=>'win tails','value'=>0},"H"=> {'odds'=> 2,'name'=>'win heads','value'=>1}}
5
+ @dice={}
6
+ 1.upto(6) {|i| @dice[i.to_s]= {'odds'=> 6,'name'=>"rolled #{i}",'value'=>i} }
7
+ @pm=Randprize::ManagePrizes.new
8
+ @pm.prize_list(@dice)
9
+ @pm.prize_statistics
10
+ puts "-------RUN DICE------"
11
+ 1.upto(6) { |i| puts @pm.random_prize}
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
 
3
3
  module Randprize
4
4
  class ManagePrizes < Randprize::Base
5
- attr_accessor :myprizelist, :keylist, :myranges, :worstoddprize
5
+ attr_accessor :myprizelist, :keylist, :myranges, :worstoddprize, :totalwinodds
6
6
  # Take the prizes in array and massage the hashlist into something we can use
7
7
  # Add ranges
8
8
  # eg { key1=>{odds,name,value,key} key3=>{odds,name,value,key}
@@ -12,10 +12,27 @@ module Randprize
12
12
  raise 'prizelist must have at least two entries' if self.keylist.size<2
13
13
  self.myranges={}
14
14
  self.worstoddprize=0
15
+ self.totalwinodds=0
15
16
  calculate_worst_odds
16
17
  normalize_odds
17
18
 
18
19
  end
20
+ # return statistics about prize list
21
+ # set non winning value to 0
22
+ def prize_statistics
23
+ calculate_total_odds
24
+ total=self.myrange.max.to_f/self.totalwinodds.to_f
25
+ puts "Total Odds: 1 in #{total.round}"
26
+ self.keylist.each { |key| odds=1
27
+ odds=self.myrange.max.to_f/self.myprizelist[key]['odds'] if self.myprizelist[key]['odds']!="REMAINING"
28
+ puts "----#{self.myprizelist[key]['name']} odds 1 in #{odds.round}" }
29
+ end
30
+ # update total win odds for non zero value prizes
31
+ def calculate_total_odds
32
+ self.keylist.each { |key|
33
+ self.totalwinodds=self.myprizelist[key]['odds']+self.totalwinodds if self.myprizelist[key]['value'].to_f!=0
34
+ }
35
+ end
19
36
  def calculate_worst_odds
20
37
  self.keylist.each { |key|
21
38
  # puts "key is #{key} odds are: #{self.myprizelist[key]['odds']}"
@@ -9,7 +9,7 @@ class RandprizeTest < Test::Unit::TestCase
9
9
  @dice={}
10
10
  1.upto(6) {|i| @dice[i.to_s]= {'odds'=> 6,'name'=>"rolled #{i}",'value'=>i} }
11
11
  @large={ "GP"=> {'odds'=> 100,'name'=>'grandprize','value'=>50000},"H"=> {'odds'=> 'REMAINING','name'=>'win heads','value'=>1}}
12
- @exlarge={ "GP"=> {'odds'=> 50000,'name'=>'grandprize','value'=>50000},"2nd"=> {'odds'=> 5000,'name'=>'2ndprize','value'=>50000},"H"=> {'odds'=> 'REMAINING','name'=>'win heads','value'=>1}}
12
+ @exlarge={ "GP"=> {'odds'=> 50000,'name'=>'grandprize','value'=>50000},"2nd"=> {'odds'=> 5000,'name'=>'2ndprize','value'=>50000},"H"=> {'odds'=> 'REMAINING','name'=>'win heads','value'=>0}}
13
13
 
14
14
  end
15
15
 
@@ -62,6 +62,12 @@ class RandprizeTest < Test::Unit::TestCase
62
62
  assert @pm.check_prize(0)['name']=='rolled 1', "shuld return 1"
63
63
  assert @pm.check_prize(5)['name']=='rolled 6', "shuld return 6"
64
64
  end
65
+ end
66
+ def test_prizestats
67
+
68
+ @pm.prize_list(@exlarge)
69
+ puts "PRIZE STATISTICIS #{@pm.worstoddprize}"
70
+ @pm.prize_statistics
65
71
  end
66
72
  def test_aaaworstodds
67
73
 
@@ -1,6 +1,7 @@
1
1
  require 'stringio'
2
2
  require 'test/unit'
3
3
  require File.dirname(__FILE__) + '/../lib/randprize'
4
+ require 'rubygems'
4
5
  require "codeclimate-test-reporter"
5
6
  CodeClimate::TestReporter.start
6
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: randprize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Sproule
@@ -21,7 +21,9 @@ files:
21
21
  - lib/randprize.rb
22
22
  - test/randprize.rb
23
23
  - test/test_helper.rb
24
+ - bin/instantwindemo.rb
24
25
  - Gemfile
26
+ - Gemfile.lock
25
27
  - README.md
26
28
  homepage: http://github.com/semdinsp/randprize
27
29
  licenses: []