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 +4 -2
- data/lib/bridge/constants.rb +52 -51
- data/lib/bridge/{imp.rb → points/chicago.rb} +4 -4
- data/lib/bridge/version.rb +1 -1
- data/lib/bridge.rb +1 -1
- data/test/{test_imp.rb → test_chicago.rb} +8 -8
- metadata +5 -5
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
|
-
==
|
38
|
+
== Points
|
39
|
+
|
40
|
+
=== Chicago
|
39
41
|
|
40
42
|
You can calculate how many IMP points you won by:
|
41
|
-
Bridge::
|
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
|
data/lib/bridge/constants.rb
CHANGED
@@ -50,60 +50,61 @@ module Bridge
|
|
50
50
|
# All possible vullnerabilites
|
51
51
|
VULNERABILITIES = ["NONE", SIDES, "BOTH"].flatten
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
POINTS =
|
53
|
+
module Points
|
54
|
+
IMPS =
|
56
55
|
{
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
82
|
+
class Chicago
|
83
|
+
# values in array: [not-vulnerable, vulnerable]
|
84
|
+
POINTS =
|
81
85
|
{
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
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
|
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
|
30
|
+
return (imps * sign) if range.include?(points_difference.abs)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
data/lib/bridge/version.rb
CHANGED
data/lib/bridge.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
1
|
require "helper"
|
2
2
|
|
3
|
-
class
|
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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
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::
|
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
|
-
-
|
9
|
-
version: 0.1.
|
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/
|
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:
|
83
|
+
hash: -1502047250263406809
|
84
84
|
segments:
|
85
85
|
- 0
|
86
86
|
version: "0"
|