console-blackjack 1.0.9 → 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 -3
- data/Gemfile.lock +40 -67
- data/README.md +19 -2
- data/bj.txt +1 -1
- data/console-blackjack-1.1.0.gem +0 -0
- data/console-blackjack.gemspec +4 -3
- data/lib/blackjack/card.rb +21 -6
- data/lib/blackjack/dealer_hand.rb +21 -19
- data/lib/blackjack/hand.rb +2 -10
- data/lib/blackjack/menus.rb +27 -7
- 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/shoe.rb +25 -36
- data/lib/blackjack/utils.rb +12 -5
- data/lib/blackjack.rb +18 -13
- data/spec/factories/blackjack_factory.rb +1 -0
- data/spec/factories/card_factory.rb +6 -1
- data/spec/factories/dealer_hand_factory.rb +1 -1
- data/spec/factories/player_hand_factory.rb +1 -1
- data/spec/factories/shoe_factory.rb +2 -1
- data/spec/lib/blackjack/card_spec.rb +51 -3
- data/spec/lib/blackjack/dealer_hand_spec.rb +31 -31
- 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 +25 -19
- data/spec/lib/blackjack_spec.rb +123 -29
- data/spec/spec_helper.rb +1 -4
- data/ss1.png +0 -0
- data/ss2.png +0 -0
- metadata +11 -9
- data/bj.png +0 -0
- 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
@@ -1,14 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
ruby '
|
3
|
+
ruby '3.1.2'
|
4
4
|
|
5
5
|
source 'https://rubygems.org'
|
6
6
|
|
7
|
-
gem 'coveralls', require: false
|
8
7
|
gem 'factory_bot'
|
9
8
|
gem 'pry'
|
10
9
|
gem 'rake'
|
11
|
-
gem 'rest-client', '>= 1.8.0'
|
12
10
|
gem 'rspec'
|
13
11
|
gem 'rubocop', require: false
|
14
12
|
gem 'rubocop-rake'
|
data/Gemfile.lock
CHANGED
@@ -1,110 +1,83 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (7.0.
|
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.
|
12
|
-
coveralls (0.7.1)
|
13
|
-
multi_json (~> 1.3)
|
14
|
-
rest-client
|
15
|
-
simplecov (>= 0.7)
|
16
|
-
term-ansicolor
|
17
|
-
thor
|
11
|
+
concurrent-ruby (1.2.0)
|
18
12
|
diff-lcs (1.5.0)
|
19
13
|
docile (1.4.0)
|
20
|
-
|
21
|
-
unf (>= 0.0.5, < 1.0.0)
|
22
|
-
factory_bot (6.2.0)
|
14
|
+
factory_bot (6.2.1)
|
23
15
|
activesupport (>= 5.0.0)
|
24
|
-
|
25
|
-
http-cookie (1.0.4)
|
26
|
-
domain_name (~> 0.5)
|
27
|
-
i18n (1.8.11)
|
16
|
+
i18n (1.12.0)
|
28
17
|
concurrent-ruby (~> 1.0)
|
18
|
+
json (2.6.3)
|
29
19
|
method_source (1.0.0)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
minitest (5.15.0)
|
34
|
-
multi_json (1.15.0)
|
35
|
-
netrc (0.11.0)
|
36
|
-
parallel (1.21.0)
|
37
|
-
parser (3.1.0.0)
|
20
|
+
minitest (5.17.0)
|
21
|
+
parallel (1.22.1)
|
22
|
+
parser (3.2.0.0)
|
38
23
|
ast (~> 2.4.1)
|
39
|
-
pry (0.14.
|
24
|
+
pry (0.14.2)
|
40
25
|
coderay (~> 1.1)
|
41
26
|
method_source (~> 1.0)
|
42
27
|
rainbow (3.1.1)
|
43
28
|
rake (13.0.6)
|
44
|
-
regexp_parser (2.2
|
45
|
-
rest-client (2.1.0)
|
46
|
-
http-accept (>= 1.7.0, < 2.0)
|
47
|
-
http-cookie (>= 1.0.2, < 2.0)
|
48
|
-
mime-types (>= 1.16, < 4.0)
|
49
|
-
netrc (~> 0.8)
|
29
|
+
regexp_parser (2.6.2)
|
50
30
|
rexml (3.2.5)
|
51
|
-
rspec (3.
|
52
|
-
rspec-core (~> 3.
|
53
|
-
rspec-expectations (~> 3.
|
54
|
-
rspec-mocks (~> 3.
|
55
|
-
rspec-core (3.
|
56
|
-
rspec-support (~> 3.
|
57
|
-
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)
|
58
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
59
|
-
rspec-support (~> 3.
|
60
|
-
rspec-mocks (3.
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-mocks (3.12.3)
|
61
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
62
|
-
rspec-support (~> 3.
|
63
|
-
rspec-support (3.
|
64
|
-
rubocop (1.
|
42
|
+
rspec-support (~> 3.12.0)
|
43
|
+
rspec-support (3.12.0)
|
44
|
+
rubocop (1.44.1)
|
45
|
+
json (~> 2.3)
|
65
46
|
parallel (~> 1.10)
|
66
|
-
parser (>= 3.
|
47
|
+
parser (>= 3.2.0.0)
|
67
48
|
rainbow (>= 2.2.2, < 4.0)
|
68
49
|
regexp_parser (>= 1.8, < 3.0)
|
69
|
-
rexml
|
70
|
-
rubocop-ast (>= 1.
|
50
|
+
rexml (>= 3.2.5, < 4.0)
|
51
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
71
52
|
ruby-progressbar (~> 1.7)
|
72
|
-
unicode-display_width (>=
|
73
|
-
rubocop-ast (1.
|
74
|
-
parser (>= 3.
|
53
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.24.1)
|
55
|
+
parser (>= 3.1.1.0)
|
56
|
+
rubocop-capybara (2.17.0)
|
57
|
+
rubocop (~> 1.41)
|
75
58
|
rubocop-rake (0.6.0)
|
76
59
|
rubocop (~> 1.0)
|
77
|
-
rubocop-rspec (2.
|
78
|
-
rubocop (~> 1.
|
60
|
+
rubocop-rspec (2.18.1)
|
61
|
+
rubocop (~> 1.33)
|
62
|
+
rubocop-capybara (~> 2.17)
|
79
63
|
ruby-progressbar (1.11.0)
|
80
|
-
simplecov (0.
|
64
|
+
simplecov (0.22.0)
|
81
65
|
docile (~> 1.1)
|
82
66
|
simplecov-html (~> 0.11)
|
83
67
|
simplecov_json_formatter (~> 0.1)
|
84
68
|
simplecov-html (0.12.3)
|
85
|
-
simplecov_json_formatter (0.1.
|
86
|
-
|
87
|
-
term-ansicolor (1.7.1)
|
88
|
-
tins (~> 1.0)
|
89
|
-
thor (1.2.1)
|
90
|
-
tins (1.31.0)
|
91
|
-
sync
|
92
|
-
tzinfo (2.0.4)
|
69
|
+
simplecov_json_formatter (0.1.4)
|
70
|
+
tzinfo (2.0.6)
|
93
71
|
concurrent-ruby (~> 1.0)
|
94
|
-
|
95
|
-
unf_ext
|
96
|
-
unf_ext (0.0.8)
|
97
|
-
unicode-display_width (2.1.0)
|
72
|
+
unicode-display_width (2.4.2)
|
98
73
|
|
99
74
|
PLATFORMS
|
100
75
|
ruby
|
101
76
|
|
102
77
|
DEPENDENCIES
|
103
|
-
coveralls
|
104
78
|
factory_bot
|
105
79
|
pry
|
106
80
|
rake
|
107
|
-
rest-client (>= 1.8.0)
|
108
81
|
rspec
|
109
82
|
rubocop
|
110
83
|
rubocop-rake
|
@@ -112,7 +85,7 @@ DEPENDENCIES
|
|
112
85
|
simplecov
|
113
86
|
|
114
87
|
RUBY VERSION
|
115
|
-
ruby
|
88
|
+
ruby 3.1.2p20
|
116
89
|
|
117
90
|
BUNDLED WITH
|
118
|
-
2.
|
91
|
+
2.3.15
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# console-blackjack-ruby
|
2
2
|
|
3
|
-

|
4
|
+
|
5
|
+

|
4
6
|
|
5
7
|
## Getting Started
|
6
8
|
|
@@ -15,9 +17,24 @@ Run:
|
|
15
17
|
## Status
|
16
18
|
|
17
19
|
[](https://github.com/gdonald/console-blackjack-ruby/actions)
|
18
|
-
[](https://coveralls.io/github/gdonald/console-blackjack-ruby?branch=master)
|
19
20
|
[](https://rubygems.org/gems/console-blackjack)
|
20
21
|
|
21
22
|
## License
|
22
23
|
|
23
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|11000|500
|
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 = '>=
|
6
|
+
spec.required_ruby_version = '>= 3.1'
|
7
7
|
spec.name = 'console-blackjack'
|
8
|
-
spec.version = '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'
|
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
'spec/**/*.rb'].to_a
|
19
19
|
spec.homepage = 'https://github.com/gdonald/console-blackjack-ruby'
|
20
20
|
spec.metadata = {
|
21
|
-
'source_code_uri' => 'https://github.com/gdonald/console-blackjack-ruby'
|
21
|
+
'source_code_uri' => 'https://github.com/gdonald/console-blackjack-ruby',
|
22
|
+
'rubygems_mfa_required' => 'true'
|
22
23
|
}
|
23
24
|
spec.license = 'MIT'
|
24
25
|
spec.post_install_message = "\nType `console-blackjack` to run!\n\n"
|
data/lib/blackjack/card.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Card
|
4
|
-
attr_reader :value, :suit
|
4
|
+
attr_reader :blackjack, :value, :suit
|
5
5
|
|
6
|
-
def initialize(value, suit)
|
6
|
+
def initialize(blackjack, value, suit)
|
7
|
+
@blackjack = blackjack
|
7
8
|
@value = value
|
8
9
|
@suit = suit
|
9
10
|
end
|
10
11
|
|
11
12
|
def to_s
|
12
|
-
Card.faces[value][suit]
|
13
|
+
return Card.faces[value][suit] if blackjack.face_type == 1
|
14
|
+
|
15
|
+
Card.faces2[value][suit]
|
13
16
|
end
|
14
17
|
|
15
18
|
def ace?
|
@@ -21,9 +24,11 @@ class Card
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def self.value(card, count_method, total)
|
24
|
-
value = card.value
|
25
|
-
|
26
|
-
|
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
|
27
32
|
end
|
28
33
|
|
29
34
|
def self.faces
|
@@ -32,4 +37,14 @@ class Card
|
|
32
37
|
%w[🂩 🂹 🃉 🃙], %w[🂪 🂺 🃊 🃚], %w[🂫 🂻 🃋 🃛], %w[🂭 🂽 🃍 🃝],
|
33
38
|
%w[🂮 🂾 🃎 🃞], %w[🂠]]
|
34
39
|
end
|
40
|
+
|
41
|
+
def self.faces2
|
42
|
+
[%w[A♠ A♥ A♣ A♦], %w[2♠ 2♥ 2♣ 2♦],
|
43
|
+
%w[3♠ 3♥ 3♣ 3♦], %w[4♠ 4♥ 4♣ 4♦],
|
44
|
+
%w[5♠ 5♥ 5♣ 5♦], %w[6♠ 6♥ 6♣ 6♦],
|
45
|
+
%w[7♠ 7♥ 7♣ 7♦], %w[8♠ 8♥ 8♣ 8♦],
|
46
|
+
%w[9♠ 9♥ 9♣ 9♦], %w[T♠ T♥ T♣ T♦],
|
47
|
+
%w[J♠ J♥ J♣ J♦], %w[Q♠ Q♥ Q♣ Q♦],
|
48
|
+
%w[K♠ K♥ K♣ K♦], %w[??]]
|
49
|
+
end
|
35
50
|
end
|
@@ -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
|
@@ -28,6 +20,6 @@ class Hand
|
|
28
20
|
def blackjack?
|
29
21
|
return false if cards.size != 2
|
30
22
|
|
31
|
-
cards.first.ace? && cards.last.ten? || cards.first.ten? && cards.last.ace?
|
23
|
+
(cards.first.ace? && cards.last.ten?) || (cards.first.ten? && cards.last.ace?)
|
32
24
|
end
|
33
25
|
end
|
data/lib/blackjack/menus.rb
CHANGED
@@ -2,31 +2,36 @@
|
|
2
2
|
|
3
3
|
module Menus
|
4
4
|
def draw_game_options
|
5
|
-
puts ' (N) Number of Decks (T) Deck Type (B) Back'
|
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
|
11
11
|
when 't'
|
12
12
|
clear_draw_hands_new_deck_type
|
13
13
|
clear_draw_hands_bet_options
|
14
|
+
when 'f'
|
15
|
+
clear_draw_hands_new_face_type
|
16
|
+
clear_draw_hands_bet_options
|
14
17
|
when 'b'
|
15
18
|
clear_draw_hands_bet_options
|
16
19
|
else
|
17
20
|
clear_draw_hands_game_options
|
18
21
|
end
|
19
|
-
break if %w[n t b].include?(c)
|
22
|
+
break if %w[n t b f].include?(c)
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
26
|
def new_deck_type
|
24
27
|
puts ' (1) Regular (2) Aces (3) Jacks (4) Aces & Jacks (5) Sevens (6) Eights'
|
25
28
|
loop do
|
26
|
-
c = Blackjack.getc.to_i
|
29
|
+
c = Blackjack.getc($stdin).to_i
|
27
30
|
case c
|
28
31
|
when (1..6)
|
32
|
+
self.deck_type = c
|
29
33
|
shoe.send("new_#{SHOES[c]}")
|
34
|
+
save_game
|
30
35
|
else
|
31
36
|
clear_draw_hands_new_deck_type
|
32
37
|
end
|
@@ -34,10 +39,25 @@ module Menus
|
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
42
|
+
def new_face_type
|
43
|
+
puts ' (1) 🂡 (2) A♠'
|
44
|
+
loop do
|
45
|
+
c = Blackjack.getc($stdin).to_i
|
46
|
+
case c
|
47
|
+
when (1..2)
|
48
|
+
self.face_type = c
|
49
|
+
save_game
|
50
|
+
else
|
51
|
+
clear_draw_hands_new_face_type
|
52
|
+
end
|
53
|
+
break if (1..2).include?(c)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
37
57
|
def ask_insurance
|
38
58
|
puts ' Insurance? (Y) Yes (N) No'
|
39
59
|
loop do
|
40
|
-
c = Blackjack.getc
|
60
|
+
c = Blackjack.getc($stdin)
|
41
61
|
case c
|
42
62
|
when 'y'
|
43
63
|
insure_hand
|
@@ -52,12 +72,12 @@ module Menus
|
|
52
72
|
|
53
73
|
def draw_bet_options
|
54
74
|
puts ' (D) Deal Hand (B) Change Bet (O) Options (Q) Quit'
|
55
|
-
c = Blackjack.getc
|
75
|
+
c = Blackjack.getc($stdin)
|
56
76
|
case c
|
57
77
|
when 'd'
|
58
78
|
deal_new_hand
|
59
79
|
when 'b'
|
60
|
-
new_bet
|
80
|
+
new_bet($stdin)
|
61
81
|
when 'o'
|
62
82
|
clear_draw_hands_game_options
|
63
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
|