console-blackjack 1.1.4 → 1.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a80968fb789ad02815a1d598eeaf4ceaabd4ea7d683fa7a5f392dcb116314355
4
- data.tar.gz: 7e15b203fb77e927ceb9a3d630d7129244c15564f5ace1c33c16b34e69590e06
3
+ metadata.gz: 3e33af9b542767ff7bead274db11e41bd1b1f8d33ebf63c5baebfa93afc611d6
4
+ data.tar.gz: 3952bad7dd3a9d28a310a144aa23afc7f3c192a708a75199f69c1ec585f576b7
5
5
  SHA512:
6
- metadata.gz: f8caf4b44ba2ffa0a6e2ae2dc16dfee13b0537ab68d1ee09b84ed48d0b78dd7eb80e93d74fb2212ebb85b7e3138b138faa20a9bf4e2c6080462cf804d9d69de9
7
- data.tar.gz: 5fcd249be0447eca9aee18e6aace72834b93c63995555baf4e270d8a190fce78ff666c1eb876353e95103c3139b6b6a719bec106c85133230aa84ed668c06ac6
6
+ metadata.gz: 1b64f0be69a10c946a9fada714d31fdf09c233ff35938adad84401060956d76d26c1bdf26ab01eb9b5f46abb954769eb5722d2e7857fbd83213d3192fe196cf0
7
+ data.tar.gz: 05ce3a76552f6b551654674e1de88518507061ab0f008fdb0823ca3baa3140c17dd417c6730f58e0d187773b27869dcc07f9d0df6e4373df7f635eba74ffa9c4
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ruby '3.2.2'
3
+ ruby '3.4.1'
4
4
 
5
5
  source 'https://rubygems.org'
6
6
 
@@ -8,6 +8,7 @@ gem 'factory_bot'
8
8
  gem 'rake'
9
9
  gem 'rspec'
10
10
  gem 'rubocop', require: false
11
+ gem 'rubocop-factory_bot'
11
12
  gem 'rubocop-rake'
12
13
  gem 'rubocop-rspec'
13
14
  gem 'simplecov', require: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (7.1.2)
4
+ activesupport (7.1.3.4)
5
5
  base64
6
6
  bigdecimal
7
7
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -13,68 +13,62 @@ GEM
13
13
  tzinfo (~> 2.0)
14
14
  ast (2.4.2)
15
15
  base64 (0.2.0)
16
- bigdecimal (3.1.4)
17
- concurrent-ruby (1.2.2)
16
+ bigdecimal (3.1.8)
17
+ concurrent-ruby (1.3.3)
18
18
  connection_pool (2.4.1)
19
- diff-lcs (1.5.0)
19
+ diff-lcs (1.5.1)
20
20
  docile (1.4.0)
21
- drb (2.2.0)
22
- ruby2_keywords
23
- factory_bot (6.4.2)
21
+ drb (2.2.1)
22
+ factory_bot (6.4.6)
24
23
  activesupport (>= 5.0.0)
25
- i18n (1.14.1)
24
+ i18n (1.14.5)
26
25
  concurrent-ruby (~> 1.0)
27
- json (2.7.1)
26
+ json (2.7.2)
28
27
  language_server-protocol (3.17.0.3)
29
- minitest (5.20.0)
28
+ minitest (5.24.1)
30
29
  mutex_m (0.2.0)
31
- parallel (1.23.0)
32
- parser (3.2.2.4)
30
+ parallel (1.25.1)
31
+ parser (3.3.4.0)
33
32
  ast (~> 2.4.1)
34
33
  racc
35
- racc (1.7.3)
34
+ racc (1.8.0)
36
35
  rainbow (3.1.1)
37
- rake (13.1.0)
38
- regexp_parser (2.8.3)
39
- rexml (3.2.6)
40
- rspec (3.12.0)
41
- rspec-core (~> 3.12.0)
42
- rspec-expectations (~> 3.12.0)
43
- rspec-mocks (~> 3.12.0)
44
- rspec-core (3.12.2)
45
- rspec-support (~> 3.12.0)
46
- rspec-expectations (3.12.3)
36
+ rake (13.2.1)
37
+ regexp_parser (2.9.2)
38
+ rexml (3.3.9)
39
+ rspec (3.13.0)
40
+ rspec-core (~> 3.13.0)
41
+ rspec-expectations (~> 3.13.0)
42
+ rspec-mocks (~> 3.13.0)
43
+ rspec-core (3.13.0)
44
+ rspec-support (~> 3.13.0)
45
+ rspec-expectations (3.13.1)
47
46
  diff-lcs (>= 1.2.0, < 2.0)
