bridge 0.1.1 → 0.1.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.
@@ -53,31 +53,31 @@ module Bridge
53
53
  module Points
54
54
  IMPS =
55
55
  {
56
- 0...10 => 0,
57
- 20...40 => 1,
58
- 50...80 => 2,
59
- 90...120 => 3,
60
- 130...160 => 4,
61
- 170...210 => 5,
62
- 220...260 => 6,
63
- 270...310 => 7,
64
- 320...360 => 8,
65
- 370...420 => 9,
66
- 430...490 => 10,
67
- 500...590 => 11,
68
- 600...740 => 12,
69
- 750...890 => 13,
70
- 900...1090 => 14,
71
- 1100...1290 => 15,
72
- 1300...1490 => 16,
73
- 1500...1740 => 17,
74
- 1750...1990 => 18,
75
- 2000...2240 => 19,
76
- 2250...2490 => 20,
77
- 2500...2990 => 21,
78
- 3000...3490 => 22,
79
- 3500...3990 => 23,
80
- 4000...7600 => 24
56
+ 0..10 => 0,
57
+ 20..40 => 1,
58
+ 50..80 => 2,
59
+ 90..120 => 3,
60
+ 130..160 => 4,
61
+ 170..210 => 5,
62
+ 220..260 => 6,
63
+ 270..310 => 7,
64
+ 320..360 => 8,
65
+ 370..420 => 9,
66
+ 430..490 => 10,
67
+ 500..590 => 11,
68
+ 600..740 => 12,
69
+ 750..890 => 13,
70
+ 900..1090 => 14,
71
+ 1100..1290 => 15,
72
+ 1300..1490 => 16,
73
+ 1500..1740 => 17,
74
+ 1750..1990 => 18,
75
+ 2000..2240 => 19,
76
+ 2250..2490 => 20,
77
+ 2500..2990 => 21,
78
+ 3000..3490 => 22,
79
+ 3500..3990 => 23,
80
+ 4000..7600 => 24
81
81
  }
82
82
  class Chicago
83
83
  # values in array: [not-vulnerable, vulnerable]
@@ -6,7 +6,7 @@ module Bridge::Points
6
6
  # Creates new Imp object
7
7
  #
8
8
  # ==== Example
9
- # Bridge::Imp.new(:hcp => 25, :points => 420, :vulnerable => true)
9
+ # Bridge::Points::Chicago.new(:hcp => 25, :points => 420, :vulnerable => true)
10
10
  def initialize(options = {})
11
11
  @hcp = options[:hcp]
12
12
  raise ArgumentError, "Invalid hcp: #{hcp} - value should be between 20 and 40" unless (20..40).include?(hcp)
@@ -29,6 +29,7 @@ module Bridge::Points
29
29
  IMPS.each do |range, imps|
30
30
  return (imps * sign) if range.include?(points_difference.abs)
31
31
  end
32
+ nil
32
33
  end
33
34
 
34
35
  private
@@ -0,0 +1,29 @@
1
+ module Bridge::Points
2
+ class Duplicate
3
+ def initialize(*scores)
4
+ @scores = Array(scores).flatten
5
+ end
6
+
7
+ def max
8
+ @scores.inject({}) do |result, score|
9
+ result.tap do |r|
10
+ r[score] ||= @scores.inject(-1) { |points, s| points += (score <=> s) + 1 }
11
+ end
12
+ end
13
+ end
14
+
15
+ # def max_percents
16
+ # max.tap do |result|
17
+ # result.each do |score, points|
18
+ # result[score] = points * 100.0 / theoretical_max
19
+ # end
20
+ # end
21
+ # end
22
+
23
+ # protected
24
+
25
+ # def theoretical_max
26
+ # (@scores.size - 1) * 2
27
+ # end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Bridge
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/bridge.rb CHANGED
@@ -3,6 +3,7 @@ require "bridge/card"
3
3
  require "bridge/constants"
4
4
  require "bridge/deal"
