bridge 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bridge.gemspec +6 -6
- data/lib/bridge/bid.rb +1 -1
- data/lib/bridge/card.rb +2 -2
- data/lib/bridge/score.rb +29 -34
- data/test/helper.rb +1 -0
- data/test/test_score.rb +2 -2
- metadata +7 -7
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.14
|
data/bridge.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bridge}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.14"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jakub Kuźma"]
|
12
|
-
s.date = %q{2010-02
|
12
|
+
s.date = %q{2010-03-02}
|
13
13
|
s.description = %q{Useful contract bridge utilities - deal generator, id to deal and deal to id conversion}
|
14
14
|
s.email = %q{qoobaa+github@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -44,13 +44,13 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.rubygems_version = %q{1.3.6}
|
45
45
|
s.summary = %q{Contract bridge utilities}
|
46
46
|
s.test_files = [
|
47
|
-
"test/
|
47
|
+
"test/test_bridge.rb",
|
48
|
+
"test/test_trick.rb",
|
48
49
|
"test/test_deal.rb",
|
49
|
-
"test/test_bid.rb",
|
50
50
|
"test/helper.rb",
|
51
|
-
"test/test_trick.rb",
|
52
51
|
"test/test_score.rb",
|
53
|
-
"test/
|
52
|
+
"test/test_bid.rb",
|
53
|
+
"test/test_card.rb"
|
54
54
|
]
|
55
55
|
|
56
56
|
if s.respond_to? :specification_version then
|
data/lib/bridge/bid.rb
CHANGED
data/lib/bridge/card.rb
CHANGED
data/lib/bridge/score.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Bridge
|
2
2
|
class Score
|
3
|
-
attr_reader :tricks, :contract, :declarer, :
|
3
|
+
attr_reader :tricks, :contract, :declarer, :vulnerable
|
4
4
|
|
5
5
|
# Creates new score object
|
6
6
|
#
|
7
7
|
# ==== Example
|
8
|
-
# Bridge::Score.new(:contract => "7SXX", :declarer => "S", :vulnerable => "
|
8
|
+
# Bridge::Score.new(:contract => "7SXX", :declarer => "S", :vulnerable => "BOTH", :tricks => 13)
|
9
9
|
def initialize(options = {})
|
10
10
|
options[:vulnerable] ||= "NONE"
|
11
11
|
options[:contract].gsub!(/(X+)/, "")
|
@@ -16,33 +16,22 @@ module Bridge
|
|
16
16
|
@declarer = options[:declarer] if Bridge::DIRECTIONS.include?(options[:declarer].upcase)
|
17
17
|
end
|
18
18
|
|
19
|
+
# Returns nr of overtricks or undertricks. 0 if contract was made without them
|
19
20
|
def result
|
20
21
|
tricks - tricks_to_make_contract
|
21
22
|
end
|
22
23
|
|
23
|
-
|
24
|
-
contract.level.to_i + 6
|
25
|
-
end
|
26
|
-
|
27
|
-
def doubled?
|
28
|
-
@modifier == 2
|
29
|
-
end
|
30
|
-
|
31
|
-
def redoubled?
|
32
|
-
@modifier == 4
|
33
|
-
end
|
34
|
-
|
24
|
+
# Returns true if contract was made, false otherwise
|
35
25
|
def made?
|
36
26
|
result >= 0
|
37
27
|
end
|
38
28
|
|
39
|
-
|
40
|
-
|
29
|
+
# Returns points achieved by declarer: + for made contract - if conctract wasn't made
|
30
|
+
def points
|
31
|
+
made? ? (made_contract_points + overtrick_points + bonus) : undertrick_points
|
41
32
|
end
|
42
33
|
|
43
|
-
|
44
|
-
contract.level.to_i == 7
|
45
|
-
end
|
34
|
+
#private
|
46
35
|
|
47
36
|
def vulnerable?
|
48
37
|
case vulnerable
|
@@ -55,8 +44,24 @@ module Bridge
|
|
55
44
|
end
|
56
45
|
end
|
57
46
|
|
58
|
-
def
|
59
|
-
|
47
|
+
def small_slam?
|
48
|
+
contract.level.to_i == 6
|
49
|
+
end
|
50
|
+
|
51
|
+
def grand_slam?
|
52
|
+
contract.level.to_i == 7
|
53
|
+
end
|
54
|
+
|
55
|
+
def tricks_to_make_contract
|
56
|
+
contract.level.to_i + 6
|
57
|
+
end
|
58
|
+
|
59
|
+
def doubled?
|
60
|
+
@modifier == 2
|
61
|
+
end
|
62
|
+
|
63
|
+
def redoubled?
|
64
|
+
@modifier == 4
|
60
65
|
end
|
61
66
|
|
62
67
|
def bonus
|
@@ -110,7 +115,7 @@ module Bridge
|
|
110
115
|
end
|
111
116
|
|
112
117
|
def made_contract_points
|
113
|
-
first_trick_points * modifier + (contract.level.to_i - 1) * single_trick_points * modifier
|
118
|
+
first_trick_points * @modifier + (contract.level.to_i - 1) * single_trick_points * @modifier
|
114
119
|
end
|
115
120
|
|
116
121
|
def overtrick_points
|
@@ -123,20 +128,10 @@ module Bridge
|
|
123
128
|
end
|
124
129
|
end
|
125
130
|
|
126
|
-
def not_vulnerable_overtrick_points
|
127
|
-
if doubled?
|
128
|
-
result * 200
|
129
|
-
elsif redoubled?
|
130
|
-
result * 400
|
131
|
-
else
|
132
|
-
result * single_trick_points
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
131
|
# TODO: do some refactoring
|
137
132
|
def vulnerable_undertrick_points
|
138
133
|
if !made?
|
139
|
-
p = -100 * modifier
|
134
|
+
p = -100 * @modifier
|
140
135
|
if result < -1
|
141
136
|
return p += (result + 1) * 300 if doubled?
|
142
137
|
return p += (result + 1) * 600 if redoubled?
|
@@ -150,7 +145,7 @@ module Bridge
|
|
150
145
|
|
151
146
|
def not_vulnerable_undertrick_points
|
152
147
|
if !made?
|
153
|
-
p = -50 * modifier
|
148
|
+
p = -50 * @modifier
|
154
149
|
if [-3, -2].include?(result)
|
155
150
|
return p += (result + 1) * 200 if doubled?
|
156
151
|
return p += (result + 1) * 400 if redoubled?
|
data/test/helper.rb
CHANGED
data/test/test_score.rb
CHANGED
@@ -20,13 +20,13 @@ class TestScore < Test::Unit::TestCase
|
|
20
20
|
|
21
21
|
test "return modifier and contract when doubled" do
|
22
22
|
score = Bridge::Score.new(:contract => "4SX", :declarer => "N", :tricks => 9)
|
23
|
-
assert_equal 2, score.modifier
|
23
|
+
assert_equal 2, score.instance_variable_get(:@modifier)
|
24
24
|
assert_equal "4S", score.contract.to_s
|
25
25
|
end
|
26
26
|
|
27
27
|
test "return modifier and contract when redoubled" do
|
28
28
|
score = Bridge::Score.new(:contract => "4SXX", :declarer => "N", :tricks => 9)
|
29
|
-
assert_equal 4, score.modifier
|
29
|
+
assert_equal 4, score.instance_variable_get(:@modifier)
|
30
30
|
assert_equal "4S", score.contract.to_s
|
31
31
|
end
|
32
32
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 14
|
9
|
+
version: 0.0.14
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Jakub Ku\xC5\xBAma"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-02
|
17
|
+
date: 2010-03-02 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -90,10 +90,10 @@ signing_key:
|
|
90
90
|
specification_version: 3
|
91
91
|
summary: Contract bridge utilities
|
92
92
|
test_files:
|
93
|
-
- test/
|
93
|
+
- test/test_bridge.rb
|
94
|
+
- test/test_trick.rb
|
94
95
|
- test/test_deal.rb
|
95
|
-
- test/test_bid.rb
|
96
96
|
- test/helper.rb
|
97
|
-
- test/test_trick.rb
|
98
97
|
- test/test_score.rb
|
99
|
-
- test/
|
98
|
+
- test/test_bid.rb
|
99
|
+
- test/test_card.rb
|