bridge 0.0.9 → 0.0.10

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 CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bridge}
8
- s.version = "0.0.9"
8
+ s.version = "0.0.10"
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"]
@@ -40,11 +40,11 @@ Gem::Specification.new do |s|
40
40
  s.rubygems_version = %q{1.3.6}
41
41
  s.summary = %q{Contract bridge utilities}
42
42
  s.test_files = [
43
- "test/test_card.rb",
44
- "test/test_deal.rb",
43
+ "test/test_bridge.rb",
45
44
  "test/test_bid.rb",
46
- "test/helper.rb",
47
- "test/test_bridge.rb"
45
+ "test/test_card.rb",
46
+ "test/test_deal.rb",
47
+ "test/helper.rb"
48
48
  ]
49
49
 
50
50
  if s.respond_to? :specification_version then
@@ -6,10 +6,19 @@ module Bridge
6
6
  # Number of possible deals in bridge
7
7
  DEALS = 53_644_737_765_488_792_839_237_440_000
8
8
 
9
+ # Card values - from A to 2
10
+ CARD_VALUES = %w(A K Q J T 9 8 7 6 5 4 3 2)
11
+
12
+ # Trumps
13
+ TRUMPS = %w(S H D C)
14
+
15
+ # No trump string
16
+ NO_TRUMP = "NT"
17
+
9
18
  # Array with card strings in the bridge deck (AKQJT98765432, four
10
19
  # suits). Contains "SA", "HT", etc.
11
- DECK = %w(S H D C).inject([]) do |d, s|
12
- d += %w(A K Q J T 9 8 7 6 5 4 3 2).map { |c| s + c }
20
+ DECK = TRUMPS.inject([]) do |d, s|
21
+ d += CARD_VALUES.map { |c| s + c }
13
22
  end
14
23
 
15
24
  # Direction strings "N", "E", "S" and "W"
@@ -17,7 +26,7 @@ module Bridge
17
26
 
18
27
  # Possible contracts in ascending order. Contains "1C", "6NT", etc.
19
28
  CONTRACTS = %w(1 2 3 4 5 6 7).inject([]) do |b, l|
20
- b += %w(C D H S NT).map { |s| l + s }
29
+ b += (TRUMPS.reverse + [NO_TRUMP]).map { |s| l + s }
21
30
  end
22
31
 
23
32
  # Pass string
@@ -79,4 +88,8 @@ module Bridge
79
88
  def self.bid?(string)
80
89
  BIDS.include?(string)
81
90
  end
91
+
92
+ def self.trump?(string)
93
+ TRUMPS.include?(string)
94
+ end
82
95
  end
@@ -20,6 +20,10 @@ module Bridge
20
20
  bid[1..-1] if contract?
21
21
  end
22
22
 
23
+ def trump
24
+ suit if Bridge.trump?(suit)
25
+ end
26
+
23
27
  def pass?
24
28
  Bridge.pass?(bid)
25
29
  end
@@ -96,4 +96,12 @@ class TestBid < Test::Unit::TestCase
96
96
  test "PASS and XX are not equal" do
97
97
  assert_not_equal Bridge::Bid.new("PASS"), Bridge::Bid.new("XX")
98
98
  end
99
+
100
+ test "1S returns S trump" do
101
+ assert_equal "S", Bridge::Bid.new("1S").trump
102
+ end
103
+
104
+ test "5NT returns nil trump" do
105
+ assert_nil Bridge::Bid.new("5NT").trump
106
+ end
99
107
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 9
9
- version: 0.0.9
8
+ - 10
9
+ version: 0.0.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jakub Ku\xC5\xBAma"
@@ -86,8 +86,8 @@ signing_key:
86
86
  specification_version: 3
87
87
  summary: Contract bridge utilities
88
88
  test_files:
89
+ - test/test_bridge.rb
90
+ - test/test_bid.rb
89
91
  - test/test_card.rb
90
92
  - test/test_deal.rb
91
- - test/test_bid.rb
92
93
  - test/helper.rb
93
- - test/test_bridge.rb