bridge 0.0.12 → 0.0.13

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.12
1
+ 0.0.13
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.12"
8
+ s.version = "0.0.13"
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-25}
12
+ s.date = %q{2010-02-26}
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 = [
@@ -28,12 +28,14 @@ Gem::Specification.new do |s|
28
28
  "lib/bridge/bid.rb",
29
29
  "lib/bridge/card.rb",
30
30
  "lib/bridge/deal.rb",
31
+ "lib/bridge/score.rb",
31
32
  "lib/bridge/trick.rb",
32
33
  "test/helper.rb",
33
34
  "test/test_bid.rb",
34
35
  "test/test_bridge.rb",
35
36
  "test/test_card.rb",
36
37
  "test/test_deal.rb",
38
+ "test/test_score.rb",
37
39
  "test/test_trick.rb"
38
40
  ]
39
41
  s.homepage = %q{http://github.com/qoobaa/bridge}
@@ -42,12 +44,13 @@ Gem::Specification.new do |s|
42
44
  s.rubygems_version = %q{1.3.6}
43
45
  s.summary = %q{Contract bridge utilities}
44
46
  s.test_files = [
45
- "test/test_bridge.rb",
47
+ "test/test_card.rb",
48
+ "test/test_deal.rb",
46
49
  "test/test_bid.rb",
50
+ "test/helper.rb",
47
51
  "test/test_trick.rb",
48
- "test/test_card.rb",
49
- "test/test_deal.rb",
50
- "test/helper.rb"
52
+ "test/test_score.rb",
53
+ "test/test_bridge.rb"
51
54
  ]
52
55
 
53
56
  if s.respond_to? :specification_version then
data/lib/bridge/bid.rb CHANGED
@@ -24,6 +24,19 @@ module Bridge
24
24
  suit if Bridge.trump?(suit)
25
25
  end
26
26
 
27
+ def minor?
28
+ Bridge.minor?(suit)
29
+ end
30
+
31
+ def major?
32
+ Bridge.major?(suit)
33
+ end
34
+
35
+ def no_trump?
36
+ Bridge.no_trump?(suit)
37
+ end
38
+ alias :nt? :no_trump?
39
+
27
40
  def pass?
28
41
  Bridge.pass?(bid)
29
42
  end
data/lib/bridge/card.rb CHANGED
@@ -20,6 +20,12 @@ module Bridge
20
20
  card[1]
21
21
  end
22
22
 
23
+ # Returns the honour card points
24
+ def honour_card_points
25
+ (%w(J Q K A).index(value) || -1) + 1
26
+ end
27
+ alias :hcp :honour_card_points
28
+
23
29
  # Compares the card with the other card
24
30
  def <=>(other)
25
31
  case other
data/lib/bridge/deal.rb CHANGED
@@ -114,6 +114,19 @@ module Bridge
114
114
  { "N" => n, "E" => e, "S" => s, "W" => w }.inspect
115
115
  end
116
116
 
117
+ def honour_card_points(side = nil)
118
+ hash = DIRECTIONS.inject({}) do |h, direction|
119
+ h[direction] = self[direction].inject(0) { |sum, card| sum += card.honour_card_points }
120
+ h
121
+ end
122
+ if side
123
+ side.to_s.upcase.split("").inject(0) { |sum, direction| sum += hash[direction] }
124
+ else
125
+ hash
126
+ end
127
+ end
128
+ alias :hcp :honour_card_points
129
+
117
130
  private
118
131
 
119
132
  def must_be_direction!(string)
@@ -0,0 +1,169 @@
1
+ module Bridge
2
+ class Score
3
+ attr_reader :tricks, :contract, :declarer, :modifier, :vulnerable
4
+
5
+ # Creates new score object
6
+ #
7
+ # ==== Example
8
+ # Bridge::Score.new(:contract => "7SXX", :declarer => "S", :vulnerable => "NONE", :tricks => 13)
9
+ def initialize(options = {})
10
+ options[:vulnerable] ||= "NONE"
11
+ options[:contract].gsub!(/(X+)/, "")
12
+ @modifier = $1.nil? ? 1 : $1.to_s.size * 2
13
+ @tricks = options[:tricks]
14
+ @contract = Bridge::Bid.new(options[:contract])
15
+ @vulnerable = options[:vulnerable] if Bridge::VULNERABILITIES.include?(options[:vulnerable].upcase)
16
+ @declarer = options[:declarer] if Bridge::DIRECTIONS.include?(options[:declarer].upcase)
17
+ end
18
+
19
+ def result
20
+ tricks - tricks_to_make_contract
21
+ end
22
+
23
+ def tricks_to_make_contract
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
+
35
+ def made?
36
+ result >= 0
37
+ end
38
+
39
+ def small_slam?
40
+ contract.level.to_i == 6
41
+ end
42
+
43
+ def grand_slam?
44
+ contract.level.to_i == 7
45
+ end
46
+
47
+ def vulnerable?
48
+ case vulnerable
49
+ when "BOTH"
50
+ true
51
+ when "NONE"
52
+ false
53
+ else
54
+ vulnerable.split('').include?(declarer)
55
+ end
56
+ end
57
+
58
+ def points
59
+ made? ? (made_contract_points + overtrick_points + bonus) : undertrick_points
60
+ end
61
+
62
+ def bonus
63
+ game_bonus + grand_slam_bonus + small_slam_bonus + doubled_bonus + redoubled_bonus
64
+ end
65
+
66
+ def game_bonus
67
+ if made? and made_contract_points >= 100
68
+ vulnerable? ? 500 : 300
69
+ elsif made?
70
+ 50
71
+ else
72
+ 0
73
+ end
74
+ end
75
+
76
+ def grand_slam_bonus
77
+ if made? and grand_slam?
78
+ vulnerable? ? 1500 : 1000
79
+ else
80
+ 0
81
+ end
82
+ end
83
+
84
+ def small_slam_bonus
85
+ if made? and small_slam?
86
+ vulnerable? ? 750 : 500
87
+ else
88
+ 0
89
+ end
90
+ end
91
+
92
+ def doubled_bonus
93
+ (made? and doubled?) ? 50 : 0
94
+ end
95
+
96
+ def redoubled_bonus
97
+ (made? and redoubled?) ? 100 : 0
98
+ end
99
+
100
+ def first_trick_points
101
+ contract.no_trump? ? 40 : single_trick_points
102
+ end
103
+
104
+ def single_trick_points
105
+ contract.minor? ? 20 : 30
106
+ end
107
+
108
+ def undertrick_points
109
+ vulnerable? ? vulnerable_undertrick_points : not_vulnerable_undertrick_points
110
+ end
111
+
112
+ def made_contract_points
113
+ first_trick_points * modifier + (contract.level.to_i - 1) * single_trick_points * modifier
114
+ end
115
+
116
+ def overtrick_points
117
+ if doubled?
118
+ vulnerable? ? result * 200 : result * 100
119
+ elsif redoubled?
120
+ vulnerable? ? result * 400 : result * 200
121
+ else
122
+ result * single_trick_points
123
+ end
124
+ end
125
+
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
+ # TODO: do some refactoring
137
+ def vulnerable_undertrick_points
138
+ if !made?
139
+ p = -100 * modifier
140
+ if result < -1
141
+ return p += (result + 1) * 300 if doubled?
142
+ return p += (result + 1) * 600 if redoubled?
143
+ return p += (result + 1) * 100
144
+ end
145
+ p
146
+ else
147
+ 0
148
+ end
149
+ end
150
+
151
+ def not_vulnerable_undertrick_points
152
+ if !made?
153
+ p = -50 * modifier
154
+ if [-3, -2].include?(result)
155
+ return p += (result + 1) * 200 if doubled?
156
+ return p += (result + 1) * 400 if redoubled?
157
+ return p += (result + 1) * 50 if (!doubled? and !redoubled?)
158
+ elsif result < -3
159
+ return p += (-2 * 200 + (result + 3) * 300) if doubled?
160
+ return p += (-2 * 400 + (result + 3) * 600) if redoubled?
161
+ return p += (result + 1) * 50 if (!doubled? and !redoubled?)
162
+ end
163
+ p
164
+ else
165
+ 0
166
+ end
167
+ end
168
+ end
169
+ end
data/lib/bridge/trick.rb CHANGED
@@ -11,6 +11,14 @@ module Bridge
11
11
  winner_in_suit(trump) || winner_in_suit(@suit)
12
12
  end
13
13
 
14
+ def complete?
15
+ @cards.size == 4
16
+ end
17
+
18
+ def incomplete?
19
+ !complete?
20
+ end
21
+
14
22
  private
15
23
 
16
24
  def winner_in_suit(suit)
data/lib/bridge.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "bridge/bid"
2
2
  require "bridge/card"
3
3
  require "bridge/deal"
4
+ require "bridge/score"
4
5
  require "bridge/trick"
5
6
 
6
7
  module Bridge
@@ -10,8 +11,12 @@ module Bridge
10
11
  # Card values - from A to 2
11
12
  CARD_VALUES = %w(A K Q J T 9 8 7 6 5 4 3 2)
12
13
 
14
+ MAJORS = %w(S H)
15
+
16
+ MINORS = %w(D C)
17
+
13
18
  # Trumps
14
- TRUMPS = %w(S H D C)
19
+ TRUMPS = MAJORS + MINORS
15
20
 
16
21
  # No trump string
17
22
  NO_TRUMP = "NT"
@@ -45,6 +50,12 @@ module Bridge
45
50
  # All possible bids (including contracts, modifiers and pass)
46
51
  BIDS = CONTRACTS + MODIFIERS + [PASS]
47
52
 
53
+ # 2 sides
54
+ SIDES = %w{NS EW}
55
+
56
+ # All possible vullnerabilites
57
+ VULNERABILITIES = %w{BOTH NONE} + SIDES
58
+
48
59
  def self.direction?(string)
49
60
  DIRECTIONS.include?(string)
50
61
  end
@@ -93,4 +104,16 @@ module Bridge
93
104
  def self.trump?(string)
94
105
  TRUMPS.include?(string)
95
106
  end
107
+
108
+ def self.minor?(string)
109
+ MINORS.include?(string)
110
+ end
111
+
112
+ def self.major?(string)
113
+ MAJORS.include?(string)
114
+ end
115
+
116
+ def self.no_trump?(string)
117
+ NO_TRUMP == string
118
+ end
96
119
  end
data/test/test_bid.rb CHANGED
@@ -104,4 +104,24 @@ class TestBid < Test::Unit::TestCase
104
104
  test "5NT returns nil trump" do
105
105
  assert_nil Bridge::Bid.new("5NT").trump
106
106
  end
107
+
108
+ test "1H is a major bid" do
109
+ assert Bridge::Bid.new("1H").major?
110
+ end
111
+
112
+ test "5S is a major bid" do
113
+ assert Bridge::Bid.new("5S").major?
114
+ end
115
+
116
+ test "2C is a minor bid" do
117
+ assert Bridge::Bid.new("2C").minor?
118
+ end
119
+
120
+ test "6D is a minor bid" do
121
+ assert Bridge::Bid.new("6D").minor?
122
+ end
123
+
124
+ test "1NT is a nt bid" do
125
+ assert Bridge::Bid.new("1NT").nt?
126
+ end
107
127
  end
data/test/test_card.rb CHANGED
@@ -34,4 +34,24 @@ class TestCard < Test::Unit::TestCase
34
34
  test "ST is lower than SJ" do
35
35
  assert Bridge::Card.new("ST") < Bridge::Card.new("SJ")
36
36
  end
37
+
38
+ test "H2 has no hcp" do
39
+ assert_equal 0, Bridge::Card.new("H2").hcp
40
+ end
41
+
42
+ test "SJ has 1 hcp" do
43
+ assert_equal 1, Bridge::Card.new("SJ").hcp
44
+ end
45
+
46
+ test "CQ has 2 hcp" do
47
+ assert_equal 2, Bridge::Card.new("CQ").hcp
48
+ end
49
+
50
+ test "CK has 3 hcp" do
51
+ assert_equal 3, Bridge::Card.new("CK").hcp
52
+ end
53
+
54
+ test "DA has 4 hcp" do
55
+ assert_equal 4, Bridge::Card.new("DA").hcp
56
+ end
37
57
  end
data/test/test_deal.rb CHANGED
@@ -12,6 +12,16 @@ class TestDeal < Test::Unit::TestCase
12
12
  assert_equal id, deal.id
13
13
  end
14
14
 
15
+ test "first deal hcp" do
16
+ deal = Bridge::Deal.from_id(0)
17
+ assert_equal 10, deal.hcp("N")
18
+ assert_equal 10, deal.hcp("E")
19
+ assert_equal 10, deal.hcp("S")
20
+ assert_equal 10, deal.hcp("W")
21
+ assert_equal 20, deal.hcp("NS")
22
+ assert_equal 20, deal.hcp("EW")
23
+ end
24
+
15
25
  test "last deal conversion" do
16
26
  id = Bridge::DEALS - 1
17
27
  deal = Bridge::Deal.from_id(id)
@@ -23,6 +33,16 @@ class TestDeal < Test::Unit::TestCase
23
33
  assert_equal id, deal.id
24
34
  end
25
35
 
36
+ test "last deal hcp" do
37
+ deal = Bridge::Deal.from_id(Bridge::DEALS - 1)
38
+ assert_equal 10, deal.hcp("N")
39
+ assert_equal 10, deal.hcp("E")
40
+ assert_equal 10, deal.hcp("S")
41
+ assert_equal 10, deal.hcp("W")
42
+ assert_equal 20, deal.hcp("NS")
43
+ assert_equal 20, deal.hcp("EW")
44
+ end
45
+
26
46
  test "deal no 1 000 000 000 000" do
27
47
  id = 1_000_000_000_000
28
48
  deal = Bridge::Deal.from_id(id)
@@ -0,0 +1,225 @@
1
+ require "helper"
2
+
3
+ class TestScore < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @score = Bridge::Score.new(:contract => "1S", :declarer => "N", :vulnerable => "NONE", :tricks => 9)
7
+ end
8
+
9
+ test "valid score" do
10
+ assert_false @score.contract.nil?
11
+ assert_false @score.declarer.nil?
12
+ assert_false @score.vulnerable.nil?
13
+ assert_false @score.tricks.nil?
14
+ end
15
+
16
+ test "default vulnerable set to NONE" do
17
+ score = Bridge::Score.new(:contract => "1S", :declarer => "N", :tricks => 9)
18
+ assert_equal "NONE", score.vulnerable
19
+ end
20
+
21
+ test "return modifier and contract when doubled" do
22
+ score = Bridge::Score.new(:contract => "4SX", :declarer => "N", :tricks => 9)
23
+ assert_equal 2, score.modifier
24
+ assert_equal "4S", score.contract.to_s
25
+ end
26
+
27
+ test "return modifier and contract when redoubled" do
28
+ score = Bridge::Score.new(:contract => "4SXX", :declarer => "N", :tricks => 9)
29
+ assert_equal 4, score.modifier
30
+ assert_equal "4S", score.contract.to_s
31
+ end
32
+
33
+ test "return tricks to make contract" do
34
+ assert_equal 7, @score.tricks_to_make_contract
35
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :tricks => 9)
36
+ assert_equal 12, score.tricks_to_make_contract
37
+ end
38
+
39
+ test "return made contract?" do
40
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :tricks => 9)
41
+ assert_false score.made?
42
+ score = Bridge::Score.new(:contract => "3NT", :declarer => "N", :vulnerable => "BOTH", :tricks => 3)
43
+ assert_false score.made?
44
+ score = Bridge::Score.new(:contract => "7NT", :declarer => "N", :vulnerable => "BOTH", :tricks => 13)
45
+ assert score.made?
46
+ score = Bridge::Score.new(:contract => "3NT", :declarer => "N", :vulnerable => "BOTH", :tricks => 11)
47
+ assert score.made?
48
+ end
49
+
50
+ test "return result" do
51
+ assert_equal 2, @score.result
52
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :tricks => 12)
53
+ assert_equal 0, score.result
54
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :tricks => 10)
55
+ assert_equal -2, score.result
56
+ end
57
+
58
+ test "return vulnerable" do
59
+ assert_false @score.vulnerable?
60
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :vulnerable => "BOTH", :tricks => 12)
61
+ assert score.vulnerable?
62
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :vulnerable => "NS", :tricks => 10)
63
+ assert score.vulnerable?
64
+ score = Bridge::Score.new(:contract => "6S", :declarer => "E", :vulnerable => "NS", :tricks => 10)
65
+ assert_false score.vulnerable?
66
+ end
67
+ end
68
+
69
+ class TestScorePoints < Test::Unit::TestCase
70
+
71
+ test "game bonus" do
72
+ score = Bridge::Score.new(:contract => "3S", :declarer => "N", :vulnerable => "NONE", :tricks => 9)
73
+ assert_equal 50, score.game_bonus
74
+ score = Bridge::Score.new(:contract => "4S", :declarer => "N", :vulnerable => "NONE", :tricks => 10)
75
+ assert_equal 300, score.game_bonus
76
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :vulnerable => "NONE", :tricks => 12)
77
+ assert_equal 300, score.game_bonus
78
+ score = Bridge::Score.new(:contract => "3NT", :declarer => "N", :vulnerable => "BOTH", :tricks => 9)
79
+ assert_equal 500, score.game_bonus
80
+ score = Bridge::Score.new(:contract => "3NT", :declarer => "N", :vulnerable => "BOTH", :tricks => 3)
81
+ assert_equal 0, score.game_bonus
82
+ score = Bridge::Score.new(:contract => "3SX", :declarer => "N", :vulnerable => "BOTH", :tricks => 9)
83
+ assert_equal 500, score.game_bonus
84
+ end
85
+
86
+ test "small slam bonus" do
87
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :vulnerable => "NONE", :tricks => 12)
88
+ assert_equal 500, score.small_slam_bonus
89
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :vulnerable => "BOTH", :tricks => 12)
90
+ assert_equal 750, score.small_slam_bonus
91
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :vulnerable => "BOTH", :tricks => 10)
92
+ assert_equal 0, score.small_slam_bonus
93
+ end
94
+
95
+ test "grand slam bonus" do
96
+ score = Bridge::Score.new(:contract => "7S", :declarer => "N", :vulnerable => "NONE", :tricks => 13)
97
+ assert_equal 1000, score.grand_slam_bonus
98
+ score = Bridge::Score.new(:contract => "7S", :declarer => "N", :vulnerable => "BOTH", :tricks => 13)
99
+ assert_equal 1500, score.grand_slam_bonus
100
+ score = Bridge::Score.new(:contract => "7S", :declarer => "N", :vulnerable => "BOTH", :tricks => 11)
101
+ assert_equal 0, score.grand_slam_bonus
102
+ score = Bridge::Score.new(:contract => "6S", :declarer => "N", :vulnerable => "BOTH", :tricks => 13)
103
+ assert_equal 0, score.grand_slam_bonus
104
+ end
105
+
106
+ test "doubled and redoubled cotract made bonus" do
107
+ score = Bridge::Score.new(:contract => "4SX", :declarer => "N", :tricks => 10)
108
+ assert_equal 50, score.doubled_bonus
109
+ score = Bridge::Score.new(:contract => "4SXX", :declarer => "N", :tricks => 10)
110
+ assert_equal 100, score.redoubled_bonus
111
+ assert_equal 0, score.doubled_bonus
112
+ end
113
+
114
+ test "vulnerable undertrick points" do
115
+ score = Bridge::Score.new(:contract => "4S", :declarer => "N", :vulnerable => "BOTH", :tricks => 9)
116
+ assert_equal -100, score.vulnerable_undertrick_points
117
+ score = Bridge::Score.new(:contract => "4SX", :declarer => "N", :vulnerable => "BOTH", :tricks => 9)
118
+ assert_equal -200, score.vulnerable_undertrick_points
119
+ score = Bridge::Score.new(:contract => "4SX", :declarer => "N", :vulnerable => "BOTH", :tricks => 7)
120
+ assert_equal -800, score.vulnerable_undertrick_points
121
+ score = Bridge::Score.new(:contract => "4SXX", :declarer => "N", :vulnerable => "BOTH", :tricks => 9)
122
+ assert_equal -400, score.vulnerable_undertrick_points
123
+ score = Bridge::Score.new(:contract => "4SXX", :declarer => "N", :vulnerable => "BOTH", :tricks => 7)
124
+ assert_equal -1600, score.vulnerable_undertrick_points
125
+ end
126
+
127
+ test "not vulnerable undertrick points" do
128
+ score = Bridge::Score.new(:contract => "4S", :declarer => "N", :vulnerable => "NONE", :tricks => 9)
129
+ assert_equal -50, score.not_vulnerable_undertrick_points
130
+ score = Bridge::Score.new(:contract => "4SX", :declarer => "N", :vulnerable => "NONE", :tricks => 9)
131
+ assert_equal -100, score.not_vulnerable_undertrick_points
132
+ score = Bridge::Score.new(:contract => "4SX", :declarer => "N", :vulnerable => "NONE", :tricks => 7)
133
+ assert_equal -500, score.not_vulnerable_undertrick_points
134
+ score = Bridge::Score.new(:contract => "4SXX", :declarer => "N", :vulnerable => "NONE", :tricks => 9)
135
+ assert_equal -200, score.not_vulnerable_undertrick_points
136
+ score = Bridge::Score.new(:contract => "4SXX", :declarer => "N", :vulnerable => "NONE", :tricks => 7)
137
+ assert_equal -1000, score.not_vulnerable_undertrick_points
138
+ score = Bridge::Score.new(:contract => "4SX", :declarer => "N", :vulnerable => "NONE", :tricks => 6)
139
+ assert_equal -800, score.not_vulnerable_undertrick_points
140
+ score = Bridge::Score.new(:contract => "4SXX", :declarer => "N", :vulnerable => "NONE", :tricks => 6)
141
+ assert_equal -1600, score.not_vulnerable_undertrick_points
142
+ score = Bridge::Score.new(:contract => "4S", :declarer => "N", :vulnerable => "NONE", :tricks => 6)
143
+ assert_equal -200, score.not_vulnerable_undertrick_points
144
+ end
145
+
146
+ test "overtrick points" do
147
+ score = Bridge::Score.new(:contract => "2S", :declarer => "N", :vulnerable => "NONE", :tricks => 10)
148
+ assert_equal 60, score.overtrick_points
149
+ score = Bridge::Score.new(:contract => "2SX", :declarer => "N", :vulnerable => "NONE", :tricks => 9)
150
+ assert_equal 100, score.overtrick_points
151
+ score = Bridge::Score.new(:contract => "2SXX", :declarer => "N", :vulnerable => "NONE", :tricks => 9)
152
+ assert_equal 200, score.overtrick_points
153
+ score = Bridge::Score.new(:contract => "2S", :declarer => "N", :vulnerable => "BOTH", :tricks => 9)
154
+ assert_equal 30, score.overtrick_points
155
+ score = Bridge::Score.new(:contract => "2SX", :declarer => "N", :vulnerable => "BOTH", :tricks => 9)
156
+ assert_equal 200, score.overtrick_points
157
+ score = Bridge::Score.new(:contract => "2SXX", :declarer => "N", :vulnerable => "BOTH", :tricks => 9)
158
+ assert_equal 400, score.overtrick_points
159
+ end
160
+
161
+ test "return 90 points for 1S=" do
162
+ score = Bridge::Score.new(:contract => "3S", :declarer => "N", :vulnerable => "NONE", :tricks => 9)
163
+ assert_equal 140, score.points
164
+ end
165
+
166
+ test "return 70 points for 2S=" do
167
+ score = Bridge::Score.new(:contract => "2NT", :declarer => "N", :vulnerable => "NONE", :tricks => 8)
168
+ assert_equal 120, score.points
169
+ end
170
+
171
+ test "return 80 points for 2D+2" do
172
+ score = Bridge::Score.new(:contract => "2D", :declarer => "N", :vulnerable => "NONE", :tricks => 10)
173
+ assert_equal 130, score.points
174
+ end
175
+
176
+ test "return 1400 points for 5CXX+1" do
177
+ score = Bridge::Score.new(:contract => "5CXX", :declarer => "N", :vulnerable => "BOTH", :tricks => 12)
178
+ assert_equal 1400, score.points
179
+ end
180
+
181
+ test "return 1700 points for 3NTX-7" do
182
+ score = Bridge::Score.new(:contract => "3NTX", :declarer => "N", :vulnerable => "NONE", :tricks => 2)
183
+ assert_equal -1700, score.points
184
+ end
185
+
186
+ test "return -7600 points for 7NTXX-13" do
187
+ score = Bridge::Score.new(:contract => "7NTXX", :declarer => "N", :vulnerable => "BOTH", :tricks => 0)
188
+ assert_equal -7600, score.points
189
+ end
190
+
191
+ test "return -7600 points for 7NT-13" do
192
+ score = Bridge::Score.new(:contract => "7NT", :declarer => "N", :vulnerable => "NONE", :tricks => 0)
193
+ assert_equal -650, score.points
194
+ end
195
+
196
+ test "return -1300 points for 7NT-13" do
197
+ score = Bridge::Score.new(:contract => "7NT", :declarer => "N", :vulnerable => "BOTH", :tricks => 0)
198
+ assert_equal -1300, score.points
199
+ end
200
+
201
+ test "return -3500 points for 7NTX-13" do
202
+ score = Bridge::Score.new(:contract => "7NTX", :declarer => "N", :vulnerable => "NONE", :tricks => 0)
203
+ assert_equal -3500, score.points
204
+ end
205
+
206
+ test "return -3800 points for 7NTX-13" do
207
+ score = Bridge::Score.new(:contract => "7NTX", :declarer => "N", :vulnerable => "BOTH", :tricks => 0)
208
+ assert_equal -3800, score.points
209
+ end
210
+
211
+ test "return -7000 points for 7NTXX-13" do
212
+ score = Bridge::Score.new(:contract => "7NTXX", :declarer => "N", :vulnerable => "NONE", :tricks => 0)
213
+ assert_equal -7000, score.points
214
+ end
215
+
216
+ test "return 1340 points for 1CX+6" do
217
+ score = Bridge::Score.new(:contract => "1CX", :declarer => "N", :vulnerable => "BOTH", :tricks => 13)
218
+ assert_equal 1340, score.points
219
+ end
220
+
221
+ test "return 740 points for 1CX+6" do
222
+ score = Bridge::Score.new(:contract => "1CX", :declarer => "N", :vulnerable => "NONE", :tricks => 13)
223
+ assert_equal 740, score.points
224
+ end
225
+ end
data/test/test_trick.rb CHANGED
@@ -35,4 +35,14 @@ class TestTrick < Test::Unit::TestCase
35
35
  trick = Bridge::Trick.new("S2", "HA", "CA", "DA")
