bridge 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.21
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.21"
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-22}
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
- result["#{contract}-#{tricks}#{vulnerable == true ? "-vulnerable" : ""}"] = new(:contract => contract.sub("H/S", "S").sub("C/D", "C"), :tricks => tricks, :vulnerable => vulnerable).points
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 = %w{BOTH NONE} + SIDES
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
- next_for_collection(DIRECTIONS, direction)
134
+ next_in_collection(DIRECTIONS, direction)
135
135
  end
136
136
 
137
- def self.next_vulnerable(vulnerable)
138
- return VULNERABILITIES.first if vulnerable.nil?
139
- return unless VULNERABILITIES.include?(vulnerable)
140
- next_for_collection(VULNERABILITIES, vulnerable)
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.next_for_collection(collection, current)
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 next vulnerable" do
35
- assert_equal "NONE", Bridge.next_vulnerable("BOTH")
36
- assert_equal "NS", Bridge.next_vulnerable("NONE")
37
- assert_equal "EW", Bridge.next_vulnerable("NS")
38
- assert_equal "BOTH", Bridge.next_vulnerable("EW")
39
- assert_equal "BOTH", Bridge.next_vulnerable(nil)
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-10-vulnerable", "1C/DXX-13", "6H/S-12-vulnerable"]
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 [] if not found" do
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
- - 21
9
- version: 0.0.21
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-22 00:00:00 +01:00
17
+ date: 2010-03-27 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency