bridge 0.0.21 → 0.0.22
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.
- data/VERSION +1 -1
- data/bridge.gemspec +2 -2
- data/lib/bridge/score.rb +10 -2
- data/lib/bridge.rb +11 -8
- data/test/test_bridge.rb +27 -6
- data/test/test_score.rb +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.22
|
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.22"
|
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-03-
|
12
|
+
s.date = %q{2010-03-27}
|
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 = [
|
data/lib/bridge/score.rb
CHANGED
@@ -183,10 +183,18 @@ module Bridge
|
|
183
183
|
contracts = %w(1 2 3 4 5 6 7).inject([]) do |bids, level|
|
184
184
|
bids += ["H/S", "C/D", "NT"].map { |suit| level + suit }
|
185
185
|
end
|
186
|
-
(contracts + contracts.map { |c| c + "X" } + contracts.map { |c| c + "XX" }).each do |contract|
|
186
|
+
(contracts + contracts.map { |c| c + "X" } + contracts.map { |c| c + "XX" } ).each do |contract|
|
187
187
|
[true, false].each do |vulnerable|
|
188
188
|
(0..13).each do |tricks|
|
189
|
-
|
189
|
+
score = new(:contract => contract.sub("H/S", "S").sub("C/D", "C"), :tricks => tricks, :vulnerable => vulnerable)
|
190
|
+
if score.result > 0
|
191
|
+
taken = "+" << score.result.to_s
|
192
|
+
elsif score.result == 0
|
193
|
+
taken = "="
|
194
|
+
else
|
195
|
+
taken = score.result.to_s
|
196
|
+
end
|
197
|
+
result[contract + taken + (score.vulnerable? ? "v" : "")] = score.points
|
190
198
|
end
|
191
199
|
end
|
192
200
|
end
|
data/lib/bridge.rb
CHANGED
@@ -54,7 +54,7 @@ module Bridge
|
|
54
54
|
SIDES = %w{NS EW}
|
55
55
|
|
56
56
|
# All possible vullnerabilites
|
57
|
-
VULNERABILITIES =
|
57
|
+
VULNERABILITIES = ["NONE", SIDES, "BOTH"].flatten
|
58
58
|
|
59
59
|
def self.direction?(string)
|
60
60
|
DIRECTIONS.include?(string)
|
@@ -128,19 +128,22 @@ module Bridge
|
|
128
128
|
[direction, partner_of(direction)].sort.join
|
129
129
|
end
|
130
130
|
|
131
|
-
def self.next_direction(direction)
|
131
|
+
def self.next_direction(direction = nil)
|
132
132
|
return DIRECTIONS.first if direction.nil?
|
133
133
|
return unless direction?(direction)
|
134
|
-
|
134
|
+
next_in_collection(DIRECTIONS, direction)
|
135
135
|
end
|
136
136
|
|
137
|
-
def self.
|
138
|
-
return VULNERABILITIES.first if
|
139
|
-
|
140
|
-
|
137
|
+
def self.vulnerable_in_deal(deal = nil)
|
138
|
+
return VULNERABILITIES.first if deal.nil?
|
139
|
+
round = (deal - 1).div(4) % 4
|
140
|
+
index = (deal - 1) % 4
|
141
|
+
vulnerabilities = VULNERABILITIES.dup
|
142
|
+
shift = vulnerabilities.shift(round)
|
143
|
+
vulnerabilities.push(shift).flatten[index]
|
141
144
|
end
|
142
145
|
|
143
|
-
def self.
|
146
|
+
def self.next_in_collection(collection, current)
|
144
147
|
i = (collection.index(current) + 1) % collection.size
|
145
148
|
collection[i]
|
146
149
|
end
|
data/test/test_bridge.rb
CHANGED
@@ -31,11 +31,32 @@ class TestBridge < Test::Unit::TestCase
|
|
31
31
|
assert_equal "N", Bridge.next_direction(nil)
|
32
32
|
end
|
33
33
|
|
34
|
-
test "return
|
35
|
-
assert_equal "NONE", Bridge.
|
36
|
-
|
37
|
-
assert_equal "
|
38
|
-
assert_equal "
|
39
|
-
assert_equal "
|
34
|
+
test "return vulnerable for given deal nr" do
|
35
|
+
assert_equal "NONE", Bridge.vulnerable_in_deal(nil)
|
36
|
+
|
37
|
+
assert_equal "NONE", Bridge.vulnerable_in_deal(1)
|
38
|
+
assert_equal "NS", Bridge.vulnerable_in_deal(2)
|
39
|
+
assert_equal "EW", Bridge.vulnerable_in_deal(3)
|
40
|
+
assert_equal "BOTH", Bridge.vulnerable_in_deal(4)
|
41
|
+
|
42
|
+
assert_equal "NS", Bridge.vulnerable_in_deal(5)
|
43
|
+
assert_equal "EW", Bridge.vulnerable_in_deal(6)
|
44
|
+
assert_equal "BOTH", Bridge.vulnerable_in_deal(7)
|
45
|
+
assert_equal "NONE", Bridge.vulnerable_in_deal(8)
|
46
|
+
|
47
|
+
assert_equal "EW", Bridge.vulnerable_in_deal(9)
|
48
|
+
assert_equal "BOTH", Bridge.vulnerable_in_deal(10)
|
49
|
+
assert_equal "NONE", Bridge.vulnerable_in_deal(11)
|
50
|
+
assert_equal "NS", Bridge.vulnerable_in_deal(12)
|
51
|
+
|
52
|
+
assert_equal "BOTH", Bridge.vulnerable_in_deal(13)
|
53
|
+
assert_equal "NONE", Bridge.vulnerable_in_deal(14)
|
54
|
+
assert_equal "NS", Bridge.vulnerable_in_deal(15)
|
55
|
+
assert_equal "EW", Bridge.vulnerable_in_deal(16)
|
56
|
+
|
57
|
+
assert_equal "NONE", Bridge.vulnerable_in_deal(17)
|
58
|
+
assert_equal "NS", Bridge.vulnerable_in_deal(18)
|
59
|
+
assert_equal "EW", Bridge.vulnerable_in_deal(19)
|
60
|
+
assert_equal "BOTH", Bridge.vulnerable_in_deal(20)
|
40
61
|
end
|
41
62
|
end
|
data/test/test_score.rb
CHANGED
@@ -254,11 +254,11 @@ class TestScoreContracts < Test::Unit::TestCase
|
|
254
254
|
end
|
255
255
|
|
256
256
|
test "return contracts for 1430 points" do
|
257
|
-
expected = ["1C/DXX
|
257
|
+
expected = ["1C/DXX+3v", "1C/DXX+6", "6H/S=v"]
|
258
258
|
assert_equal expected, Bridge::Score.with_points(1430)
|
259
259
|
end
|
260
260
|
|
261
|
-
test "return
|
261
|
+
test "return no contracts if not found score with given points" do
|
262
262
|
assert_equal [], Bridge::Score.with_points(100)
|
263
263
|
end
|
264
264
|
end
|
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
|
+
- 22
|
9
|
+
version: 0.0.22
|
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-03-
|
17
|
+
date: 2010-03-27 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|