bridge 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +2 -3
- data/README.md +56 -0
- data/Rakefile +3 -4
- data/bridge.gemspec +19 -18
- data/lib/bridge.rb +3 -1
- data/lib/bridge/auction.rb +77 -0
- data/lib/bridge/bid.rb +1 -1
- data/lib/bridge/card.rb +2 -2
- data/lib/bridge/constants.rb +42 -24
- data/lib/bridge/deal.rb +5 -10
- data/lib/bridge/play.rb +80 -0
- data/lib/bridge/score.rb +53 -47
- data/lib/bridge/trick.rb +3 -3
- data/lib/bridge/version.rb +1 -1
- data/test/auction_test.rb +133 -0
- data/test/bid_test.rb +135 -0
- data/test/bridge_test.rb +118 -0
- data/test/{test_card.rb → card_test.rb} +12 -12
- data/test/{test_chicago.rb → chicago_test.rb} +11 -11
- data/test/deal_test.rb +225 -0
- data/test/{test_duplicate.rb → duplicate_test.rb} +9 -9
- data/test/helper.rb +3 -6
- data/test/play_test.rb +102 -0
- data/test/score_test.rb +215 -0
- data/test/{test_trick.rb → trick_test.rb} +10 -10
- metadata +80 -73
- data/Gemfile.lock +0 -12
- data/README.rdoc +0 -62
- data/test/test_bid.rb +0 -135
- data/test/test_bridge.rb +0 -62
- data/test/test_deal.rb +0 -225
- data/test/test_score.rb +0 -330
metadata
CHANGED
@@ -1,108 +1,115 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bridge
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 4
|
9
|
-
version: 0.1.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
12
|
-
-
|
13
|
-
-
|
6
|
+
authors:
|
7
|
+
- Jakub Kuźma
|
8
|
+
- Wojciech Wnętrzak
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-05-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: bundler
|
23
|
-
requirement:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
33
35
|
type: :development
|
34
36
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
-
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: Useful contract bridge utilities - deal generator, id to deal and deal
|
43
|
+
to id conversion
|
37
44
|
email: qoobaa+github@gmail.com
|
38
45
|
executables: []
|
39
|
-
|
40
46
|
extensions: []
|
41
|
-
|
42
47
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
48
|
+
files:
|
45
49
|
- .gitignore
|
50
|
+
- .travis.yml
|
46
51
|
- Gemfile
|
47
|
-
- Gemfile.lock
|
48
52
|
- LICENSE
|
49
|
-
- README.
|
53
|
+
- README.md
|
50
54
|
- Rakefile
|
51
55
|
- bridge.gemspec
|
52
56
|
- lib/bridge.rb
|
57
|
+
- lib/bridge/auction.rb
|
53
58
|
- lib/bridge/bid.rb
|
54
59
|
- lib/bridge/card.rb
|
55
60
|
- lib/bridge/constants.rb
|
56
61
|
- lib/bridge/deal.rb
|
62
|
+
- lib/bridge/play.rb
|
57
63
|
- lib/bridge/points.rb
|
58
64
|
- lib/bridge/points/chicago.rb
|
59
65
|
- lib/bridge/points/duplicate.rb
|
60
66
|
- lib/bridge/score.rb
|
61
67
|
- lib/bridge/trick.rb
|
62
68
|
- lib/bridge/version.rb
|
69
|
+
- test/auction_test.rb
|
70
|
+
- test/bid_test.rb
|
71
|
+
- test/bridge_test.rb
|
72
|
+
- test/card_test.rb
|
73
|
+
- test/chicago_test.rb
|
74
|
+
- test/deal_test.rb
|
75
|
+
- test/duplicate_test.rb
|
63
76
|
- test/helper.rb
|
64
|
-
- test/
|
65
|
-
- test/
|
66
|
-
- test/
|
67
|
-
|
68
|
-
|
69
|
-
-
|
70
|
-
|
71
|
-
- test/test_trick.rb
|
72
|
-
has_rdoc: true
|
73
|
-
homepage: http://github.com/qoobaa/bridge
|
74
|
-
licenses: []
|
75
|
-
|
77
|
+
- test/play_test.rb
|
78
|
+
- test/score_test.rb
|
79
|
+
- test/trick_test.rb
|
80
|
+
homepage: https://github.com/qoobaa/bridge
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
76
84
|
post_install_message:
|
77
85
|
rdoc_options: []
|
78
|
-
|
79
|
-
require_paths:
|
86
|
+
require_paths:
|
80
87
|
- lib
|
81
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
none: false
|
92
|
-
requirements:
|
93
|
-
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
segments:
|
96
|
-
- 1
|
97
|
-
- 3
|
98
|
-
- 6
|
99
|
-
version: 1.3.6
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.9.3
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
100
98
|
requirements: []
|
101
|
-
|
102
|
-
|
103
|
-
rubygems_version: 1.3.7
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.0.2
|
104
101
|
signing_key:
|
105
|
-
specification_version:
|
102
|
+
specification_version: 4
|
106
103
|
summary: Contract bridge utilities
|
107
|
-
test_files:
|
108
|
-
|
104
|
+
test_files:
|
105
|
+
- test/auction_test.rb
|
106
|
+
- test/bid_test.rb
|
107
|
+
- test/bridge_test.rb
|
108
|
+
- test/card_test.rb
|
109
|
+
- test/chicago_test.rb
|
110
|
+
- test/deal_test.rb
|
111
|
+
- test/duplicate_test.rb
|
112
|
+
- test/helper.rb
|
113
|
+
- test/play_test.rb
|
114
|
+
- test/score_test.rb
|
115
|
+
- test/trick_test.rb
|
data/Gemfile.lock
DELETED
data/README.rdoc
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
= bridge
|
2
|
-
|
3
|
-
Contract bridge utils.
|
4
|
-
|
5
|
-
== Bid
|
6
|
-
|
7
|
-
== Card
|
8
|
-
|
9
|
-
== Deal
|
10
|
-
|
11
|
-
== Trick
|
12
|
-
|
13
|
-
== Score
|
14
|
-
|
15
|
-
You can create Score object passing 3 arguments:
|
16
|
-
Bridge::Score.new(:contract => "6NTX", :vulnerable => true, :tricks => "=")
|
17
|
-
|
18
|
-
Arguments:
|
19
|
-
* :contract -- String, where first sign is level, second suit (C D H S NT) and optional double or redouble (X or XX)
|
20
|
-
* :vulnerable -- Boolean, declarer is vulnerable? (default is false)
|
21
|
-
* :tricks -- Integer or String, when Integer is passed it's number of tricks taken by declarer side, String can be relative to contract level i.e. "+1", "-2", "="
|
22
|
-
|
23
|
-
Methods:
|
24
|
-
* Score#made? -- Boolean
|
25
|
-
* Score#result -- Integer, relative to contract level i.e. -1 (one down), 1 (overtrick), 0 (contract made)
|
26
|
-
* Score#result_string -- String, relative to contract level i.e "+1", "=", "-3"
|
27
|
-
* Score#points -- Integer, calculated full value
|
28
|
-
|
29
|
-
You can also ask for all possible contracts finished with given points:
|
30
|
-
Bridge::Score.with_points(980)
|
31
|
-
#=> ["1NTX+4v", "2C/DX+4v", "6H/S="]
|
32
|
-
|
33
|
-
You can use regexp to check if contract with result is valid:
|
34
|
-
Bridge::Score::REGEXP
|
35
|
-
will match i.e.
|
36
|
-
"1NT=", "2SX+1", "6NTXX-2"
|
37
|
-
|
38
|
-
== Points
|
39
|
-
|
40
|
-
=== Chicago
|
41
|
-
|
42
|
-
You can calculate how many IMP points you won by:
|
43
|
-
Bridge::Points::Chicago.new(:hcp => 25, :points => 420, :vulnerable => false).imps
|
44
|
-
|
45
|
-
Arguments:
|
46
|
-
* :hcp -- Integer (range between 20 and 40), which means how many honour card points has side
|
47
|
-
* :vulnerable -- Boolean, side with given hcp is vulnerable?
|
48
|
-
* :points -- Integer, the result at the end of board (can be calculated by Bridge::Score)
|
49
|
-
|
50
|
-
== Note on Patches/Pull Requests
|
51
|
-
|
52
|
-
* Fork the project.
|
53
|
-
* Make your feature addition or bug fix.
|
54
|
-
* Add tests for it. This is important so I don't break it in a
|
55
|
-
future version unintentionally.
|
56
|
-
* Commit, do not mess with rakefile, version, or history.
|
57
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
58
|
-
* Send me a pull request. Bonus points for topic branches.
|
59
|
-
|
60
|
-
== Copyright
|
61
|
-
|
62
|
-
Copyright (c) 2010 Jakub Kuźma. See LICENSE for details.
|
data/test/test_bid.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestBid < Test::Unit::TestCase
|
4
|
-
test "pas is not a valid bid" do
|
5
|
-
assert_raises(ArgumentError) do
|
6
|
-
Bridge::Bid.new("pas")
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
test "case doesn't matter in bid" do
|
11
|
-
Bridge::Bid.new("pass")
|
12
|
-
Bridge::Bid.new("x")
|
13
|
-
Bridge::Bid.new("xx")
|
14
|
-
Bridge::Bid.new("1nt")
|
15
|
-
end
|
16
|
-
|
17
|
-
test "pass is a valid bid" do
|
18
|
-
bid = Bridge::Bid.new("PASS")
|
19
|
-
assert bid.pass?
|
20
|
-
assert_false bid.double?
|
21
|
-
assert_false bid.redouble?
|
22
|
-
assert_false bid.modifier?
|
23
|
-
assert_false bid.contract?
|
24
|
-
assert_nil bid.level
|
25
|
-
assert_nil bid.suit
|
26
|
-
end
|
27
|
-
|
28
|
-
test "double is a valid bid" do
|
29
|
-
bid = Bridge::Bid.new("X")
|
30
|
-
assert_false bid.pass?
|
31
|
-
assert bid.double?
|
32
|
-
assert_false bid.redouble?
|
33
|
-
assert bid.modifier?
|
34
|
-
assert_false bid.contract?
|
35
|
-
assert_nil bid.level
|
36
|
-
assert_nil bid.suit
|
37
|
-
end
|
38
|
-
|
39
|
-
test "redouble is a valid bid" do
|
40
|
-
bid = Bridge::Bid.new("XX")
|
41
|
-
assert_false bid.pass?
|
42
|
-
assert_false bid.double?
|
43
|
-
assert bid.redouble?
|
44
|
-
assert bid.modifier?
|
45
|
-
assert_false bid.contract?
|
46
|
-
assert_nil bid.level
|
47
|
-
assert_nil bid.suit
|
48
|
-
end
|
49
|
-
|
50
|
-
test "1H is a valid bid" do
|
51
|
-
bid = Bridge::Bid.new("1H")
|
52
|
-
assert_false bid.pass?
|
53
|
-
assert_false bid.double?
|
54
|
-
assert_false bid.redouble?
|
55
|
-
assert_false bid.modifier?
|
56
|
-
assert bid.contract?
|
57
|
-
assert_equal "1", bid.level
|
58
|
-
assert_equal "H", bid.suit
|
59
|
-
end
|
60
|
-
|
61
|
-
test "7NT is a valid bid" do
|
62
|
-
bid = Bridge::Bid.new("7NT")
|
63
|
-
assert_false bid.pass?
|
64
|
-
assert_false bid.double?
|
65
|
-
assert_false bid.redouble?
|
66
|
-
assert_false bid.modifier?
|
67
|
-
assert bid.contract?
|
68
|
-
assert_equal "7", bid.level
|
69
|
-
assert_equal "NT", bid.suit
|
70
|
-
end
|
71
|
-
|
72
|
-
test "7NT is greater than 1C" do
|
73
|
-
assert Bridge::Bid.new("7NT") > Bridge::Bid.new("1C")
|
74
|
-
assert_false Bridge::Bid.new("7NT") < Bridge::Bid.new("1C")
|
75
|
-
assert_false Bridge::Bid.new("7NT") == Bridge::Bid.new("1C")
|
76
|
-
end
|
77
|
-
|
78
|
-
test "1S is greater than 1H" do
|
79
|
-
assert Bridge::Bid.new("1S") > Bridge::Bid.new("1H")
|
80
|
-
assert_false Bridge::Bid.new("1S") < Bridge::Bid.new("1H")
|
81
|
-
assert_false Bridge::Bid.new("1S") == Bridge::Bid.new("1H")
|
82
|
-
end
|
83
|
-
|
84
|
-
test "comparison of PASS and 1S raises an error" do
|
85
|
-
assert_raises(ArgumentError) do
|
86
|
-
Bridge::Bid.new("PASS") > Bridge::Bid.new("1S")
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
test "comparison of X and PASS raises an error" do
|
91
|
-
assert_raises(ArgumentError) do
|
92
|
-
Bridge::Bid.new("X") > Bridge::Bid.new("PASS")
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
test "PASS and XX are not equal" do
|
97
|
-
assert_not_equal Bridge::Bid.new("PASS"), Bridge::Bid.new("XX")
|
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
|
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
|
127
|
-
|
128
|
-
test "6NT is a small slam" do
|
129
|
-
assert Bridge::Bid.new("6NT").small_slam?
|
130
|
-
end
|
131
|
-
|
132
|
-
test "7NT is a grand slam" do
|
133
|
-
assert Bridge::Bid.new("7NT").grand_slam?
|
134
|
-
end
|
135
|
-
end
|
data/test/test_bridge.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestBridge < Test::Unit::TestCase
|
4
|
-
test "negative number is not valid deal id" do
|
5
|
-
assert_false Bridge.deal_id?(-1)
|
6
|
-
end
|
7
|
-
|
8
|
-
test "number of possible bridge deals is not valid deal id" do
|
9
|
-
assert_false Bridge.deal_id?(Bridge::DEALS)
|
10
|
-
end
|
11
|
-
|
12
|
-
test "return partner of direction" do
|
13
|
-
assert_equal "N", Bridge.partner_of("S")
|
14
|
-
assert_equal "S", Bridge.partner_of("N")
|
15
|
-
assert_equal "E", Bridge.partner_of("W")
|
16
|
-
assert_equal "W", Bridge.partner_of("E")
|
17
|
-
end
|
18
|
-
|
19
|
-
test "return side of direction" do
|
20
|
-
assert_equal "NS", Bridge.side_of("S")
|
21
|
-
assert_equal "NS", Bridge.side_of("N")
|
22
|
-
assert_equal "EW", Bridge.side_of("W")
|
23
|
-
assert_equal "EW", Bridge.side_of("E")
|
24
|
-
end
|
25
|
-
|
26
|
-
test "return next direction" do
|
27
|
-
assert_equal "E", Bridge.next_direction("N")
|
28
|
-
assert_equal "S", Bridge.next_direction("E")
|
29
|
-
assert_equal "W", Bridge.next_direction("S")
|
30
|
-
assert_equal "N", Bridge.next_direction("W")
|
31
|
-
assert_equal "N", Bridge.next_direction(nil)
|
32
|
-
end
|
33
|
-
|
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)
|
61
|
-
end
|
62
|
-
end
|