36
36
  assert_equal Bridge::Card.new("S2"), trick.winner("S")
37
37
  end
38
+
39
+ test "is incomplete with 3 cards" do
40
+ trick = Bridge::Trick.new("S2", "HA", "CA")
41
+ assert trick.incomplete?
42
+ end
43
+
44
+ test "is incomplete with 4 cards" do
45
+ trick = Bridge::Trick.new("S2", "HA", "CA", "DA")
46
+ assert trick.complete?
47
+ end
38
48
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 12
9
- version: 0.0.12
8
+ - 13
9
+ version: 0.0.13
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-25 00:00:00 +01:00
17
+ date: 2010-02-26 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -50,12 +50,14 @@ files:
50
50
  - lib/bridge/bid.rb
51
51
  - lib/bridge/card.rb
52
52
  - lib/bridge/deal.rb
53
+ - lib/bridge/score.rb
53
54
  - lib/bridge/trick.rb
54
55
  - test/helper.rb
55
56
  - test/test_bid.rb
56
57
  - test/test_bridge.rb
57
58
  - test/test_card.rb
58
59
  - test/test_deal.rb
60
+ - test/test_score.rb
59
61
  - test/test_trick.rb
60
62
  has_rdoc: true
61
63
  homepage: http://github.com/qoobaa/bridge
@@ -88,9 +90,10 @@ signing_key:
88
90
  specification_version: 3
89
91
  summary: Contract bridge utilities
90
92
  test_files:
91
- - test/test_bridge.rb
92
- - test/test_bid.rb
93
- - test/test_trick.rb
94
93
  - test/test_card.rb
95
94
  - test/test_deal.rb
95
+ - test/test_bid.rb
96
96
  - test/helper.rb
97
+ - test/test_trick.rb
98
+ - test/test_score.rb
99
+ - test/test_bridge.rb