bridge 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -35,10 +35,12 @@ You can use regexp to check if contract with result is valid:
35
35
  will match i.e.
36
36
  "1NT=", "2SX+1", "6NTXX-2"
37
37
 
38
- == Imp
38
+ == Points
39
+
40
+ === Chicago
39
41
 
40
42
  You can calculate how many IMP points you won by:
41
- Bridge::Imp.new(:hcp => 25, :points => 420, :vulnerable => false).imps
43
+ Bridge::Points::Chicago.new(:hcp => 25, :points => 420, :vulnerable => false).imps
42
44
 
43
45
  Arguments:
44
46
  * :hcp -- Integer (range between 20 and 40), which means how many honour card points has side
@@ -50,60 +50,61 @@ module Bridge
50
50
  # All possible vullnerabilites
51
51
  VULNERABILITIES = ["NONE", SIDES, "BOTH"].flatten
52
52
 
53
- class Imp
54
- # values in array: [not-vulnerable, vulnerable]
55
- POINTS =
53
+ module Points
54
+ IMPS =
56
55
  {
57
- "20" => [0, 0],
58
- "21" => [50, 50],
59
- "22" => [70, 70],
60
- "23" => [110, 110],
61
- "24" => [200, 290],
62
- "25" => [300, 440],
63
- "26" => [350, 520],
64
- "27" => [400, 600],
65
- "28" => [430, 630],
66
- "29" => [460, 660],
67
- "30" => [490, 690],
68
- "31" => [600, 900],
69
- "32" => [700, 1050],
70
- "33" => [900, 1350],
71
- "34" => [1000, 1500],
72
- "35" => [1100, 1650],
73
- "36" => [1200, 1800],
74
- "37" => [1300, 1950],
75
- "38" => [1300, 1950],
76
- "39" => [1300, 1950],
77
- "40" => [1300, 1950]
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
78
81
  }
79
-
80
- IMPS =
82
+ class Chicago
83
+ # values in array: [not-vulnerable, vulnerable]
84
+ POINTS =
81
85
  {
82
- "0...10" => 0,
83
- "20...40" => 1,
84
- "50...80" => 2,
85
- "90...120" => 3,
86
- "130...160" => 4,
87
- "170...210" => 5,
88
- "220...260" => 6,
89
- "270...310" => 7,
90
- "320...360" => 8,
91
- "370...420" => 9,
92
- "430...490" => 10,
93
- "500...590" => 11,
94
- "600...740" => 12,
95
- "750...890" => 13,
96
- "900...1090" => 14,
97
- "1100...1290" => 15,
98
- "1300...1490" => 16,
99
- "1500...1740" => 17,
100
- "1750...1990" => 18,
101
- "2000...2240" => 19,
102
- "2250...2490" => 20,
103
- "2500...2990" => 21,
104
- "3000...3490" => 22,
105
- "3500...3990" => 23,
106
- "4000...7600" => 24
86
+ 20 => [0, 0],
87
+ 21 => [50, 50],
88
+ 22 => [70, 70],
89
+ 23 => [110, 110],
90
+ 24 => [200, 290],
91
+ 25 => [300, 440],
92
+ 26 => [350, 520],
93
+ 27 => [400, 600],
94
+ 28 => [430, 630],
95
+ 29 => [460, 660],
96
+ 30 => [490, 690],
97
+ 31 => [600, 900],
98
+ 32 => [700, 1050],
99
+ 33 => [900, 1350],
100
+ 34 => [1000, 1500],
101
+ 35 => [1100, 1650],
102
+ 36 => [1200, 1800],
103
+ 37 => [1300, 1950],
104
+ 38 => [1300, 1950],
105
+ 39 => [1300, 1950],
106
+ 40 => [1300, 1950]
107
107
  }
108
+ end
108
109
  end
109
110
  end
@@ -1,5 +1,5 @@
1
- module Bridge
2
- class Imp
1
+ module Bridge::Points
2
+ class Chicago
3
3
  attr_reader :hcp, :points, :vulnerable
4
4
  alias :vulnerable? :vulnerable
5
5
 
@@ -16,7 +16,7 @@ module Bridge
16
16
 
17
17
  # Returns points that side should make with given hcp
18
18
  def points_to_make
19
- POINTS[hcp.to_s][vulnerable? ? 1 : 0]
19
+ POINTS[hcp][vulnerable? ? 1 : 0]
20
20
  end
