cribbage 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +0 -4
- data/lib/cribbage/cli.rb +2 -0
- data/lib/cribbage/version.rb +1 -1
- data/lib/cribbage.rb +12 -8
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e815bde106e3529bbfc215373993536bb3b9f02a
|
|
4
|
+
data.tar.gz: c9a125f34f365a9058400b6345dad137c957a059
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2cbb03d76a9b9fe87cdb52662dfe83ee05e56d3f346076cc0b50522e4fd5f52e25f0df77608676f8b2935794a3be3a152f78deb908065522648f7d20263ca07e
|
|
7
|
+
data.tar.gz: d4b1125ef7baaf5047fdf3e924ba746128c3336e9ba1685e62f99d18cda67321e66c404c2fae2cbeb02af8f12d3a72f97b5e82eca361a50c84911d00b3cb0e6f
|
data/README.md
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
- Add suit unicode
|
|
2
|
-
- publish
|
|
3
|
-
- DRY
|
|
4
|
-
|
|
5
1
|
# Cribbage
|
|
6
2
|
|
|
7
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cribbage`. To experiment with that code, run `bin/console` for an interactive prompt.
|
data/lib/cribbage/cli.rb
CHANGED
data/lib/cribbage/version.rb
CHANGED
data/lib/cribbage.rb
CHANGED
|
@@ -22,6 +22,7 @@ module Cribbage
|
|
|
22
22
|
attr_accessor :index # index in a hand. Ie A = 0,
|
|
23
23
|
|
|
24
24
|
INDEX = %w(A 2 3 4 5 6 7 8 9 10 J Q K)
|
|
25
|
+
SUITS = {'H' => '♥', 'D' => '♦', 'C' => '♣', 'S' => '♠'}
|
|
25
26
|
|
|
26
27
|
def initialize(str)
|
|
27
28
|
raise "String cannot be blank!" if str.nil?
|
|
@@ -41,7 +42,7 @@ module Cribbage
|
|
|
41
42
|
end
|
|
42
43
|
|
|
43
44
|
def to_s
|
|
44
|
-
"#{@face_value}#{@suit}"
|
|
45
|
+
"[#{@face_value}#{SUITS[@suit]}]"
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
def compute_value(char)
|
|
@@ -100,26 +101,29 @@ module Cribbage
|
|
|
100
101
|
# Total Points: +17
|
|
101
102
|
# Fifteens (+8): (5 5 5), (5 J), (5 J), (5 K)
|
|
102
103
|
# Runs:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
ap "Total Points: #{total_score}"
|
|
104
|
+
#
|
|
105
|
+
$stdout.printf "\n\n"
|
|
106
|
+
$stdout.printf "%-3s %-21s %-10s\n\n", '', 'Hand:', starter_card.to_s + "" + players_cards.join('')
|
|
107
107
|
|
|
108
108
|
print_points :fifteens
|
|
109
109
|
print_points :runs
|
|
110
110
|
print_points :pairs
|
|
111
111
|
print_points :flush
|
|
112
112
|
print_points :nobs
|
|
113
|
-
end
|
|
114
113
|
|
|
114
|
+
$stdout.printf "\n%-3s %-10s %-10s\n", '', 'Total:', "+#{total_score}"
|
|
115
|
+
|
|
116
|
+
$stdout.printf "\n\n"
|
|
117
|
+
end
|
|
118
|
+
#
|
|
115
119
|
def print_points(key)
|
|
116
120
|
if @points[key].nil?
|
|
117
121
|
return false
|
|
118
122
|
end
|
|
119
123
|
cards = @points[key.to_sym][:cards] # should be array of array
|
|
120
|
-
str = cards.map { |c| "
|
|
124
|
+
str = cards.map { |c| "" + c.join('') + "" }.join ", "
|
|
121
125
|
title = key.to_s
|
|
122
|
-
|
|
126
|
+
$stdout.printf "%-3s %-10s %-10s %-10s\n", '', title, "+#{@points[key][:point_value]}", str
|
|
123
127
|
end
|
|
124
128
|
|
|
125
129
|
def print_cards(label, cards)
|