5
5
  require "bridge/points/chicago"
6
+ require "bridge/points/duplicate"
6
7
  require "bridge/score"
7
8
  require "bridge/trick"
8
9
  require "bridge/version"
data/test/test_chicago.rb CHANGED
@@ -22,6 +22,16 @@ class TestChicago < Test::Unit::TestCase
22
22
  assert_equal 110, imp.points_to_make
23
23
  end
24
24
 
25
+ test "return nil when points are not in range" do
26
+ imp = Bridge::Points::Chicago.new(:hcp => 20, :points => 45)
27
+ assert_equal nil, imp.imps
28
+ end
29
+
30
+ test "return high value of imp range" do
31
+ imp = Bridge::Points::Chicago.new(:hcp => 22, :points => 110)
32
+ assert_equal 1, imp.imps
33
+ end
34
+
25
35
  test "return points to make when not vulnerable" do
26
36
  imp = Bridge::Points::Chicago.new(:hcp => 23, :points => 100, :vulnerable => false)
27
37
  assert_equal 110, imp.points_to_make
@@ -0,0 +1,38 @@
1
+ require "helper"
2
+
3
+ class TestDuplicate < Test::Unit::TestCase
4
+ test "maximum points with unique values" do
5
+ max = Bridge::Points::Duplicate.new(-200, -100, 620, 630, 660, 690).max
6
+ assert_equal 10, max[690]
7
+ assert_equal 8, max[660]
8
+ assert_equal 6, max[630]
9
+ assert_equal 4, max[620]
10
+ assert_equal 2, max[-100]
11
+ assert_equal 0, max[-200]
12
+ end
13
+
14
+ test "maximum points with non-unique values" do
15
+ max = Bridge::Points::Duplicate.new(420, 420, 400, 400, -50, -100).max
16
+ assert_equal 9, max[420]
17
+ assert_equal 5, max[400]
18
+ assert_equal 2, max[-50]
19
+ assert_equal 0, max[-100]
20
+ end
21
+
22
+ test "maximum points with non-unique values, without zero value" do
23
+ max = Bridge::Points::Duplicate.new(430, 420, 420, 420, 300, 300).max
24
+ assert_equal 10, max[430]
25
+ assert_equal 6, max[420]
26
+ assert_equal 1, max[300]
27
+ end
28
+
29
+ # test "maximum percents" do
30
+ # max_percents = Bridge::Points::Duplicate.new(50, 400, 110, 100, 110, 120, 50, 120, 140, 420, 110, 110, 110, 110, 50, 110, 140, 110).max_percents
31
+ # notify max_percents.inspect
32
+ # end
33
+
34
+ # test "maximum percents 2" do
35
+ # max_percents = Bridge::Points::Duplicate.new(-500, -650, -170, -170, -620, -620, -620).max_percents
36
+ # notify max_percents.inspect
37
+ # end
38
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jakub Ku\xC5\xBAma"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-13 00:00:00 +02:00
18
+ date: 2010-09-14 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,7 @@ files:
55
55
  - lib/bridge/constants.rb
56
56
  - lib/bridge/deal.rb
57
57
  - lib/bridge/points/chicago.rb
58
+ - lib/bridge/points/duplicate.rb
58
59
  - lib/bridge/score.rb
59
60
  - lib/bridge/trick.rb
60
61
  - lib/bridge/version.rb
@@ -64,6 +65,7 @@ files:
64
65
  - test/test_card.rb
65
66
  - test/test_chicago.rb
66
67
  - test/test_deal.rb
68
+ - test/test_duplicate.rb
67
69
  - test/test_score.rb
68
70
  - test/test_trick.rb
69
71
  has_rdoc: true
@@ -80,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
82
  requirements:
81
83
  - - ">="
82
84
  - !ruby/object:Gem::Version
83
- hash: -1502047250263406809
85
+ hash: -4128306614799067572
84
86
  segments:
85
87
  - 0
86
88
  version: "0"