21
21
 
22
22
  # Returns points score relative to hcp
@@ -27,7 +27,7 @@ module Bridge
27
27
  # Returns imps (negative or positive) based on given points
28
28
  def imps
29
29
  IMPS.each do |range, imps|
30
- return (imps * sign) if eval(range).include?(points_difference.abs)
30
+ return (imps * sign) if range.include?(points_difference.abs)
31
31
  end
32
32
  end
33
33
 
@@ -1,3 +1,3 @@
1
1
  module Bridge
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/bridge.rb CHANGED
@@ -2,7 +2,7 @@ require "bridge/bid"
2
2
  require "bridge/card"
3
3
  require "bridge/constants"
4
4
  require "bridge/deal"
5
- require "bridge/imp"
5
+ require "bridge/points/chicago"
6
6
  require "bridge/score"
7
7
  require "bridge/trick"
8
8
  require "bridge/version"
@@ -1,39 +1,39 @@
1
1
  require "helper"
2
2
 
3
- class TestImp < Test::Unit::TestCase
3
+ class TestChicago < Test::Unit::TestCase
4
4
  test "raises ArgumentError when invalid honour card points provided" do
5
5
  assert_raises(ArgumentError) do
6
- Bridge::Imp.new(:hcp => 15, :points => 100)
6
+ Bridge::Points::Chicago.new(:hcp => 15, :points => 100)
7
7
  end
8
8
  end
9
9
 
10
10
  test "set default vulnerable to false" do
11
- imp = Bridge::Imp.new(:hcp => 40, :points => -100)
11
+ imp = Bridge::Points::Chicago.new(:hcp => 40, :points => -100)
12
12
  assert_false imp.vulnerable
13
13
  end
14
14
 
15
15
  test "return vulnerable boolean" do
16
- imp = Bridge::Imp.new(:hcp => 20, :points => 100, :vulnerable => true)
16
+ imp = Bridge::Points::Chicago.new(:hcp => 20, :points => 100, :vulnerable => true)
17
17
  assert imp.vulnerable?
18
18
  end
19
19
 
20
20
  test "return points to make when vulnerable" do
21
- imp = Bridge::Imp.new(:hcp => 23, :points => 100, :vulnerable => true)
21
+ imp = Bridge::Points::Chicago.new(:hcp => 23, :points => 100, :vulnerable => true)
22
22
  assert_equal 110, imp.points_to_make
23
23
  end
24
24
 
25
25
  test "return points to make when not vulnerable" do
26
- imp = Bridge::Imp.new(:hcp => 23, :points => 100, :vulnerable => false)
26
+ imp = Bridge::Points::Chicago.new(:hcp => 23, :points => 100, :vulnerable => false)
27
27
  assert_equal 110, imp.points_to_make
28
28
  end
29
29
 
30
30
  test "return positive imps" do
31
- imp = Bridge::Imp.new(:hcp => 21, :points => 100)
31
+ imp = Bridge::Points::Chicago.new(:hcp => 21, :points => 100)
32
32
  assert_equal 2, imp.imps
33
33
  end
34
34
 
35
35
  test "return negative imps" do
36
- imp = Bridge::Imp.new(:hcp => 21, :points => -100)
36
+ imp = Bridge::Points::Chicago.new(:hcp => 21, :points => -100)
37
37
  assert_equal -4, imp.imps
38
38
  end
39
39
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jakub Ku\xC5\xBAma"
@@ -54,7 +54,7 @@ files:
54
54
  - lib/bridge/card.rb
55
55
  - lib/bridge/constants.rb
56
56
  - lib/bridge/deal.rb
57
- - lib/bridge/imp.rb
57
+ - lib/bridge/points/chicago.rb
58
58
  - lib/bridge/score.rb
59
59
  - lib/bridge/trick.rb
60
60
  - lib/bridge/version.rb
@@ -62,8 +62,8 @@ files:
62
62
  - test/test_bid.rb
63
63
  - test/test_bridge.rb
64
64
  - test/test_card.rb
65
+ - test/test_chicago.rb
65
66
  - test/test_deal.rb
66
- - test/test_imp.rb
67
67
  - test/test_score.rb
68
68
  - test/test_trick.rb
69
69
  has_rdoc: true
@@ -80,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- hash: 2761440476130499620
83
+ hash: -1502047250263406809
84
84
  segments:
85
85
  - 0
86
86
  version: "0"