48
- rspec-support (~> 3.12.0)
49
- rspec-mocks (3.12.6)
47
+ rspec-support (~> 3.13.0)
48
+ rspec-mocks (3.13.1)
50
49
  diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.12.0)
52
- rspec-support (3.12.1)
53
- rubocop (1.58.0)
50
+ rspec-support (~> 3.13.0)
51
+ rspec-support (3.13.1)
52
+ rubocop (1.65.0)
54
53
  json (~> 2.3)
55
54
  language_server-protocol (>= 3.17.0)
56
55
  parallel (~> 1.10)
57
- parser (>= 3.2.2.4)
56
+ parser (>= 3.3.0.2)
58
57
  rainbow (>= 2.2.2, < 4.0)
59
- regexp_parser (>= 1.8, < 3.0)
58
+ regexp_parser (>= 2.4, < 3.0)
60
59
  rexml (>= 3.2.5, < 4.0)
61
- rubocop-ast (>= 1.30.0, < 2.0)
60
+ rubocop-ast (>= 1.31.1, < 2.0)
62
61
  ruby-progressbar (~> 1.7)
63
62
  unicode-display_width (>= 2.4.0, < 3.0)
64
- rubocop-ast (1.30.0)
65
- parser (>= 3.2.1.0)
66
- rubocop-capybara (2.19.0)
67
- rubocop (~> 1.41)
68
- rubocop-factory_bot (2.24.0)
69
- rubocop (~> 1.33)
63
+ rubocop-ast (1.31.3)
64
+ parser (>= 3.3.1.0)
65
+ rubocop-factory_bot (2.26.1)
66
+ rubocop (~> 1.61)
70
67
  rubocop-rake (0.6.0)
71
68
  rubocop (~> 1.0)
72
- rubocop-rspec (2.25.0)
73
- rubocop (~> 1.40)
74
- rubocop-capybara (~> 2.17)
75
- rubocop-factory_bot (~> 2.22)
69
+ rubocop-rspec (3.0.3)
70
+ rubocop (~> 1.61)
76
71
  ruby-progressbar (1.13.0)
77
- ruby2_keywords (0.0.5)
78
72
  simplecov (0.22.0)
79
73
  docile (~> 1.1)
80
74
  simplecov-html (~> 0.11)
@@ -94,12 +88,13 @@ DEPENDENCIES
94
88
  rake
95
89
  rspec
96
90
  rubocop
91
+ rubocop-factory_bot
97
92
  rubocop-rake
98
93
  rubocop-rspec
99
94
  simplecov
100
95
 
101
96
  RUBY VERSION
102
- ruby 3.2.2p53
97
+ ruby 3.4.1p0
103
98
 
104
99
  BUNDLED WITH
105
100
  2.4.22
data/README.md CHANGED
@@ -23,19 +23,7 @@ Run:
23
23
 
