bridge 0.0.17 → 0.0.18
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/README.rdoc +8 -0
- data/VERSION +1 -1
- data/bridge.gemspec +7 -7
- data/lib/bridge/deal.rb +6 -1
- data/lib/bridge/score.rb +9 -6
- data/test/test_deal.rb +5 -0
- data/test/test_score.rb +16 -9
- metadata +7 -7
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.18
|
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.18"
|
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-17}
|
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/helper.rb",
|
48
|
+
"test/test_bid.rb",
|
49
|
+
"test/test_card.rb",
|
48
50
|
"test/test_trick.rb",
|
49
51
|
"test/test_deal.rb",
|
50
|
-
"test/
|
51
|
-
"test/test_score.rb"
|
52
|
-
"test/test_bid.rb",
|
53
|
-
"test/test_card.rb"
|
52
|
+
"test/test_bridge.rb",
|
53
|
+
"test/test_score.rb"
|
54
54
|
]
|
55
55
|
|
56
56
|
if s.respond_to? :specification_version then
|
data/lib/bridge/deal.rb
CHANGED
@@ -110,8 +110,13 @@ module Bridge
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
# Returns hash with hands
|
114
|
+
def to_hash
|
115
|
+
{ "N" => n, "E" => e, "S" => s, "W" => w }
|
116
|
+
end
|
117
|
+
|
113
118
|
def inspect
|
114
|
-
|
119
|
+
to_hash.inspect
|
115
120
|
end
|
116
121
|
|
117
122
|
def honour_card_points(side = nil)
|
data/lib/bridge/score.rb
CHANGED
@@ -8,7 +8,8 @@ module Bridge
|
|
8
8
|
# Bridge::Score.new(:contract => "7SXX", :vulnerable => true, :tricks => "=")
|
9
9
|
def initialize(options = {})
|
10
10
|
@contract, @modifier = split_contract(options[:contract])
|
11
|
-
@tricks = calculate_tricks(options[:tricks]
|
11
|
+
@tricks = calculate_tricks(options[:tricks])
|
12
|
+
raise ArgumentError, "invalid tricks: #{@tricks}" unless (0..13).include?(@tricks)
|
12
13
|
@vulnerable = options[:vulnerable] || false
|
13
14
|
end
|
14
15
|
|
@@ -149,13 +150,15 @@ module Bridge
|
|
149
150
|
end
|
150
151
|
|
151
152
|
def calculate_tricks(tricks)
|
152
|
-
if tricks
|
153
|
+
if tricks.kind_of? Numeric
|
154
|
+
tricks
|
155
|
+
elsif tricks =~ /\A\+\d\Z/
|
153
156
|
tricks_to_make_contract + tricks[1..1].to_i
|
154
157
|
elsif tricks =~ /\A-\d\Z/
|
155
158
|
tricks_to_make_contract - tricks[1..1].to_i
|
156
159
|
elsif tricks =~ /\A=\Z/
|
157
|
-
tricks_to_make_contract
|
158
|
-
|
160
|
+
tricks_to_make_contract
|
161
|
+
elsif tricks =~ /\A\d[0-3]?\Z/
|
159
162
|
tricks.to_i
|
160
163
|
end
|
161
164
|
end
|
@@ -168,8 +171,8 @@ module Bridge
|
|
168
171
|
|
169
172
|
def self.all_contracts
|
170
173
|
result = {}
|
171
|
-
contracts = %w(1 2 3 4 5 6 7).inject([]) do |
|
172
|
-
|
174
|
+
contracts = %w(1 2 3 4 5 6 7).inject([]) do |bids, level|
|
175
|
+
bids += ["H/S", "C/D", "NT"].map { |suit| level + suit }
|
173
176
|
end
|
174
177
|
(contracts + contracts.map { |c| c + "X" } + contracts.map { |c| c + "XX" }).each do |contract|
|
175
178
|
[true, false].each do |vulnerable|
|
data/test/test_deal.rb
CHANGED
@@ -120,4 +120,9 @@ class TestDeal < Test::Unit::TestCase
|
|
120
120
|
assert_equal "W", deal.owner("H6")
|
121
121
|
assert_equal "W", deal.owner("C9")
|
122
122
|
end
|
123
|
+
|
124
|
+
test "to_hash returns hash" do
|
125
|
+
deal = Bridge::Deal.from_id(0)
|
126
|
+
assert_equal Hash, deal.to_hash.class
|
127
|
+
end
|
123
128
|
end
|
data/test/test_score.rb
CHANGED
@@ -38,11 +38,11 @@ class TestScore < Test::Unit::TestCase
|
|
38
38
|
test "return made contract?" do
|
39
39
|
score = Bridge::Score.new(:contract => "6S", :tricks => 9)
|
40
40
|
assert_false score.made?
|
41
|
-
score = Bridge::Score.new(:contract => "3NT", :
|
41
|
+
score = Bridge::Score.new(:contract => "3NT", :tricks => 3)
|
42
42
|
assert_false score.made?
|
43
|
-
score = Bridge::Score.new(:contract => "7NT", :
|
43
|
+
score = Bridge::Score.new(:contract => "7NT", :tricks => 13)
|
44
44
|
assert score.made?
|
45
|
-
score = Bridge::Score.new(:contract => "3NT", :
|
45
|
+
score = Bridge::Score.new(:contract => "3NT", :tricks => 11)
|
46
46
|
assert score.made?
|
47
47
|
end
|
48
48
|
|
@@ -63,23 +63,30 @@ class TestScore < Test::Unit::TestCase
|
|
63
63
|
end
|
64
64
|
|
65
65
|
test "calculate tricks with plus" do
|
66
|
-
score = Bridge::Score.new(:contract => "4S", :
|
66
|
+
score = Bridge::Score.new(:contract => "4S", :tricks => "+1")
|
67
67
|
assert_equal 11, score.tricks
|
68
68
|
end
|
69
69
|
|
70
70
|
test "calculate tricks with minus" do
|
71
|
-
score = Bridge::Score.new(:contract => "4S", :
|
71
|
+
score = Bridge::Score.new(:contract => "4S", :tricks => "-4")
|
72
72
|
assert_equal 6, score.tricks
|
73
73
|
end
|
74
74
|
|
75
75
|
test "calculate tricks with equal sign" do
|
76
|
-
score = Bridge::Score.new(:contract => "4S", :
|
76
|
+
score = Bridge::Score.new(:contract => "4S", :tricks => "=")
|
77
77
|
assert_equal 10, score.tricks
|
78
78
|
end
|
79
79
|
|
80
|
-
test "
|
81
|
-
|
82
|
-
|
80
|
+
test "15 is not a valid tricks argument" do
|
81
|
+
assert_raises(ArgumentError) do
|
82
|
+
Bridge::Score.new(:contract => "4S", :tricks => 15)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
test "wrong string is not a valid tricks argument" do
|
87
|
+
assert_raises(ArgumentError) do
|
88
|
+
Bridge::Score.new(:contract => "4S", :tricks => "wrong")
|
89
|
+
end
|
83
90
|
end
|
84
91
|
end
|
85
92
|
|
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
|
+
- 18
|
9
|
+
version: 0.0.18
|
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-17 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/test_bridge.rb
|
94
|
-
- test/test_trick.rb
|
95
|
-
- test/test_deal.rb
|
96
93
|
- test/helper.rb
|
97
|
-
- test/test_score.rb
|
98
94
|
- test/test_bid.rb
|
99
95
|
- test/test_card.rb
|
96
|
+
- test/test_trick.rb
|
97
|
+
- test/test_deal.rb
|
98
|
+
- test/test_bridge.rb
|
99
|
+
- test/test_score.rb
|