console-blackjack 1.1.0 → 1.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/Gemfile +1 -1
- data/Gemfile.lock +36 -31
- data/README.md +16 -0
- data/bj.txt +1 -1
- data/{console-blackjack-1.0.9.gem → console-blackjack-1.1.0.gem} +0 -0
- data/console-blackjack.gemspec +2 -2
- data/lib/blackjack/card.rb +5 -3
- data/lib/blackjack/dealer_hand.rb +21 -19
- data/lib/blackjack/hand.rb +1 -9
- data/lib/blackjack/menus.rb +6 -6
- data/lib/blackjack/player_hand.rb +10 -10
- data/lib/blackjack/player_hand_actions.rb +1 -1
- data/lib/blackjack/player_hand_draw.rb +6 -6
- data/lib/blackjack/utils.rb +1 -1
- data/lib/blackjack.rb +10 -10
- data/spec/factories/card_factory.rb +4 -0
- data/spec/factories/dealer_hand_factory.rb +1 -1
- data/spec/factories/player_hand_factory.rb +1 -1
- data/spec/lib/blackjack/card_spec.rb +36 -1
- data/spec/lib/blackjack/dealer_hand_spec.rb +30 -30
- data/spec/lib/blackjack/hand_spec.rb +2 -2
- data/spec/lib/blackjack/player_hand_spec.rb +16 -16
- data/spec/lib/blackjack/shoe_spec.rb +12 -13
- data/spec/lib/blackjack_spec.rb +28 -26
- metadata +5 -7
- data/console-blackjack-1.0.7.gem +0 -0
- data/console-blackjack-1.0.8.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1200cfab5226e842230a10d390124668b36ca0b889099cad6cf293d01311dbd6
|
4
|
+
data.tar.gz: ae0e5612e1bfc3c29cb22b07aaad391d12a7b477e86b2cdc4996b58480a12e4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28668e7ba8c3c412a6ab2ae0e5bc426157cba6beb3a29d76062ac2f311c2f952d642b3f86d84274a2b42cc967315ce4f3352c6de56638294ba534ef4dc60997f
|
7
|
+
data.tar.gz: 44224e3eaed8a420d86912093f4f9d9398c853f24a5fe464f8101eeee5b208345c1bb6f0c76c9a1c76c465a119885608330f402b141083809ed835ea1bd224dd
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,70 +1,75 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (7.0.2
|
4
|
+
activesupport (7.0.4.2)
|
5
5
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
6
|
i18n (>= 1.6, < 2)
|
7
7
|
minitest (>= 5.1)
|
8
8
|
tzinfo (~> 2.0)
|
9
9
|
ast (2.4.2)
|
10
10
|
coderay (1.1.3)
|
11
|
-
concurrent-ruby (1.
|
11
|
+
concurrent-ruby (1.2.0)
|
12
12
|
diff-lcs (1.5.0)
|
13
13
|
docile (1.4.0)
|
14
14
|
factory_bot (6.2.1)
|
15
15
|
activesupport (>= 5.0.0)
|
16
|
-
i18n (1.
|
16
|
+
i18n (1.12.0)
|
17
17
|
concurrent-ruby (~> 1.0)
|
18
|
+
json (2.6.3)
|
18
19
|
method_source (1.0.0)
|
19
|
-
minitest (5.
|
20
|
+
minitest (5.17.0)
|
20
21
|
parallel (1.22.1)
|
21
|
-
parser (3.
|
22
|
+
parser (3.2.0.0)
|
22
23
|
ast (~> 2.4.1)
|
23
|
-
pry (0.14.
|
24
|
+
pry (0.14.2)
|
24
25
|
coderay (~> 1.1)
|
25
26
|
method_source (~> 1.0)
|
26
27
|
rainbow (3.1.1)
|
27
28
|
rake (13.0.6)
|
28
|
-
regexp_parser (2.2
|
29
|
+
regexp_parser (2.6.2)
|
29
30
|
rexml (3.2.5)
|
30
|
-
rspec (3.
|
31
|
-
rspec-core (~> 3.
|
32
|
-
rspec-expectations (~> 3.
|
33
|
-
rspec-mocks (~> 3.
|
34
|
-
rspec-core (3.
|
35
|
-
rspec-support (~> 3.
|
36
|
-
rspec-expectations (3.
|
31
|
+
rspec (3.12.0)
|
32
|
+
rspec-core (~> 3.12.0)
|
33
|
+
rspec-expectations (~> 3.12.0)
|
34
|
+
rspec-mocks (~> 3.12.0)
|
35
|
+
rspec-core (3.12.1)
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-expectations (3.12.2)
|
37
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-mocks (3.
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-mocks (3.12.3)
|
40
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-support (3.
|
43
|
-
rubocop (1.
|
42
|
+
rspec-support (~> 3.12.0)
|
43
|
+
rspec-support (3.12.0)
|
44
|
+
rubocop (1.44.1)
|
45
|
+
json (~> 2.3)
|
44
46
|
parallel (~> 1.10)
|
45
|
-
parser (>= 3.
|
47
|
+
parser (>= 3.2.0.0)
|
46
48
|
rainbow (>= 2.2.2, < 4.0)
|
47
49
|
regexp_parser (>= 1.8, < 3.0)
|
48
|
-
rexml
|
49
|
-
rubocop-ast (>= 1.
|
50
|
+
rexml (>= 3.2.5, < 4.0)
|
51
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
50
52
|
ruby-progressbar (~> 1.7)
|
51
|
-
unicode-display_width (>=
|
52
|
-
rubocop-ast (1.
|
53
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.24.1)
|
53
55
|
parser (>= 3.1.1.0)
|
56
|
+
rubocop-capybara (2.17.0)
|
57
|
+
rubocop (~> 1.41)
|
54
58
|
rubocop-rake (0.6.0)
|
55
59
|
rubocop (~> 1.0)
|
56
|
-
rubocop-rspec (2.
|
57
|
-
rubocop (~> 1.
|
60
|
+
rubocop-rspec (2.18.1)
|
61
|
+
rubocop (~> 1.33)
|
62
|
+
rubocop-capybara (~> 2.17)
|
58
63
|
ruby-progressbar (1.11.0)
|
59
|
-
simplecov (0.
|
64
|
+
simplecov (0.22.0)
|
60
65
|
docile (~> 1.1)
|
61
66
|
simplecov-html (~> 0.11)
|
62
67
|
simplecov_json_formatter (~> 0.1)
|
63
68
|
simplecov-html (0.12.3)
|
64
69
|
simplecov_json_formatter (0.1.4)
|
65
|
-
tzinfo (2.0.
|
70
|
+
tzinfo (2.0.6)
|
66
71
|
concurrent-ruby (~> 1.0)
|
67
|
-
unicode-display_width (2.
|
72
|
+
unicode-display_width (2.4.2)
|
68
73
|
|
69
74
|
PLATFORMS
|
70
75
|
ruby
|
@@ -80,7 +85,7 @@ DEPENDENCIES
|
|
80
85
|
simplecov
|
81
86
|
|
82
87
|
RUBY VERSION
|
83
|
-
ruby 3.
|
88
|
+
ruby 3.1.2p20
|
84
89
|
|
85
90
|
BUNDLED WITH
|
86
|
-
2.
|
91
|
+
2.3.15
|
data/README.md
CHANGED
@@ -22,3 +22,19 @@ Run:
|
|
22
22
|
## License
|
23
23
|
|
24
24
|
[](https://github.com/gdonald/console-blackjack-ruby/blob/master/LICENSE)
|
25
|
+
|
26
|
+
## Alternative Implementations:
|
27
|
+
|
28
|
+
I've written Blackjack in several other languages:
|
29
|
+
|
30
|
+
- [Rust](https://github.com/gdonald/console-blackjack-rust)
|
31
|
+
- [Typescript](https://github.com/gdonald/blackjack-js)
|
32
|
+
- [Raku](https://github.com/gdonald/Console-Blackjack)
|
33
|
+
- [Perl](https://github.com/gdonald/console-blackjack-perl)
|
34
|
+
- [C](https://github.com/gdonald/blackjack-c)
|
35
|
+
- [C++](https://github.com/gdonald/blackjack-cpp)
|
36
|
+
- [Crystal](https://github.com/gdonald/blackjack-cr)
|
37
|
+
- [Go](https://github.com/gdonald/blackjack-go)
|
38
|
+
- [Elixir](https://github.com/gdonald/blackjack-ex)
|
39
|
+
- [Python](https://github.com/gdonald/blackjack-py)
|
40
|
+
- [C with SDL](https://github.com/gdonald/blackjack-c-sdl)
|
data/bj.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1|1|1|
|
1
|
+
1|1|1|11000|500
|
Binary file
|
data/console-blackjack.gemspec
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
require 'rake'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.required_ruby_version = '>= 3.
|
6
|
+
spec.required_ruby_version = '>= 3.1'
|
7
7
|
spec.name = 'console-blackjack'
|
8
|
-
spec.version = '1.1.
|
8
|
+
spec.version = '1.1.1'
|
9
9
|
spec.summary = 'Console Blackjack'
|
10
10
|
spec.description = 'Blackjack for your console, full version.'
|
11
11
|
spec.author = 'Greg Donald'
|
data/lib/blackjack/card.rb
CHANGED
@@ -24,9 +24,11 @@ class Card
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.value(card, count_method, total)
|
27
|
-
value = card.value
|
28
|
-
|
29
|
-
|
27
|
+
value = card.value.succ
|
28
|
+
value = 10 if value > 9
|
29
|
+
return 11 if value == 1 && count_method == :soft && total < 11
|
30
|
+
|
31
|
+
value
|
30
32
|
end
|
31
33
|
|
32
34
|
def self.faces
|
@@ -3,33 +3,23 @@
|
|
3
3
|
require_relative 'hand'
|
4
4
|
|
5
5
|
class DealerHand < Hand
|
6
|
-
attr_accessor :blackjack, :
|
6
|
+
attr_accessor :blackjack, :hide_first_card
|
7
7
|
|
8
8
|
def initialize(blackjack)
|
9
9
|
super(blackjack)
|
10
|
-
@
|
10
|
+
@hide_first_card = true
|
11
11
|
end
|
12
12
|
|
13
13
|
def value(count_method)
|
14
|
-
total =
|
14
|
+
total = value_for_method(count_method)
|
15
15
|
|
16
|
-
if count_method ==
|
17
|
-
value(
|
16
|
+
if count_method == :soft && total > 21
|
17
|
+
value(:hard)
|
18
18
|
else
|
19
19
|
total
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def total_card_value(count_method)
|
24
|
-
total = 0
|
25
|
-
cards.each_with_index do |card, index|
|
26
|
-
next if index == 1 && hide_down_card
|
27
|
-
|
28
|
-
total += Card.value(card, count_method, total)
|
29
|
-
end
|
30
|
-
total
|
31
|
-
end
|
32
|
-
|
33
23
|
def upcard_is_ace?
|
34
24
|
cards.first.ace?
|
35
25
|
end
|
@@ -37,10 +27,10 @@ class DealerHand < Hand
|
|
37
27
|
def draw
|
38
28
|
out = String.new(' ')
|
39
29
|
cards.each_with_index do |card, index|
|
40
|
-
out << (index
|
30
|
+
out << (index.zero? && hide_first_card ? Card.new(blackjack, 13, 0) : card).to_s
|
41
31
|
out << ' '
|
42
32
|
end
|
43
|
-
out << ' ⇒ ' << value(
|
33
|
+
out << ' ⇒ ' << value(:soft).to_s
|
44
34
|
end
|
45
35
|
|
46
36
|
def deal_required_cards
|
@@ -52,14 +42,26 @@ class DealerHand < Hand
|
|
52
42
|
end
|
53
43
|
|
54
44
|
def both_values
|
55
|
-
[value(
|
45
|
+
[value(:soft), value(:hard)]
|
56
46
|
end
|
57
47
|
|
58
48
|
def play
|
59
49
|
playing = blackjack.need_to_play_dealer_hand?
|
60
|
-
self.
|
50
|
+
self.hide_first_card = false if blackjack? || playing
|
61
51
|
deal_required_cards if playing
|
62
52
|
self.played = true
|
63
53
|
blackjack.pay_hands
|
64
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def value_for_method(count_method)
|
59
|
+
total = 0
|
60
|
+
cards.each_with_index do |card, index|
|
61
|
+
next if index.zero? && hide_first_card
|
62
|
+
|
63
|
+
total += Card.value(card, count_method, total)
|
64
|
+
end
|
65
|
+
total
|
66
|
+
end
|
65
67
|
end
|
data/lib/blackjack/hand.rb
CHANGED
@@ -1,13 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
UNKNOWN = 0
|
4
|
-
WON = 1
|
5
|
-
LOST = 2
|
6
|
-
PUSH = 3
|
7
|
-
|
8
|
-
SOFT = 4
|
9
|
-
HARD = 5
|
10
|
-
|
11
3
|
class Hand
|
12
4
|
attr_accessor :cards, :blackjack, :played
|
13
5
|
|
@@ -18,7 +10,7 @@ class Hand
|
|
18
10
|
end
|
19
11
|
|
20
12
|
def busted?
|
21
|
-
value(
|
13
|
+
value(:soft) > 21
|
22
14
|
end
|
23
15
|
|
24
16
|
def deal_card
|
data/lib/blackjack/menus.rb
CHANGED
@@ -4,7 +4,7 @@ module Menus
|
|
4
4
|
def draw_game_options
|
5
5
|
puts ' (N) Number of Decks (T) Deck Type (F) Face Type (B) Back'
|
6
6
|
loop do
|
7
|
-
c = Blackjack.getc
|
7
|
+
c = Blackjack.getc($stdin)
|
8
8
|
case c
|
9
9
|
when 'n'
|
10
10
|
clear_draw_hands_new_num_decks
|
@@ -26,7 +26,7 @@ module Menus
|
|
26
26
|
def new_deck_type
|
27
27
|
puts ' (1) Regular (2) Aces (3) Jacks (4) Aces & Jacks (5) Sevens (6) Eights'
|
28
28
|
loop do
|
29
|
-
c = Blackjack.getc.to_i
|
29
|
+
c = Blackjack.getc($stdin).to_i
|
30
30
|
case c
|
31
31
|
when (1..6)
|
32
32
|
self.deck_type = c
|
@@ -42,7 +42,7 @@ module Menus
|
|
42
42
|
def new_face_type
|
43
43
|
puts ' (1) 🂡 (2) A♠'
|
44
44
|
loop do
|
45
|
-
c = Blackjack.getc.to_i
|
45
|
+
c = Blackjack.getc($stdin).to_i
|
46
46
|
case c
|
47
47
|
when (1..2)
|
48
48
|
self.face_type = c
|
@@ -57,7 +57,7 @@ module Menus
|
|
57
57
|
def ask_insurance
|
58
58
|
puts ' Insurance? (Y) Yes (N) No'
|
59
59
|
loop do
|
60
|
-
c = Blackjack.getc
|
60
|
+
c = Blackjack.getc($stdin)
|
61
61
|
case c
|
62
62
|
when 'y'
|
63
63
|
insure_hand
|
@@ -72,12 +72,12 @@ module Menus
|
|
72
72
|
|
73
73
|
def draw_bet_options
|
74
74
|
puts ' (D) Deal Hand (B) Change Bet (O) Options (Q) Quit'
|
75
|
-
c = Blackjack.getc
|
75
|
+
c = Blackjack.getc($stdin)
|
76
76
|
case c
|
77
77
|
when 'd'
|
78
78
|
deal_new_hand
|
79
79
|
when 'b'
|
80
|
-
new_bet
|
80
|
+
new_bet($stdin)
|
81
81
|
when 'o'
|
82
82
|
clear_draw_hands_game_options
|
83
83
|
when 'q'
|
@@ -15,7 +15,7 @@ class PlayerHand < Hand
|
|
15
15
|
def initialize(blackjack, bet)
|
16
16
|
super(blackjack)
|
17
17
|
@bet = bet
|
18
|
-
@status =
|
18
|
+
@status = :unknown
|
19
19
|
@payed = false
|
20
20
|
@stood = false
|
21
21
|
end
|
@@ -24,14 +24,14 @@ class PlayerHand < Hand
|
|
24
24
|
return if payed
|
25
25
|
|
26
26
|
self.payed = true
|
27
|
-
player_hand_value = value(
|
27
|
+
player_hand_value = value(:soft)
|
28
28
|
|
29
29
|
if player_hand_won?(dealer_busted, dealer_hand_value, player_hand_value)
|
30
30
|
pay_won_hand
|
31
31
|
elsif player_hand_lost?(dealer_hand_value, player_hand_value)
|
32
32
|
collect_lost_hand
|
33
33
|
else
|
34
|
-
self.status =
|
34
|
+
self.status = :push
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -45,20 +45,20 @@ class PlayerHand < Hand
|
|
45
45
|
|
46
46
|
def collect_lost_hand
|
47
47
|
blackjack.money -= bet
|
48
|
-
self.status =
|
48
|
+
self.status = :lost
|
49
49
|
end
|
50
50
|
|
51
51
|
def pay_won_hand
|
52
52
|
self.bet *= 1.5 if blackjack?
|
53
53
|
blackjack.money += bet
|
54
|
-
self.status =
|
54
|
+
self.status = :won
|
55
55
|
end
|
56
56
|
|
57
57
|
def value(count_method)
|
58
58
|
total = cards.inject(0) { |sum, card| sum + Card.value(card, count_method, sum) }
|
59
59
|
|
60
|
-
if count_method ==
|
61
|
-
value(
|
60
|
+
if count_method == :soft && total > 21
|
61
|
+
value(:hard)
|
62
62
|
else
|
63
63
|
total
|
64
64
|
end
|
@@ -74,12 +74,12 @@ class PlayerHand < Hand
|
|
74
74
|
|
75
75
|
def collect_busted_hand
|
76
76
|
self.payed = true
|
77
|
-
self.status =
|
77
|
+
self.status = :lost
|
78
78
|
blackjack.money -= bet
|
79
79
|
end
|
80
80
|
|
81
81
|
def no_more_actions?
|
82
|
-
played || stood || blackjack? || busted? || value(
|
82
|
+
played || stood || blackjack? || busted? || value(:soft) == 21 || value(:hard) == 21
|
83
83
|
end
|
84
84
|
|
85
85
|
def process
|
@@ -92,7 +92,7 @@ class PlayerHand < Hand
|
|
92
92
|
|
93
93
|
def action?
|
94
94
|
draw_actions
|
95
|
-
c = Blackjack.getc
|
95
|
+
c = Blackjack.getc($stdin)
|
96
96
|
case c
|
97
97
|
when 'h'
|
98
98
|
hit
|
@@ -12,11 +12,11 @@ module PlayerHandDraw
|
|
12
12
|
|
13
13
|
def draw_status
|
14
14
|
case status
|
15
|
-
when
|
15
|
+
when :lost
|
16
16
|
draw_lost_str
|
17
|
-
when
|
17
|
+
when :won
|
18
18
|
draw_won_str
|
19
|
-
when
|
19
|
+
when :push
|
20
20
|
'Push'
|
21
21
|
else
|
22
22
|
''
|
@@ -33,8 +33,8 @@ module PlayerHandDraw
|
|
33
33
|
|
34
34
|
def draw_money(index)
|
35
35
|
out = String.new('')
|
36
|
-
out << '-' if status ==
|
37
|
-
out << '+' if status ==
|
36
|
+
out << '-' if status == :lost
|
37
|
+
out << '+' if status == :won
|
38
38
|
out << '$' << Format.money(bet / 100.0)
|
39
39
|
out << ' ⇐' if !played && index == blackjack.current_hand
|
40
40
|
out << ' '
|
@@ -44,7 +44,7 @@ module PlayerHandDraw
|
|
44
44
|
def draw_cards
|
45
45
|
out = String.new('')
|
46
46
|
out << cards.map { |card| "#{card} " }.join
|
47
|
-
out << ' ⇒ ' << value(
|
47
|
+
out << ' ⇒ ' << value(:soft).to_s << ' '
|
48
48
|
out
|
49
49
|
end
|
50
50
|
end
|
data/lib/blackjack/utils.rb
CHANGED
data/lib/blackjack.rb
CHANGED
@@ -63,7 +63,7 @@ class Blackjack
|
|
63
63
|
draw_hands
|
64
64
|
ask_insurance
|
65
65
|
elsif player_hand.done?
|
66
|
-
dealer_hand.
|
66
|
+
dealer_hand.hide_first_card = false
|
67
67
|
pay_hands
|
68
68
|
draw_hands
|
69
69
|
draw_bet_options
|
@@ -97,7 +97,7 @@ class Blackjack
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def pay_hands
|
100
|
-
dealer_hand_value = dealer_hand.value(
|
100
|
+
dealer_hand_value = dealer_hand.value(:soft)
|
101
101
|
dealer_busted = dealer_hand.busted?
|
102
102
|
|
103
103
|
player_hands.each do |player_hand|
|
@@ -133,23 +133,23 @@ class Blackjack
|
|
133
133
|
out
|
134
134
|
end
|
135
135
|
|
136
|
-
def new_bet
|
136
|
+
def new_bet(input)
|
137
137
|
clear
|
138
138
|
draw_hands
|
139
139
|
|
140
140
|
puts " Current Bet: $#{Format.money(current_bet / 100)}\n"
|
141
141
|
print ' Enter New Bet: $'
|
142
142
|
|
143
|
-
self.current_bet =
|
143
|
+
self.current_bet = input.gets.to_i * 100
|
144
144
|
|
145
145
|
normalize_current_bet
|
146
146
|
deal_new_hand
|
147
147
|
end
|
148
148
|
|
149
|
-
def new_num_decks
|
149
|
+
def new_num_decks(input)
|
150
150
|
puts " Number Of Decks: #{num_decks}"
|
151
151
|
print ' New Number Of Decks (1-8): '
|
152
|
-
self.num_decks =
|
152
|
+
self.num_decks = input.gets.to_i
|
153
153
|
|
154
154
|
normalize_num_decks
|
155
155
|
clear_draw_hands_game_options
|
@@ -165,7 +165,7 @@ class Blackjack
|
|
165
165
|
player_hand.bet /= 2
|
166
166
|
player_hand.played = true
|
167
167
|
player_hand.payed = true
|
168
|
-
player_hand.status =
|
168
|
+
player_hand.status = :lost
|
169
169
|
|
170
170
|
self.money -= player_hand.bet
|
171
171
|
|
@@ -175,7 +175,7 @@ class Blackjack
|
|
175
175
|
|
176
176
|
def no_insurance
|
177
177
|
if dealer_hand.blackjack?
|
178
|
-
dealer_hand.
|
178
|
+
dealer_hand.hide_first_card = false
|
179
179
|
|
180
180
|
pay_hands
|
181
181
|
draw_hands
|
@@ -206,10 +206,10 @@ class Blackjack
|
|
206
206
|
self.current_bet = money if current_bet > money
|
207
207
|
end
|
208
208
|
|
209
|
-
def self.getc
|
209
|
+
def self.getc(input)
|
210
210
|
begin
|
211
211
|
system('stty raw -echo')
|
212
|
-
c =
|
212
|
+
c = input.getc
|
213
213
|
ensure
|
214
214
|
system('stty -raw echo')
|
215
215
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
RSpec.describe Card do
|
4
4
|
let(:blackjack) { build(:blackjack) }
|
5
|
-
let(:card) { build(:card, blackjack:
|
5
|
+
let(:card) { build(:card, blackjack:) }
|
6
6
|
|
7
7
|
describe '.new' do
|
8
8
|
it 'creates a card' do
|
@@ -63,4 +63,39 @@ RSpec.describe Card do
|
|
63
63
|
expect(described_class.faces[4][3]).to eq('🃕')
|
64
64
|
end
|
65
65
|
end
|
66
|
+
|
67
|
+
describe '.value' do
|
68
|
+
let(:card) { build(:card, blackjack:) }
|
69
|
+
let(:count_method) { :soft }
|
70
|
+
let(:total) { 0 }
|
71
|
+
let(:result) { described_class.value(card, count_method, total) }
|
72
|
+
|
73
|
+
it 'returns 11' do
|
74
|
+
expect(result).to eq(11)
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'with a hard count' do
|
78
|
+
let(:count_method) { :hard }
|
79
|
+
|
80
|
+
it 'returns 1' do
|
81
|
+
expect(result).to eq(1)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with a total of 11' do
|
86
|
+
let(:total) { 11 }
|
87
|
+
|
88
|
+
it 'returns 1' do
|
89
|
+
expect(result).to eq(1)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'with a face card' do
|
94
|
+
let(:card) { build(:card, :jack, blackjack:) }
|
95
|
+
|
96
|
+
it 'returns 10' do
|
97
|
+
expect(result).to eq(10)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
66
101
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
RSpec.describe DealerHand do
|
4
4
|
let(:shoe) { build(:shoe, :new_regular) }
|
5
5
|
let(:blackjack) { build(:blackjack) }
|
6
|
-
let(:dealer_hand) { build(:dealer_hand, blackjack:
|
7
|
-
let(:ace) { build(:card, :ace, blackjack:
|
8
|
-
let(:ten) { build(:card, :ten, blackjack:
|
6
|
+
let(:dealer_hand) { build(:dealer_hand, blackjack:) }
|
7
|
+
let(:ace) { build(:card, :ace, blackjack:) }
|
8
|
+
let(:ten) { build(:card, :ten, blackjack:) }
|
9
9
|
|
10
10
|
describe '.new' do
|
11
11
|
it 'creates a dealer_hand' do
|
@@ -24,7 +24,7 @@ RSpec.describe DealerHand do
|
|
24
24
|
|
25
25
|
it 'returns true' do
|
26
26
|
dealer_hand.cards << ten << ten << ten
|
27
|
-
dealer_hand.
|
27
|
+
dealer_hand.hide_first_card = false
|
28
28
|
expect(dealer_hand).to be_busted
|
29
29
|
end
|
30
30
|
end
|
@@ -32,31 +32,31 @@ RSpec.describe DealerHand do
|
|
32
32
|
describe '#value' do
|
33
33
|
context 'with a soft count' do
|
34
34
|
it 'returns 10' do
|
35
|
-
dealer_hand.cards <<
|
36
|
-
expect(dealer_hand.value(
|
35
|
+
dealer_hand.cards << ace << ten
|
36
|
+
expect(dealer_hand.value(:soft)).to eq(10)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'returns 11' do
|
40
|
-
dealer_hand.cards <<
|
41
|
-
expect(dealer_hand.value(
|
40
|
+
dealer_hand.cards << ten << ace
|
41
|
+
expect(dealer_hand.value(:soft)).to eq(11)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'returns 12' do
|
45
45
|
dealer_hand.cards << ten << ace << ace
|
46
|
-
dealer_hand.
|
47
|
-
expect(dealer_hand.value(
|
46
|
+
dealer_hand.hide_first_card = false
|
47
|
+
expect(dealer_hand.value(:soft)).to eq(12)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
context 'with a hard count' do
|
52
52
|
it 'returns 10' do
|
53
|
-
dealer_hand.cards <<
|
54
|
-
expect(dealer_hand.value(
|
53
|
+
dealer_hand.cards << ace << ten
|
54
|
+
expect(dealer_hand.value(:hard)).to eq(10)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'returns 1' do
|
58
|
-
dealer_hand.cards <<
|
59
|
-
expect(dealer_hand.value(
|
58
|
+
dealer_hand.cards << ten << ace
|
59
|
+
expect(dealer_hand.value(:hard)).to eq(1)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -74,21 +74,21 @@ RSpec.describe DealerHand do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
describe '#draw' do
|
77
|
-
it 'returns " 🂪
|
78
|
-
dealer_hand.cards <<
|
79
|
-
expected = ' 🂪
|
77
|
+
it 'returns " 🂠 🂪 ⇒ 10"' do
|
78
|
+
dealer_hand.cards << ace << ten
|
79
|
+
expected = ' 🂠 🂪 ⇒ 10'
|
80
80
|
expect(dealer_hand.draw).to eq(expected)
|
81
81
|
end
|
82
82
|
|
83
|
-
it 'returns " 🂡
|
84
|
-
dealer_hand.cards <<
|
85
|
-
expected = ' 🂡
|
83
|
+
it 'returns " 🂠 🂡 ⇒ 11"' do
|
84
|
+
dealer_hand.cards << ten << ace
|
85
|
+
expected = ' 🂠 🂡 ⇒ 11'
|
86
86
|
expect(dealer_hand.draw).to eq(expected)
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'returns " 🂡 🂪 ⇒ 21"' do
|
90
90
|
dealer_hand.cards << ace << ten
|
91
|
-
dealer_hand.
|
91
|
+
dealer_hand.hide_first_card = false
|
92
92
|
expected = ' 🂡 🂪 ⇒ 21'
|
93
93
|
expect(dealer_hand.draw).to eq(expected)
|
94
94
|
end
|
@@ -97,30 +97,30 @@ RSpec.describe DealerHand do
|
|
97
97
|
describe '#both_values' do
|
98
98
|
context 'with a soft count' do
|
99
99
|
it 'returns [10, 10]' do
|
100
|
-
dealer_hand.cards <<
|
100
|
+
dealer_hand.cards << ace << ten
|
101
101
|
expect(dealer_hand.both_values).to eq([10, 10])
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'returns [11, 1]' do
|
105
|
-
dealer_hand.cards <<
|
105
|
+
dealer_hand.cards << ten << ace
|
106
106
|
expect(dealer_hand.both_values).to eq([11, 1])
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'returns [12, 12]' do
|
110
110
|
dealer_hand.cards << ten << ace << ace
|
111
|
-
dealer_hand.
|
111
|
+
dealer_hand.hide_first_card = false
|
112
112
|
expect(dealer_hand.both_values).to eq([12, 12])
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
context 'with a hard count' do
|
117
117
|
it 'returns [10, 10]' do
|
118
|
-
dealer_hand.cards <<
|
118
|
+
dealer_hand.cards << ace << ten
|
119
119
|
expect(dealer_hand.both_values).to eq([10, 10])
|
120
120
|
end
|
121
121
|
|
122
122
|
it 'returns [11, 1]' do
|
123
|
-
dealer_hand.cards <<
|
123
|
+
dealer_hand.cards << ten << ace
|
124
124
|
expect(dealer_hand.both_values).to eq([11, 1])
|
125
125
|
end
|
126
126
|
end
|
@@ -172,13 +172,13 @@ RSpec.describe DealerHand do
|
|
172
172
|
it 'hides down card when no blackjack' do
|
173
173
|
allow(dealer_hand).to receive(:blackjack?).and_return(false)
|
174
174
|
dealer_hand.play
|
175
|
-
expect(dealer_hand.
|
175
|
+
expect(dealer_hand.hide_first_card).to be_truthy
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'shows down card if blackjack' do
|
179
179
|
allow(dealer_hand).to receive(:blackjack?).and_return(true)
|
180
180
|
dealer_hand.play
|
181
|
-
expect(dealer_hand.
|
181
|
+
expect(dealer_hand.hide_first_card).to be_falsey
|
182
182
|
end
|
183
183
|
|
184
184
|
it 'does not deal any cards' do
|
@@ -197,13 +197,13 @@ RSpec.describe DealerHand do
|
|
197
197
|
it 'shows down card if not blackjack' do
|
198
198
|
allow(dealer_hand).to receive(:blackjack?).and_return(false)
|
199
199
|
dealer_hand.play
|
200
|
-
expect(dealer_hand.
|
200
|
+
expect(dealer_hand.hide_first_card).to be_falsey
|
201
201
|
end
|
202
202
|
|
203
203
|
it 'shows down card if blackjack' do
|
204
204
|
allow(dealer_hand).to receive(:blackjack?).and_return(true)
|
205
205
|
dealer_hand.play
|
206
|
-
expect(dealer_hand.
|
206
|
+
expect(dealer_hand.hide_first_card).to be_falsey
|
207
207
|
end
|
208
208
|
|
209
209
|
it 'deals required cards' do
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
RSpec.describe Hand do
|
4
4
|
let(:shoe) { build(:shoe, :new_regular) }
|
5
|
-
let(:blackjack) { build(:blackjack, shoe:
|
6
|
-
let(:hand) { build(:hand, blackjack:
|
5
|
+
let(:blackjack) { build(:blackjack, shoe:) }
|
6
|
+
let(:hand) { build(:hand, blackjack:) }
|
7
7
|
|
8
8
|
describe '.new' do
|
9
9
|
it 'creates a hand' do
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
RSpec.describe PlayerHand do
|
4
4
|
let(:blackjack) { build(:blackjack, shoe: build(:shoe, :new_regular)) }
|
5
|
-
let(:player_hand) { build(:player_hand, blackjack:
|
6
|
-
let(:dealer_hand) { build(:dealer_hand, blackjack:
|
7
|
-
let(:ace) { build(:card, :ace, blackjack:
|
8
|
-
let(:ten) { build(:card, :ten, blackjack:
|
5
|
+
let(:player_hand) { build(:player_hand, blackjack:) }
|
6
|
+
let(:dealer_hand) { build(:dealer_hand, blackjack:) }
|
7
|
+
let(:ace) { build(:card, :ace, blackjack:) }
|
8
|
+
let(:ten) { build(:card, :ten, blackjack:) }
|
9
9
|
|
10
10
|
describe '.new' do
|
11
11
|
it 'creates a player_hand' do
|
@@ -21,7 +21,7 @@ RSpec.describe PlayerHand do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'has an unknown status' do
|
24
|
-
expect(player_hand.status).to eq(
|
24
|
+
expect(player_hand.status).to eq(:unknown)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'has not been payed' do
|
@@ -38,21 +38,21 @@ RSpec.describe PlayerHand do
|
|
38
38
|
|
39
39
|
it 'draws a lost hand' do
|
40
40
|
player_hand.cards << ace << ace
|
41
|
-
player_hand.status =
|
41
|
+
player_hand.status = :lost
|
42
42
|
expected = " 🂡 🂡 ⇒ 12 -$5.00 Lose!\n\n"
|
43
43
|
expect(player_hand.draw(1)).to eq(expected)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'draws a won hand' do
|
47
47
|
player_hand.cards << ace << ace
|
48
|
-
player_hand.status =
|
48
|
+
player_hand.status = :won
|
49
49
|
expected = " 🂡 🂡 ⇒ 12 +$5.00 Won!\n\n"
|
50
50
|
expect(player_hand.draw(1)).to eq(expected)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'draws a push hand' do
|
54
54
|
player_hand.cards << ace << ace
|
55
|
-
player_hand.status =
|
55
|
+
player_hand.status = :push
|
56
56
|
expected = " 🂡 🂡 ⇒ 12 $5.00 Push\n\n"
|
57
57
|
expect(player_hand.draw(1)).to eq(expected)
|
58
58
|
end
|
@@ -73,19 +73,19 @@ RSpec.describe PlayerHand do
|
|
73
73
|
context 'with a soft count' do
|
74
74
|
it 'returns 21' do
|
75
75
|
player_hand.cards << ten << ace
|
76
|
-
expect(player_hand.value(
|
76
|
+
expect(player_hand.value(:soft)).to eq(21)
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'returns 12' do
|
80
80
|
player_hand.cards << ten << ace << ace
|
81
|
-
expect(player_hand.value(
|
81
|
+
expect(player_hand.value(:soft)).to eq(12)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
context 'with a hard count' do
|
86
86
|
it 'returns 11' do
|
87
87
|
player_hand.cards << ten << ace
|
88
|
-
expect(player_hand.value(
|
88
|
+
expect(player_hand.value(:hard)).to eq(11)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -328,7 +328,7 @@ RSpec.describe PlayerHand do
|
|
328
328
|
end
|
329
329
|
|
330
330
|
context 'when done' do
|
331
|
-
let(:dealer_hand) { build(:dealer_hand, blackjack:
|
331
|
+
let(:dealer_hand) { build(:dealer_hand, blackjack:) }
|
332
332
|
|
333
333
|
before do
|
334
334
|
allow(player_hand).to receive(:done?).and_return(true)
|
@@ -560,7 +560,7 @@ RSpec.describe PlayerHand do
|
|
560
560
|
context 'when dealer busted' do
|
561
561
|
it 'hand is won' do
|
562
562
|
player_hand.pay(22, true)
|
563
|
-
expect(player_hand.status).to eq(
|
563
|
+
expect(player_hand.status).to eq(:won)
|
564
564
|
end
|
565
565
|
end
|
566
566
|
|
@@ -574,7 +574,7 @@ RSpec.describe PlayerHand do
|
|
574
574
|
it 'hand status is won' do
|
575
575
|
player_hand.cards << ten << ten
|
576
576
|
player_hand.pay(18, false)
|
577
|
-
expect(player_hand.status).to eq(
|
577
|
+
expect(player_hand.status).to eq(:won)
|
578
578
|
end
|
579
579
|
|
580
580
|
it 'blackjack money is increased by player hand bet' do
|
@@ -592,7 +592,7 @@ RSpec.describe PlayerHand do
|
|
592
592
|
it 'hand is lost' do
|
593
593
|
player_hand.cards << ten << build(:card, :seven)
|
594
594
|
player_hand.pay(18, false)
|
595
|
-
expect(player_hand.status).to eq(
|
595
|
+
expect(player_hand.status).to eq(:lost)
|
596
596
|
end
|
597
597
|
|
598
598
|
it 'blackjack money is descreased by player hand bet' do
|
@@ -604,7 +604,7 @@ RSpec.describe PlayerHand do
|
|
604
604
|
it 'hand is push' do
|
605
605
|
player_hand.cards << ten << build(:card, :seven)
|
606
606
|
player_hand.pay(17, false)
|
607
|
-
expect(player_hand.status).to eq(
|
607
|
+
expect(player_hand.status).to eq(:push)
|
608
608
|
end
|
609
609
|
|
610
610
|
it 'blackjack money is unaltered' do
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
RSpec.describe Shoe do
|
4
4
|
let(:blackjack) { build(:blackjack) }
|
5
|
-
let(:shoe) { build(:shoe, blackjack:
|
5
|
+
let(:shoe) { build(:shoe, blackjack:) }
|
6
6
|
|
7
7
|
describe 'CARDS_PER_DECK' do
|
8
8
|
it 'returns 52' do
|
@@ -28,7 +28,7 @@ RSpec.describe Shoe do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'with a new regular shoe' do
|
31
|
-
let(:shoe) { build(:shoe, :new_regular, blackjack:
|
31
|
+
let(:shoe) { build(:shoe, :new_regular, blackjack:) }
|
32
32
|
|
33
33
|
it 'returns false' do
|
34
34
|
expect(shoe).to_not be_needs_to_shuffle
|
@@ -36,7 +36,7 @@ RSpec.describe Shoe do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
context 'with 42 cards being dealt' do
|
39
|
-
let(:shoe) { build(:shoe, :new_regular, blackjack:
|
39
|
+
let(:shoe) { build(:shoe, :new_regular, blackjack:) }
|
40
40
|
|
41
41
|
before do
|
42
42
|
42.times { shoe.next_card }
|
@@ -49,7 +49,7 @@ RSpec.describe Shoe do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
describe '#shuffle' do
|
52
|
-
let(:shoe) { build(:shoe, blackjack:
|
52
|
+
let(:shoe) { build(:shoe, blackjack:) }
|
53
53
|
|
54
54
|
it 'calls shuffle' do
|
55
55
|
cards = instance_double(Array)
|
@@ -61,7 +61,7 @@ RSpec.describe Shoe do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '#new_regular' do
|
64
|
-
let(:shoe) { build(:shoe, blackjack:
|
64
|
+
let(:shoe) { build(:shoe, blackjack:) }
|
65
65
|
|
66
66
|
it 'creates a shoe' do
|
67
67
|
shoe.new_regular
|
@@ -76,7 +76,7 @@ RSpec.describe Shoe do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
describe '#new_aces' do
|
79
|
-
let(:shoe) { build(:shoe, blackjack:
|
79
|
+
let(:shoe) { build(:shoe, blackjack:) }
|
80
80
|
|
81
81
|
it 'creates a shoe' do
|
82
82
|
shoe.new_aces
|
@@ -91,7 +91,7 @@ RSpec.describe Shoe do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
describe '#new_jacks' do
|
94
|
-
let(:shoe) { build(:shoe, blackjack:
|
94
|
+
let(:shoe) { build(:shoe, blackjack:) }
|
95
95
|
|
96
96
|
it 'creates a shoe' do
|
97
97
|
shoe.new_jacks
|
@@ -106,7 +106,7 @@ RSpec.describe Shoe do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
describe '#new_aces_jacks' do
|
109
|
-
let(:shoe) { build(:shoe, blackjack:
|
109
|
+
let(:shoe) { build(:shoe, blackjack:) }
|
110
110
|
|
111
111
|
it 'creates a shoe' do
|
112
112
|
shoe.new_aces_jacks
|
@@ -121,7 +121,7 @@ RSpec.describe Shoe do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
describe '#new_sevens' do
|
124
|
-
let(:shoe) { build(:shoe, blackjack:
|
124
|
+
let(:shoe) { build(:shoe, blackjack:) }
|
125
125
|
|
126
126
|
it 'creates a shoe' do
|
127
127
|
shoe.new_sevens
|
@@ -136,7 +136,7 @@ RSpec.describe Shoe do
|
|
136
136
|
end
|
137
137
|
|
138
138
|
describe '#new_eights' do
|
139
|
-
let(:shoe) { build(:shoe, blackjack:
|
139
|
+
let(:shoe) { build(:shoe, blackjack:) }
|
140
140
|
|
141
141
|
it 'creates a shoe' do
|
142
142
|
shoe.new_eights
|
@@ -151,11 +151,10 @@ RSpec.describe Shoe do
|
|
151
151
|
end
|
152
152
|
|
153
153
|
describe '#next_card' do
|
154
|
-
let(:shoe) { build(:shoe, :new_regular, blackjack:
|
154
|
+
let(:shoe) { build(:shoe, :new_regular, blackjack:) }
|
155
155
|
|
156
156
|
it 'removes the next card' do
|
157
|
-
shoe.next_card
|
158
|
-
expect(shoe.cards.size).to eq(51)
|
157
|
+
expect { shoe.next_card }.to change(shoe.cards, :size).by(-1)
|
159
158
|
end
|
160
159
|
|
161
160
|
it 'returns a Card' do
|
data/spec/lib/blackjack_spec.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
RSpec.describe Blackjack do
|
4
4
|
let(:blackjack) { build(:blackjack, shoe: build(:shoe, :new_regular)) }
|
5
|
-
let(:player_hand) { build(:player_hand, blackjack:
|
6
|
-
let(:dealer_hand) { build(:dealer_hand, blackjack:
|
7
|
-
let(:ace) { build(:card, :ace, blackjack:
|
8
|
-
let(:ten) { build(:card, :ten, blackjack:
|
5
|
+
let(:player_hand) { build(:player_hand, blackjack:) }
|
6
|
+
let(:dealer_hand) { build(:dealer_hand, blackjack:) }
|
7
|
+
let(:ace) { build(:card, :ace, blackjack:) }
|
8
|
+
let(:ten) { build(:card, :ten, blackjack:) }
|
9
|
+
let(:input) { StringIO.new }
|
9
10
|
|
10
11
|
describe '#current_player_hand' do
|
11
12
|
it 'returns the current hand' do
|
@@ -27,8 +28,8 @@ RSpec.describe Blackjack do
|
|
27
28
|
|
28
29
|
describe '#getc' do
|
29
30
|
it 'get a single character from stdin' do
|
30
|
-
allow(
|
31
|
-
c = described_class.getc
|
31
|
+
allow(input).to receive(:getc).and_return('q')
|
32
|
+
c = described_class.getc(input)
|
32
33
|
expect(c).to eq('q')
|
33
34
|
end
|
34
35
|
end
|
@@ -100,7 +101,7 @@ RSpec.describe Blackjack do
|
|
100
101
|
end
|
101
102
|
|
102
103
|
describe '#save_game' do
|
103
|
-
let(:file) { instance_double(
|
104
|
+
let(:file) { instance_double(File) }
|
104
105
|
|
105
106
|
before do
|
106
107
|
allow(File).to receive(:open).with(SAVE_FILE, 'w').and_yield(file)
|
@@ -109,8 +110,9 @@ RSpec.describe Blackjack do
|
|
109
110
|
|
110
111
|
it 'opens and put save file data' do
|
111
112
|
blackjack.save_game
|
112
|
-
|
113
|
-
|
113
|
+
expected = %i[num_decks deck_type face_type money current_bet].map do |f|
|
114
|
+
blackjack.send(f)
|
115
|
+
end.join('|')
|
114
116
|
expect(file).to have_received(:puts).with(expected)
|
115
117
|
end
|
116
118
|
end
|
@@ -324,7 +326,7 @@ RSpec.describe Blackjack do
|
|
324
326
|
|
325
327
|
it 'shows dealer down card' do
|
326
328
|
blackjack.deal_new_hand
|
327
|
-
expect(dealer_hand.
|
329
|
+
expect(dealer_hand.hide_first_card).to be_falsey
|
328
330
|
end
|
329
331
|
|
330
332
|
it 'hands are paid' do
|
@@ -391,7 +393,7 @@ RSpec.describe Blackjack do
|
|
391
393
|
|
392
394
|
it 'draws the hands' do
|
393
395
|
blackjack.draw_hands
|
394
|
-
expected = "\n Dealer:\n 🂪
|
396
|
+
expected = "\n Dealer:\n 🂠 🂪 ⇒ 10\n\n Player $100.00:\n 🂡 🂪 ⇒ 21 $5.00 ⇐ \n\n"
|
395
397
|
expect(blackjack).to have_received(:puts).with(expected)
|
396
398
|
end
|
397
399
|
end
|
@@ -399,7 +401,7 @@ RSpec.describe Blackjack do
|
|
399
401
|
describe '#new_bet' do
|
400
402
|
before do
|
401
403
|
blackjack.dealer_hand = dealer_hand
|
402
|
-
allow(
|
404
|
+
allow(input).to receive(:gets).and_return('10')
|
403
405
|
allow(described_class).to receive(:getc).and_return('s', 'q')
|
404
406
|
allow(blackjack).to receive(:print)
|
405
407
|
allow(blackjack).to receive(:puts)
|
@@ -410,33 +412,33 @@ RSpec.describe Blackjack do
|
|
410
412
|
end
|
411
413
|
|
412
414
|
it 'clears the screen' do
|
413
|
-
blackjack.new_bet
|
415
|
+
blackjack.new_bet(input)
|
414
416
|
expect(blackjack).to have_received(:clear)
|
415
417
|
end
|
416
418
|
|
417
419
|
it 'draws hands' do
|
418
|
-
blackjack.new_bet
|
420
|
+
blackjack.new_bet(input)
|
419
421
|
expect(blackjack).to have_received(:draw_hands)
|
420
422
|
end
|
421
423
|
|
422
424
|
it 'draws the current bet' do
|
423
|
-
blackjack.new_bet
|
425
|
+
blackjack.new_bet(input)
|
424
426
|
expected = " Current Bet: $5.00\n"
|
425
427
|
expect(blackjack).to have_received(:puts).with(expected)
|
426
428
|
end
|
427
429
|
|
428
430
|
it 'updates current bet' do
|
429
|
-
blackjack.new_bet
|
431
|
+
blackjack.new_bet(input)
|
430
432
|
expect(blackjack.current_bet).to eq(1000)
|
431
433
|
end
|
432
434
|
|
433
435
|
it 'normalizes the bet' do
|
434
|
-
blackjack.new_bet
|
436
|
+
blackjack.new_bet(input)
|
435
437
|
expect(blackjack).to have_received(:normalize_current_bet)
|
436
438
|
end
|
437
439
|
|
438
440
|
it 'deals a new hand' do
|
439
|
-
blackjack.new_bet
|
441
|
+
blackjack.new_bet(input)
|
440
442
|
expect(blackjack).to have_received(:deal_new_hand)
|
441
443
|
end
|
442
444
|
end
|
@@ -584,7 +586,7 @@ RSpec.describe Blackjack do
|
|
584
586
|
describe '#new_num_decks' do
|
585
587
|
before do
|
586
588
|
blackjack.dealer_hand = dealer_hand
|
587
|
-
allow(
|
589
|
+
allow(input).to receive(:gets).and_return('2')
|
588
590
|
allow(described_class).to receive(:getc).and_return('b', 'q')
|
589
591
|
allow(blackjack).to receive(:print)
|
590
592
|
allow(blackjack).to receive(:puts)
|
@@ -595,22 +597,22 @@ RSpec.describe Blackjack do
|
|
595
597
|
end
|
596
598
|
|
597
599
|
it 'clears screen' do
|
598
|
-
blackjack.new_num_decks
|
600
|
+
blackjack.new_num_decks(input)
|
599
601
|
expect(blackjack).to have_received(:clear)
|
600
602
|
end
|
601
603
|
|
602
604
|
it 'draws hands' do
|
603
|
-
blackjack.new_num_decks
|
605
|
+
blackjack.new_num_decks(input)
|
604
606
|
expect(blackjack).to have_received(:draw_hands)
|
605
607
|
end
|
606
608
|
|
607
609
|
it 'gets new number of decks' do
|
608
|
-
blackjack.new_num_decks
|
610
|
+
blackjack.new_num_decks(input)
|
609
611
|
expect(blackjack.num_decks).to eq(2)
|
610
612
|
end
|
611
613
|
|
612
614
|
it 'normalizes number of decks' do
|
613
|
-
blackjack.new_num_decks
|
615
|
+
blackjack.new_num_decks(input)
|
614
616
|
expect(blackjack).to have_received(:normalize_num_decks)
|
615
617
|
end
|
616
618
|
end
|
@@ -814,9 +816,9 @@ RSpec.describe Blackjack do
|
|
814
816
|
expect(player_hand.payed).to be_truthy
|
815
817
|
end
|
816
818
|
|
817
|
-
it 'sets hand status as
|
819
|
+
it 'sets hand status as :lost' do
|
818
820
|
blackjack.insure_hand
|
819
|
-
expect(player_hand.status).to eq(
|
821
|
+
expect(player_hand.status).to eq(:lost)
|
820
822
|
end
|
821
823
|
|
822
824
|
it 'updates blackjack money' do
|
@@ -852,7 +854,7 @@ RSpec.describe Blackjack do
|
|
852
854
|
|
853
855
|
it 'shows dealer down card' do
|
854
856
|
blackjack.no_insurance
|
855
|
-
expect(dealer_hand.
|
857
|
+
expect(dealer_hand.hide_first_card).to be_falsey
|
856
858
|
end
|
857
859
|
|
858
860
|
it 'pays hands' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console-blackjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Donald
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Blackjack for your console, full version.
|
14
14
|
email: gdonald@gmail.com
|
@@ -24,9 +24,7 @@ files:
|
|
24
24
|
- Rakefile
|
25
25
|
- bin/console-blackjack
|
26
26
|
- bj.txt
|
27
|
-
- console-blackjack-1.0.
|
28
|
-
- console-blackjack-1.0.8.gem
|
29
|
-
- console-blackjack-1.0.9.gem
|
27
|
+
- console-blackjack-1.1.0.gem
|
30
28
|
- console-blackjack.gemspec
|
31
29
|
- lib/blackjack.rb
|
32
30
|
- lib/blackjack/card.rb
|
@@ -73,14 +71,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
71
|
requirements:
|
74
72
|
- - ">="
|
75
73
|
- !ruby/object:Gem::Version
|
76
|
-
version: '3.
|
74
|
+
version: '3.1'
|
77
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
76
|
requirements:
|
79
77
|
- - ">="
|
80
78
|
- !ruby/object:Gem::Version
|
81
79
|
version: '0'
|
82
80
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
81
|
+
rubygems_version: 3.3.7
|
84
82
|
signing_key:
|
85
83
|
specification_version: 4
|
86
84
|
summary: Console Blackjack
|
data/console-blackjack-1.0.7.gem
DELETED
Binary file
|
data/console-blackjack-1.0.8.gem
DELETED
Binary file
|