24
24
  [![GitHub](https://img.shields.io/github/license/gdonald/console-blackjack-ruby?color=aa0000)](https://github.com/gdonald/console-blackjack-ruby/blob/master/LICENSE)
25
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)
41
- - [Emacs Lisp](https://github.com/gdonald/blackjack-el)
26
+ ### Other Blackjack Implementations:
27
+
28
+ I've written Blackjack in [some other programming languages](https://github.com/gdonald?tab=repositories&q=blackjack&type=public&language=&sort=stargazers) too. Check them out!
29
+
data/bj.txt CHANGED
@@ -1 +1 @@
1
- 1|1|1|9000|500
1
+ 1|1|1|10000|500
Binary file
Binary file
@@ -3,9 +3,9 @@
3
3
  require 'rake'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.required_ruby_version = '>= 3.2'
6
+ spec.required_ruby_version = '>= 3.4'
7
7
  spec.name = 'console-blackjack'
8
- spec.version = '1.1.4'
8
+ spec.version = '1.1.6'
9
9
  spec.summary = 'Console Blackjack'
10
10
  spec.description = 'Blackjack for your console, full version.'
11
11
  spec.author = 'Greg Donald'
@@ -10,9 +10,7 @@ class Card
10
10
  end
11
11
 
12
12
  def to_s
13
- return Card.faces[value][suit] if blackjack.face_type == 1
14
-
15
- Card.faces2[value][suit]
13
+ (blackjack.face_type == 1 ? Card.faces : Card.faces2)[value][suit]
16
14
  end
17
15
 
18
16
  def ace?
@@ -6,20 +6,10 @@ class DealerHand < Hand
6
6
  attr_accessor :blackjack, :hide_first_card
7
7
 
8
8
  def initialize(blackjack)
9
- super(blackjack)
9
+ super
10
10
  @hide_first_card = true
11
11
  end
12
12
 
13
- def value(count_method)
14
- total = value_for_method(count_method)
15
-
16
- if count_method == :soft && total > 21
17
- value(:hard)
18
- else
19
- total
20
- end
21
- end
22
-
23
13
  def upcard_is_ace?
24
14
  cards.first.ace?
25
15
  end
@@ -30,7 +20,7 @@ class DealerHand < Hand
30
20
  out << (index.zero? && hide_first_card ? Card.new(blackjack, 13, 0) : card).to_s
31
21
  out << ' '
32
22
  end
33
- out << ' ⇒ ' << value(:soft).to_s
23
+ out << ' ⇒ ' << value(:soft, hide_first_card:).to_s
34
24
  end
35
25
 
36
26
  def deal_required_cards
@@ -42,7 +32,7 @@ class DealerHand < Hand
42
32
  end
43
33
 
44
34
  def both_values
45
- [value(:soft), value(:hard)]
35
+ [value(:soft, hide_first_card:), value(:hard, hide_first_card:)]
46
36
  end
47
37
 
48
38
  def play
@@ -52,16 +42,4 @@ class DealerHand < Hand
52
42
  self.played = true
53
43
  blackjack.pay_hands
54
44
  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
67
45
  end
@@ -18,8 +18,19 @@ class Hand
18
18
  end
19
19
 
20
20
  def blackjack?
21
- return false if cards.size != 2
21
+ cards.size == 2 && value(:soft) == 21
22
+ end
23
+
24
+ def value(count_method, hide_first_card: false)
25
+ total = 0
26
+ cards.each_with_index do |card, index|
27
+ next if index.zero? && hide_first_card
28
+
29
+ total += Card.value(card, count_method, total)
30
+ end
31
+
32
+ return value(:hard, hide_first_card:) if count_method == :soft && total > 21
22
33
 
23
- (cards.first.ace? && cards.last.ten?) || (cards.first.ten? && cards.last.ace?)
34
+ total
24
35
  end
25
36
  end
@@ -54,16 +54,6 @@ class PlayerHand < Hand
54
54
  self.status = :won
55
55
  end
56
56
 
57
- def value(count_method)
58
- total = cards.inject(0) { |sum, card| sum + Card.value(card, count_method, sum) }
59
-
60
- if count_method == :soft && total > 21
61
- value(:hard)
62
- else
63
- total
64
- end
65
- end
66
-
67
57
  def done?
68
58
  return false unless no_more_actions?
69
59
 
@@ -115,8 +105,8 @@ class PlayerHand < Hand
115
105
 
116
106
  def draw_actions
117
107
  actions = []
118
- actions << '(H) Hit' if can_hit?
119
- actions << '(S) Stand' if can_stand?
108
+ actions << '(H) Hit'
109
+ actions << '(S) Stand'
120
110
  actions << '(P) Split' if can_split?
121
111
  actions << '(D) Double' if can_dbl?
122
112
  puts " #{actions.join(' ')}"
@@ -13,9 +13,9 @@ module PlayerHandDraw
13
13
  def draw_status
14
14
  case status
15
15
  when :lost
16
- draw_lost_str
16
+ busted? ? 'Busted!' : 'Lose!'
17
17
  when :won
18
- draw_won_str
18
+ blackjack? ? 'Blackjack!' : 'Won!'
19
19
  when :push
20
20
  'Push'
21
21
  else
@@ -23,14 +23,6 @@ module PlayerHandDraw
23
23
  end
24
24
  end
25
25
 
26
- def draw_lost_str
27
- busted? ? 'Busted!' : 'Lose!'
28
- end
29
-
30
- def draw_won_str
31
- blackjack? ? 'Blackjack!' : 'Won!'
32
- end
33
-
34
26
  def draw_money(index)
35
27
  out = String.new('')
36
28
  out << '-' if status == :lost
@@ -35,54 +35,46 @@ class Shoe
35
35
  7.times { cards.shuffle! }
36
36
  end
37
37
 
38
- def new_regular
39
- self.cards = []
40
- num_decks.times do
41
- 4.times do |suit_value|
42
- 13.times do |value|
43
- cards << Card.new(blackjack, value, suit_value)
44
- end
45
- end
46
- end
47
- shuffle
38
+ def total_cards
39
+ @total_cards ||= num_decks * CARDS_PER_DECK
48
40
  end
49
41
 
50
- def new_irregular(values = [])
42
+ def build_deck(values = [])
51
43
  self.cards = []
52
44
  while cards.count < total_cards
53
- 4.times do |suit_value|
45
+ 4.times do |suit|
54
46
  next if cards.count >= total_cards
55
47
 
56
48
  values.each do |value|
57
- cards << Card.new(blackjack, value, suit_value)
49
+ cards << Card.new(blackjack, value, suit)
58
50
  end
59
51
  end
60
52
  end
61
53
  shuffle
62
54
  end
63
55
 
64
- def total_cards
65
- num_decks * CARDS_PER_DECK
56
+ def new_regular
57
+ build_deck((0..12).to_a)
66
58
  end
67
59
 
68
60
  def new_aces
69
- new_irregular([0])
61
+ build_deck([0])
70
62
  end
71
63
 
72
64
  def new_jacks
73
- new_irregular([10])
65
+ build_deck([10])
74
66
  end
75
67
 
76
68
  def new_aces_jacks
77
- new_irregular([0, 10])
69
+ build_deck([0, 10])
78
70
  end
79
71
 
80
72
  def new_sevens
81
- new_irregular([6])
73
+ build_deck([6])
82
74
  end
83
75
 
84
76
  def new_eights
85
- new_irregular([7])
77
+ build_deck([7])
86
78
  end
87
79
 
88
80
  def next_card
@@ -33,12 +33,12 @@ RSpec.describe DealerHand do
33
33
  context 'with a soft count' do
34
34
  it 'returns 10' do
35
35
  dealer_hand.cards << ace << ten
36
- expect(dealer_hand.value(:soft)).to eq(10)
36
+ expect(dealer_hand.value(:soft, hide_first_card: true)).to eq(10)
37
37
  end
38
38
 
39
39
  it 'returns 11' do
40
40
  dealer_hand.cards << ten << ace
41
- expect(dealer_hand.value(:soft)).to eq(11)
41
+ expect(dealer_hand.value(:soft, hide_first_card: true)).to eq(11)
42
42
  end
43
43
 
44
44
  it 'returns 12' do
@@ -51,12 +51,12 @@ RSpec.describe DealerHand do
51
51
  context 'with a hard count' do
52
52
  it 'returns 10' do
53
53
  dealer_hand.cards << ace << ten
54
- expect(dealer_hand.value(:hard)).to eq(10)
54
+ expect(dealer_hand.value(:hard, hide_first_card: true)).to eq(10)
55
55
  end
56
56
 
57
57
  it 'returns 1' do
58
58
  dealer_hand.cards << ten << ace
59
- expect(dealer_hand.value(:hard)).to eq(1)
59
+ expect(dealer_hand.value(:hard, hide_first_card: true)).to eq(1)
60
60
  end
61
61
  end
62
62
  end
@@ -496,20 +496,6 @@ RSpec.describe PlayerHand do
496
496
  end.to output(" (H) Hit (S) Stand\n").to_stdout
497
497
  end
498
498
 
499
- it 'cannot hit' do
500
- allow(player_hand).to receive(:can_hit?).and_return(false)
501
- expect do
502
- player_hand.draw_actions
503
- end.to output(" (S) Stand\n").to_stdout
504
- end
505
-
506
- it 'cannot stand' do
507
- allow(player_hand).to receive(:can_stand?).and_return(false)
508
- expect do
509
- player_hand.draw_actions
510
- end.to output(" (H) Hit\n").to_stdout
511
- end
512
-
513
499
  it 'can split' do
514
500
  allow(player_hand).to receive(:can_split?).and_return(true)
515
501
  expect do
@@ -523,29 +509,46 @@ RSpec.describe PlayerHand do
523
509
  player_hand.draw_actions
524
510
  end.to output(" (H) Hit (S) Stand (D) Double\n").to_stdout
525
511
  end
526
- end
527
-
528
- describe '#draw_lost_str' do
529
- it 'returns Busted!' do
530
- allow(player_hand).to receive(:busted?).and_return(true)
531
- expect(player_hand.draw_lost_str).to eq('Busted!')
532
- end
533
512
 
534
- it 'returns Lose!' do
535
- allow(player_hand).to receive(:busted?).and_return(false)
536
- expect(player_hand.draw_lost_str).to eq('Lose!')
513
+ it 'can split and double' do
514
+ allow(player_hand).to receive_messages(can_split?: true, can_dbl?: true)
515
+ expect do
516
+ player_hand.draw_actions
517
+ end.to output(" (H) Hit (S) Stand (P) Split (D) Double\n").to_stdout
537
518
  end
538
519
  end
539
520
 
540
- describe '#draw_won_str' do
541
- it 'returns Blackjack!' do
542
- allow(player_hand).to receive(:blackjack?).and_return(true)
543
- expect(player_hand.draw_won_str).to eq('Blackjack!')
521
+ describe '#draw_status' do
522
+ context 'with a lost hand' do
523
+ before do
524
+ allow(player_hand).to receive(:status).and_return(:lost)
525
+ end
526
+
527
+ it 'returns Busted!' do
528
+ allow(player_hand).to receive(:busted?).and_return(true)
529
+ expect(player_hand.draw_status).to eq('Busted!')
530
+ end
531
+
532
+ it 'returns Lose!' do
533
+ allow(player_hand).to receive(:busted?).and_return(false)
534
+ expect(player_hand.draw_status).to eq('Lose!')
535
+ end
544
536
  end
545
537
 
546
- it 'returns Won!' do
547
- allow(player_hand).to receive(:blackjack?).and_return(false)
548
- expect(player_hand.draw_won_str).to eq('Won!')
538
+ context 'with a won hand' do
539
+ before do
540
+ allow(player_hand).to receive(:status).and_return(:won)
541
+ end
542
+
543
+ it 'returns Blackjack!' do
544
+ allow(player_hand).to receive(:blackjack?).and_return(true)
545
+ expect(player_hand.draw_status).to eq('Blackjack!')
546
+ end
547
+
548
+ it 'returns Won!' do
549
+ allow(player_hand).to receive(:blackjack?).and_return(false)
550
+ expect(player_hand.draw_status).to eq('Won!')
551
+ end
549
552
  end
550
553
  end
551
554
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console-blackjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Donald
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-12-09 00:00:00.000000000 Z
10
+ date: 2025-01-18 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Blackjack for your console, full version.
14
13
  email: gdonald@gmail.com
@@ -25,6 +24,8 @@ files:
25
24
  - bin/console-blackjack
26
25
  - bj.txt
27
26
  - console-blackjack-1.1.3.gem
27
+ - console-blackjack-1.1.4.gem
28
+ - console-blackjack-1.1.5.gem
28
29
  - console-blackjack.gemspec
29
30
  - lib/blackjack.rb
30
31
  - lib/blackjack/card.rb
@@ -71,15 +72,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - ">="
73
74
  - !ruby/object:Gem::Version
74
- version: '3.2'
75
+ version: '3.4'
75
76
  required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  requirements:
77
78
  - - ">="
78
79
  - !ruby/object:Gem::Version
79
80
  version: '0'
80
81
  requirements: []
81
- rubygems_version: 3.4.22
82
- signing_key:
82
+ rubygems_version: 3.6.2
83
83
  specification_version: 4
84
84
  summary: Console Blackjack
85
85
  test_files: []