console-blackjack 1.0.9 → 1.1.0

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: 1a3369825b0d070363a8da6637b068793e21b2faef84732507dad91edcefeb4a
4
- data.tar.gz: e8c8ab2105f823bb1971bce15d1a6d3cf4943441e45307152cc8444ca0b5dbc2
3
+ metadata.gz: a97facbefaaf3b5fad5b2051e997180a69ec440671f113d42185af30f2083dfa
4
+ data.tar.gz: c5d018999a9fa12d3c61a0c871deefc3196cfd79bb560dd0caacd4987b6b9a39
5
5
  SHA512:
6
- metadata.gz: 057dd5b492a59aeb487ba9e3d2969654f5ca99c5474f3ca204494b197ccc73a8394ca12b74fe94105995557407cf58f1416ac51074319feff3849a7d77e2a34a
7
- data.tar.gz: 58bee05314cb656e6fb5135aaa7c460797d9a309ab01843570b4c424e7848a81cb28f7a57eaeb76b2a8f4475f45eb08dcac56da75202cebe136de0c6c9057efc
6
+ metadata.gz: f7e7b7079ae568d62bf9bf0ede19b1815a64c0b346c81a14830b02bc5133d116bfcc3f74f5a5408933a2ac5c584d96eceb7544fb163d54166a01b312a5e35497
7
+ data.tar.gz: 1f261b2eea702d06f3936c30e678e1c74594379a423e58583ac74b6de98ef8855519dcc3390aeddfa71beb841eac8a5996161193c2beadadcb3726904d1b5496
data/Gemfile CHANGED
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- ruby '2.7.5'
3
+ ruby '3.0.3'
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,80 +1,59 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (7.0.1)
4
+ activesupport (7.0.2.3)
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.1.9)
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.1.10)
18
12
  diff-lcs (1.5.0)
19
13
  docile (1.4.0)
20
- domain_name (0.5.20190701)
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
- http-accept (1.7.0)
25
- http-cookie (1.0.4)
26
- domain_name (~> 0.5)
27
- i18n (1.8.11)
16
+ i18n (1.10.0)
28
17
  concurrent-ruby (~> 1.0)
29
18
  method_source (1.0.0)
30
- mime-types (3.4.1)
31
- mime-types-data (~> 3.2015)
32
- mime-types-data (3.2022.0105)
33
19
  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
+ parallel (1.22.1)
21
+ parser (3.1.1.0)
38
22
  ast (~> 2.4.1)
39
23
  pry (0.14.1)
40
24
  coderay (~> 1.1)
41
25
  method_source (~> 1.0)
42
26
  rainbow (3.1.1)
43
27
  rake (13.0.6)
44
- regexp_parser (2.2.0)
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)
28
+ regexp_parser (2.2.1)
50
29
  rexml (3.2.5)
51
- rspec (3.10.0)
52
- rspec-core (~> 3.10.0)
53
- rspec-expectations (~> 3.10.0)
54
- rspec-mocks (~> 3.10.0)
55
- rspec-core (3.10.1)
56
- rspec-support (~> 3.10.0)
57
- rspec-expectations (3.10.2)
30
+ rspec (3.11.0)
31
+ rspec-core (~> 3.11.0)
32
+ rspec-expectations (~> 3.11.0)
33
+ rspec-mocks (~> 3.11.0)
34
+ rspec-core (3.11.0)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-expectations (3.11.0)
58
37
  diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.10.0)
60
- rspec-mocks (3.10.2)
38
+ rspec-support (~> 3.11.0)
39
+ rspec-mocks (3.11.0)
61
40
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.10.0)
63
- rspec-support (3.10.3)
64
- rubocop (1.24.1)
41
+ rspec-support (~> 3.11.0)
42
+ rspec-support (3.11.0)
43
+ rubocop (1.26.1)
65
44
  parallel (~> 1.10)
66
- parser (>= 3.0.0.0)
45
+ parser (>= 3.1.0.0)
67
46
  rainbow (>= 2.2.2, < 4.0)
68
47
  regexp_parser (>= 1.8, < 3.0)
69
48
  rexml
70
- rubocop-ast (>= 1.15.1, < 2.0)
49
+ rubocop-ast (>= 1.16.0, < 2.0)
71
50
  ruby-progressbar (~> 1.7)
72
51
  unicode-display_width (>= 1.4.0, < 3.0)
73
- rubocop-ast (1.15.1)
74
- parser (>= 3.0.1.1)
52
+ rubocop-ast (1.16.0)
53
+ parser (>= 3.1.1.0)
75
54
  rubocop-rake (0.6.0)
76
55
  rubocop (~> 1.0)
77
- rubocop-rspec (2.7.0)
56
+ rubocop-rspec (2.9.0)
78
57
  rubocop (~> 1.19)
79
58
  ruby-progressbar (1.11.0)
80
59
  simplecov (0.21.2)
@@ -82,29 +61,18 @@ GEM
82
61
  simplecov-html (~> 0.11)
83
62
  simplecov_json_formatter (~> 0.1)
84
63
  simplecov-html (0.12.3)
85
- simplecov_json_formatter (0.1.3)
86
- sync (0.5.0)
87
- term-ansicolor (1.7.1)
88
- tins (~> 1.0)
89
- thor (1.2.1)
90
- tins (1.31.0)
91
- sync
64
+ simplecov_json_formatter (0.1.4)
92
65
  tzinfo (2.0.4)
93
66
  concurrent-ruby (~> 1.0)
94
- unf (0.1.4)
95
- unf_ext
96
- unf_ext (0.0.8)
97
67
  unicode-display_width (2.1.0)
98
68
 
99
69
  PLATFORMS
100
70
  ruby
101
71
 
102
72
  DEPENDENCIES
103
- coveralls
104
73
  factory_bot
105
74
  pry
106
75
  rake
107
- rest-client (>= 1.8.0)
108
76
  rspec
109
77
  rubocop
110
78
  rubocop-rake
@@ -112,7 +80,7 @@ DEPENDENCIES
112
80
  simplecov
113
81
 
114
82
  RUBY VERSION
115
- ruby 2.7.5p203
83
+ ruby 3.0.3p157
116
84
 
117
85
  BUNDLED WITH
118
- 2.1.4
86
+ 2.2.32
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # console-blackjack-ruby
2
2
 
3
- ![Blackjack](https://raw.githubusercontent.com/gdonald/console-blackjack-ruby/master/bj.png)
3
+ ![Blackjack](https://raw.githubusercontent.com/gdonald/console-blackjack-ruby/master/ss2.png)
4
+
5
+ ![Blackjack](https://raw.githubusercontent.com/gdonald/console-blackjack-ruby/master/ss1.png)
4
6
 
5
7
  ## Getting Started
6
8
 
@@ -15,7 +17,6 @@ Run:
15
17
  ## Status
16
18
 
17
19
  [![Ruby](https://github.com/gdonald/console-blackjack-ruby/workflows/Ruby/badge.svg)](https://github.com/gdonald/console-blackjack-ruby/actions)
18
- [![Coverage Status](https://coveralls.io/repos/github/gdonald/console-blackjack-ruby/badge.svg?branch=master)](https://coveralls.io/github/gdonald/console-blackjack-ruby?branch=master)
19
20
  [![Downloads](https://ruby-gem-downloads-badge.herokuapp.com/console-blackjack?color=blue&type=total&total_label=)](https://rubygems.org/gems/console-blackjack)
20
21
 
21
22
  ## License
data/bj.txt CHANGED
@@ -1 +1 @@
1
- 1|11000|500
1
+ 1|1|1|9000|500
Binary file
@@ -3,9 +3,9 @@
3
3
  require 'rake'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.required_ruby_version = '>= 2.7.5'
6
+ spec.required_ruby_version = '>= 3.0'
7
7
  spec.name = 'console-blackjack'
8
- spec.version = '1.0.9'
8
+ spec.version = '1.1.0'
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"
@@ -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?
@@ -32,4 +35,14 @@ class Card
32
35
  %w[🂩 🂹 🃉 🃙], %w[🂪 🂺 🃊 🃚], %w[🂫 🂻 🃋 🃛], %w[🂭 🂽 🃍 🃝],
33
36
  %w[🂮 🂾 🃎 🃞], %w[🂠]]
34
37
  end
38
+
39
+ def self.faces2
40
+ [%w[A♠ A♥ A♣ A♦], %w[2♠ 2♥ 2♣ 2♦],
41
+ %w[3♠ 3♥ 3♣ 3♦], %w[4♠ 4♥ 4♣ 4♦],
42
+ %w[5♠ 5♥ 5♣ 5♦], %w[6♠ 6♥ 6♣ 6♦],
43
+ %w[7♠ 7♥ 7♣ 7♦], %w[8♠ 8♥ 8♣ 8♦],
44
+ %w[9♠ 9♥ 9♣ 9♦], %w[T♠ T♥ T♣ T♦],
45
+ %w[J♠ J♥ J♣ J♦], %w[Q♠ Q♥ Q♣ Q♦],
46
+ %w[K♠ K♥ K♣ K♦], %w[??]]
47
+ end
35
48
  end
@@ -37,7 +37,7 @@ class DealerHand < Hand
37
37
  def draw
38
38
  out = String.new(' ')
39
39
  cards.each_with_index do |card, index|
40
- out << (index == 1 && hide_down_card ? Card.faces[13][0] : card).to_s
40
+ out << (index == 1 && hide_down_card ? Card.new(blackjack, 13, 0) : card).to_s
41
41
  out << ' '
42
42
  end
43
43
  out << ' ⇒ ' << value(SOFT).to_s
@@ -28,6 +28,6 @@ class Hand
28
28
  def blackjack?
29
29
  return false if cards.size != 2
30
30
 
31
- cards.first.ace? && cards.last.ten? || cards.first.ten? && cards.last.ace?
31
+ (cards.first.ace? && cards.last.ten?) || (cards.first.ten? && cards.last.ace?)
32
32
  end
33
33
  end
@@ -2,7 +2,7 @@
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
7
  c = Blackjack.getc
8
8
  case c
@@ -11,12 +11,15 @@ module Menus
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
 
@@ -26,7 +29,9 @@ module Menus
26
29
  c = Blackjack.getc.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,6 +39,21 @@ 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.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
@@ -12,9 +12,12 @@ SHOES = {
12
12
  }.freeze
13
13
 
14
14
  class Shoe
15
- attr_accessor :num_decks, :cards
15
+ CARDS_PER_DECK = 52
16
16
 
17
- def initialize(num_decks = 1)
17
+ attr_accessor :blackjack, :num_decks, :cards
18
+
19
+ def initialize(blackjack, num_decks)
20
+ @blackjack = blackjack
18
21
  @num_decks = num_decks
19
22
  @cards = []
20
23
  end
@@ -22,7 +25,6 @@ class Shoe
22
25
  def needs_to_shuffle?
23
26
  return true if cards.size.zero?
24
27
 
25
- total_cards = num_decks * 52
26
28
  cards_dealt = total_cards - cards.size
27
29
  used = cards_dealt / total_cards.to_f * 100.0
28
30
 
@@ -38,62 +40,49 @@ class Shoe
38
40
  num_decks.times do
39
41
  (0..3).each do |suit_value|
40
42
  (0..12).each do |value|
41
- cards << Card.new(value, suit_value)
43
+ cards << Card.new(blackjack, value, suit_value)
42
44
  end
43
45
  end
44
46
  end
45
47
  shuffle
46
48
  end
47
49
 
48
- def new_aces
50
+ def new_irregular(values = [])
49
51
  self.cards = []
50
- (num_decks * 10).times do
52
+ while cards.count < total_cards
51
53
  (0..3).each do |suit_value|
52
- cards << Card.new(0, suit_value)
54
+ next if cards.count >= total_cards
55
+
56
+ values.each do |value|
57
+ cards << Card.new(blackjack, value, suit_value)
58
+ end
53
59
  end
54
60
  end
55
61
  shuffle
56
62
  end
57
63
 
64
+ def total_cards
65
+ num_decks * CARDS_PER_DECK
66
+ end
67
+
68
+ def new_aces
69
+ new_irregular([0])
70
+ end
71
+
58
72
  def new_jacks
59
- self.cards = []
60
- (num_decks * 10).times do
61
- (0..3).each do |suit_value|
62
- cards << Card.new(10, suit_value)
63
- end
64
- end
65
- shuffle
73
+ new_irregular([10])
66
74
  end
67
75
 
68
76
  def new_aces_jacks
69
- self.cards = []
70
- (num_decks * 10).times do
71
- (0..3).each do |suit_value|
72
- cards << Card.new(0, suit_value)
73
- cards << Card.new(10, suit_value)
74
- end
75
- end
76
- shuffle
77
+ new_irregular([0, 10])
77
78
  end
78
79
 
79
80
  def new_sevens
80
- self.cards = []
81
- (num_decks * 10).times do
82
- (0..3).each do |suit_value|
83
- cards << Card.new(6, suit_value)
84
- end
85
- end
86
- shuffle
81
+ new_irregular([6])
87
82
  end
88
83
 
89
84
  def new_eights
90
- self.cards = []
91
- (num_decks * 10).times do
92
- (0..3).each do |suit_value|
93
- cards << Card.new(7, suit_value)
94
- end
95
- end
96
- shuffle
85
+ new_irregular([7])
97
86
  end
98
87
 
99
88
  def next_card
@@ -3,7 +3,7 @@
3
3
  module Utils
4
4
  def save_game
5
5
  File.open(SAVE_FILE, 'w') do |file|
6
- file.puts "#{num_decks}|#{money}|#{current_bet}"
6
+ file.puts "#{num_decks}|#{deck_type}|#{face_type}|#{money}|#{current_bet}"
7
7
  end
8
8
  end
9
9
 
@@ -11,9 +11,11 @@ module Utils
11
11
  return unless File.readable?(SAVE_FILE)
12
12
 
13
13
  a = File.read(SAVE_FILE).split('|')
14
- self.num_decks = a[0].to_i
15
- self.money = a[1].to_i
16
- self.current_bet = a[2].to_i
14
+ self.num_decks = a[0].to_i
15
+ self.deck_type = a[1].to_i
16
+ self.face_type = a[2].to_i
17
+ self.money = a[3].to_i
18
+ self.current_bet = a[4].to_i
17
19
  end
18
20
 
19
21
  def clear_draw_hands
@@ -31,6 +33,11 @@ module Utils
31
33
  new_deck_type
32
34
  end
33
35
 
36
+ def clear_draw_hands_new_face_type
37
+ clear_draw_hands
38
+ new_face_type
39
+ end
40
+
34
41
  def clear_draw_hands_ask_insurance
35
42
  clear_draw_hands
36
43
  ask_insurance
data/lib/blackjack.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'pry'
4
+
3
5
  require_relative 'blackjack/dealer_hand'
4
6
  require_relative 'blackjack/format'
5
7
  require_relative 'blackjack/menus'
@@ -17,17 +19,20 @@ class Blackjack
17
19
  include SplitHand
18
20
  include Utils
19
21
 
20
- attr_accessor :shoe, :money, :player_hands, :dealer_hand, :num_decks, :current_bet, :current_hand
22
+ attr_accessor :shoe, :money, :player_hands, :dealer_hand, :num_decks,
23
+ :deck_type, :face_type, :current_bet, :current_hand
21
24
 
22
25
  def initialize
23
26
  @num_decks = 1
27
+ @face_type = 1
28
+ @deck_type = 1
24
29
  @money = 10_000
25
30
  @current_bet = 500
26
31
  end
27
32
 
28
33
  def run
29
34
  load_game
30
- @shoe = Shoe.new(num_decks)
35
+ @shoe = Shoe.new(self, num_decks)
31
36
  deal_new_hand
32
37
  end
33
38
 
@@ -51,7 +56,7 @@ class Blackjack
51
56
  end
52
57
 
53
58
  def deal_new_hand
54
- shoe.new_regular if shoe.needs_to_shuffle?
59
+ shoe.send("new_#{SHOES[deck_type]}") if shoe.needs_to_shuffle?
55
60
  player_hand = build_new_hand
56
61
 
57
62
  if dealer_hand.upcard_is_ace? && !player_hand.blackjack?
@@ -7,6 +7,7 @@ FactoryBot.define do
7
7
  player_hands { [] }
8
8
  dealer_hand { nil }
9
9
  num_decks { 1 }
10
+ face_type { 1 }
10
11
  current_bet { 500 }
11
12
  current_hand { 0 }
12
13
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  FactoryBot.define do
4
4
  factory :card do
5
+ blackjack { nil }
5
6
  value { 0 }
6
7
  suit { 0 }
7
8
 
@@ -37,6 +38,6 @@ FactoryBot.define do
37
38
  value { 9 }
38
39
  end
39
40
 
40
- initialize_with { new(value, suit) }
41
+ initialize_with { new(blackjack, value, suit) }
41
42
  end
42
43
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  FactoryBot.define do
4
4
  factory :shoe do
5
+ blackjack { nil }
5
6
  num_decks { 1 }
6
7
  cards { [] }
7
8
 
@@ -9,6 +10,6 @@ FactoryBot.define do
9
10
  after(:build, &:new_regular)
10
11
  end
11
12
 
12
- initialize_with { new(num_decks) }
13
+ initialize_with { new(blackjack, num_decks) }
13
14
  end
14
15
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Card do
4
- let(:card) { build(:card) }
4
+ let(:blackjack) { build(:blackjack) }
5
+ let(:card) { build(:card, blackjack: blackjack) }
5
6
 
6
7
  describe '.new' do
7
8
  it 'creates a card' do
@@ -18,8 +19,20 @@ RSpec.describe Card do
18
19
  end
19
20
 
20
21
  describe '#to_s' do
21
- it 'returns a string value' do
22
- expect(card.to_s).to eq('🂡')
22
+ context 'with regular faces' do
23
+ it 'returns a string value' do
24
+ expect(card.to_s).to eq('🂡')
25
+ end
26
+ end
27
+
28
+ context 'with alternate faces' do
29
+ before do
30
+ blackjack.face_type = 2
31
+ end
32
+
33
+ it 'returns a string value' do
34
+ expect(card.to_s).to eq('A♠')
35
+ end
23
36
  end
24
37
  end
25
38
 
@@ -4,8 +4,8 @@ RSpec.describe DealerHand do
4
4
  let(:shoe) { build(:shoe, :new_regular) }
5
5
  let(:blackjack) { build(:blackjack) }
6
6
  let(:dealer_hand) { build(:dealer_hand, blackjack: blackjack) }
7
- let(:ace) { build(:card, :ace) }
8
- let(:ten) { build(:card, :ten) }
7
+ let(:ace) { build(:card, :ace, blackjack: blackjack) }
8
+ let(:ten) { build(:card, :ten, blackjack: blackjack) }
9
9
 
10
10
  describe '.new' do
11
11
  it 'creates a dealer_hand' do
@@ -74,19 +74,19 @@ RSpec.describe DealerHand do
74
74
  end
75
75
 
76
76
  describe '#draw' do
77
- it 'returns " 🂪 🂠 10"' do
77
+ it 'returns " 🂪 🂠 10"' do
78
78
  dealer_hand.cards << ten << ace
79
79
  expected = ' 🂪 🂠 ⇒ 10'
80
80
  expect(dealer_hand.draw).to eq(expected)
81
81
  end
82
82
 
83
- it 'returns " 🂡 🂠 11"' do
83
+ it 'returns " 🂡 🂠 11"' do
84
84
  dealer_hand.cards << ace << ten
85
85
  expected = ' 🂡 🂠 ⇒ 11'
86
86
  expect(dealer_hand.draw).to eq(expected)
87
87
  end
88
88
 
89
- it 'returns " 🂡 🂪 21"' do
89
+ it 'returns " 🂡 🂪 21"' do
90
90
  dealer_hand.cards << ace << ten
91
91
  dealer_hand.hide_down_card = false
92
92
  expected = ' 🂡 🂪 ⇒ 21'
@@ -4,8 +4,8 @@ RSpec.describe PlayerHand do
4
4
  let(:blackjack) { build(:blackjack, shoe: build(:shoe, :new_regular)) }
5
5
  let(:player_hand) { build(:player_hand, blackjack: blackjack) }
6
6
  let(:dealer_hand) { build(:dealer_hand, blackjack: blackjack) }
7
- let(:ace) { build(:card, :ace) }
8
- let(:ten) { build(:card, :ten) }
7
+ let(:ace) { build(:card, :ace, blackjack: blackjack) }
8
+ let(:ten) { build(:card, :ten, blackjack: blackjack) }
9
9
 
10
10
  describe '.new' do
11
11
  it 'creates a player_hand' do
@@ -1,7 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Shoe do
4
- let(:shoe) { build(:shoe) }
4
+ let(:blackjack) { build(:blackjack) }
5
+ let(:shoe) { build(:shoe, blackjack: blackjack) }
6
+
7
+ describe 'CARDS_PER_DECK' do
8
+ it 'returns 52' do
9
+ expect(described_class::CARDS_PER_DECK).to eq(52)
10
+ end
11
+ end
5
12
 
6
13
  describe '.new' do
7
14
  it 'creates a shoe' do
@@ -21,7 +28,7 @@ RSpec.describe Shoe do
21
28
  end
22
29
 
23
30
  context 'with a new regular shoe' do
24
- let(:shoe) { build(:shoe, :new_regular) }
31
+ let(:shoe) { build(:shoe, :new_regular, blackjack: blackjack) }
25
32
 
26
33
  it 'returns false' do
27
34
  expect(shoe).to_not be_needs_to_shuffle
@@ -29,7 +36,7 @@ RSpec.describe Shoe do
29
36
  end
30
37
 
31
38
  context 'with 42 cards being dealt' do
32
- let(:shoe) { build(:shoe, :new_regular) }
39
+ let(:shoe) { build(:shoe, :new_regular, blackjack: blackjack) }
33
40
 
34
41
  before do
35
42
  42.times { shoe.next_card }
@@ -42,7 +49,7 @@ RSpec.describe Shoe do
42
49
  end
43
50
 
44
51
  describe '#shuffle' do
45
- let(:shoe) { build(:shoe) }
52
+ let(:shoe) { build(:shoe, blackjack: blackjack) }
46
53
 
47
54
  it 'calls shuffle' do
48
55
  cards = instance_double(Array)
@@ -54,11 +61,11 @@ RSpec.describe Shoe do
54
61
  end
55
62
 
56
63
  describe '#new_regular' do
57
- let(:shoe) { build(:shoe) }
64
+ let(:shoe) { build(:shoe, blackjack: blackjack) }
58
65
 
59
66
  it 'creates a shoe' do
60
67
  shoe.new_regular
61
- expect(shoe.cards.size).to eq(52)
68
+ expect(shoe.cards.size).to eq(Shoe::CARDS_PER_DECK)
62
69
  end
63
70
 
64
71
  it 'calls shuffle' do
@@ -69,11 +76,11 @@ RSpec.describe Shoe do
69
76
  end
70
77
 
71
78
  describe '#new_aces' do
72
- let(:shoe) { build(:shoe) }
79
+ let(:shoe) { build(:shoe, blackjack: blackjack) }
73
80
 
74
81
  it 'creates a shoe' do
75
82
  shoe.new_aces
76
- expect(shoe.cards.size).to eq(40)
83
+ expect(shoe.cards.size).to eq(Shoe::CARDS_PER_DECK)
77
84
  end
78
85
 
79
86
  it 'calls shuffle' do
@@ -84,11 +91,11 @@ RSpec.describe Shoe do
84
91
  end
85
92
 
86
93
  describe '#new_jacks' do
87
- let(:shoe) { build(:shoe) }
94
+ let(:shoe) { build(:shoe, blackjack: blackjack) }
88
95
 
89
96
  it 'creates a shoe' do
90
97
  shoe.new_jacks
91
- expect(shoe.cards.size).to eq(40)
98
+ expect(shoe.cards.size).to eq(Shoe::CARDS_PER_DECK)
92
99
  end
93
100
 
94
101
  it 'calls shuffle' do
@@ -99,11 +106,11 @@ RSpec.describe Shoe do
99
106
  end
100
107
 
101
108
  describe '#new_aces_jacks' do
102
- let(:shoe) { build(:shoe) }
109
+ let(:shoe) { build(:shoe, blackjack: blackjack) }
103
110
 
104
111
  it 'creates a shoe' do
105
112
  shoe.new_aces_jacks
106
- expect(shoe.cards.size).to eq(80)
113
+ expect(shoe.cards.size).to eq(Shoe::CARDS_PER_DECK)
107
114
  end
108
115
 
109
116
  it 'calls shuffle' do
@@ -114,11 +121,11 @@ RSpec.describe Shoe do
114
121
  end
115
122
 
116
123
  describe '#new_sevens' do
117
- let(:shoe) { build(:shoe) }
124
+ let(:shoe) { build(:shoe, blackjack: blackjack) }
118
125
 
119
126
  it 'creates a shoe' do
120
127
  shoe.new_sevens
121
- expect(shoe.cards.size).to eq(40)
128
+ expect(shoe.cards.size).to eq(Shoe::CARDS_PER_DECK)
122
129
  end
123
130
 
124
131
  it 'calls shuffle' do
@@ -129,11 +136,11 @@ RSpec.describe Shoe do
129
136
  end
130
137
 
131
138
  describe '#new_eights' do
132
- let(:shoe) { build(:shoe) }
139
+ let(:shoe) { build(:shoe, blackjack: blackjack) }
133
140
 
134
141
  it 'creates a shoe' do
135
142
  shoe.new_eights
136
- expect(shoe.cards.size).to eq(40)
143
+ expect(shoe.cards.size).to eq(Shoe::CARDS_PER_DECK)
137
144
  end
138
145
 
139
146
  it 'calls shuffle' do
@@ -144,7 +151,7 @@ RSpec.describe Shoe do
144
151
  end
145
152
 
146
153
  describe '#next_card' do
147
- let(:shoe) { build(:shoe, :new_regular) }
154
+ let(:shoe) { build(:shoe, :new_regular, blackjack: blackjack) }
148
155
 
149
156
  it 'removes the next card' do
150
157
  shoe.next_card
@@ -4,8 +4,8 @@ RSpec.describe Blackjack do
4
4
  let(:blackjack) { build(:blackjack, shoe: build(:shoe, :new_regular)) }
5
5
  let(:player_hand) { build(:player_hand, blackjack: blackjack) }
6
6
  let(:dealer_hand) { build(:dealer_hand, blackjack: blackjack) }
7
- let(:ace) { build(:card, :ace) }
8
- let(:ten) { build(:card, :ten) }
7
+ let(:ace) { build(:card, :ace, blackjack: blackjack) }
8
+ let(:ten) { build(:card, :ten, blackjack: blackjack) }
9
9
 
10
10
  describe '#current_player_hand' do
11
11
  it 'returns the current hand' do
@@ -100,12 +100,18 @@ RSpec.describe Blackjack do
100
100
  end
101
101
 
102
102
  describe '#save_game' do
103
- it 'opens and put save file data' do
104
- file = instance_double('File')
103
+ let(:file) { instance_double('File') }
104
+
105
+ before do
105
106
  allow(File).to receive(:open).with(SAVE_FILE, 'w').and_yield(file)
106
107
  allow(file).to receive(:puts)
108
+ end
109
+
110
+ it 'opens and put save file data' do
107
111
  blackjack.save_game
108
- expect(file).to have_received(:puts).with("#{blackjack.num_decks}|#{blackjack.money}|#{blackjack.current_bet}")
112
+ fields = %i[num_decks deck_type face_type money current_bet]
113
+ expected = fields.map { |f| blackjack.send(f) }.join('|')
114
+ expect(file).to have_received(:puts).with(expected)
109
115
  end
110
116
  end
111
117
 
@@ -123,7 +129,7 @@ RSpec.describe Blackjack do
123
129
  context 'with a readabale save file' do
124
130
  before do
125
131
  allow(File).to receive(:readable?).with(SAVE_FILE).and_return(true)
126
- allow(File).to receive(:read).with(SAVE_FILE).and_return('8|2000|1000')
132
+ allow(File).to receive(:read).with(SAVE_FILE).and_return('8|1|1|2000|1000')
127
133
  end
128
134
 
129
135
  it 'loads num_decks from save file data' do
@@ -131,6 +137,11 @@ RSpec.describe Blackjack do
131
137
  expect(blackjack.num_decks).to eq(8)
132
138
  end
133
139
 
140
+ it 'loads face_type from save file data' do
141
+ blackjack.load_game
142
+ expect(blackjack.face_type).to eq(1)
143
+ end
144
+
134
145
  it 'loads money from save file data' do
135
146
  blackjack.load_game
136
147
  expect(blackjack.money).to eq(2000)
@@ -446,7 +457,7 @@ RSpec.describe Blackjack do
446
457
 
447
458
  it 'draws the blackjack options' do
448
459
  blackjack.draw_game_options
449
- expected = ' (N) Number of Decks (T) Deck Type (B) Back'
460
+ expected = ' (N) Number of Decks (T) Deck Type (F) Face Type (B) Back'
450
461
  expect(blackjack).to have_received(:puts).with(expected)
451
462
  end
452
463
 
@@ -497,6 +508,37 @@ RSpec.describe Blackjack do
497
508
  end
498
509
  end
499
510
 
511
+ context 'when updating the face type' do
512
+ before do
513
+ allow(described_class).to receive(:getc).and_return('f')
514
+ allow(blackjack).to receive(:clear)
515
+ allow(blackjack).to receive(:draw_hands)
516
+ allow(blackjack).to receive(:new_face_type)
517
+ allow(blackjack).to receive(:draw_bet_options)
518
+ allow(blackjack).to receive(:puts)
519
+ end
520
+
521
+ it 'clears the screen' do
522
+ blackjack.draw_game_options
523
+ expect(blackjack).to have_received(:clear).twice
524
+ end
525
+
526
+ it 'draws the hands' do
527
+ blackjack.draw_game_options
528
+ expect(blackjack).to have_received(:draw_hands).twice
529
+ end
530
+
531
+ it 'updates face type' do
532
+ blackjack.draw_game_options
533
+ expect(blackjack).to have_received(:new_face_type)
534
+ end
535
+
536
+ it 'draws the bet options' do
537
+ blackjack.draw_game_options
538
+ expect(blackjack).to have_received(:draw_bet_options)
539
+ end
540
+ end
541
+
500
542
  context 'when going back to previous menu' do
501
543
  before do
502
544
  allow(described_class).to receive(:getc).and_return('b')
@@ -597,6 +639,7 @@ RSpec.describe Blackjack do
597
639
  before do
598
640
  blackjack.dealer_hand = dealer_hand
599
641
  allow(blackjack).to receive(:puts)
642
+ allow(blackjack).to receive(:save_game)
600
643
  end
601
644
 
602
645
  context 'when choosing a new deck type' do
@@ -612,6 +655,7 @@ RSpec.describe Blackjack do
612
655
  allow(blackjack.shoe).to receive(:new_regular)
613
656
  blackjack.new_deck_type
614
657
  expect(blackjack.shoe).to have_received(:new_regular)
658
+ expect(blackjack).to have_received(:save_game)
615
659
  end
616
660
 
617
661
  it 'builds a new aces' do
@@ -619,6 +663,7 @@ RSpec.describe Blackjack do
619
663
  allow(blackjack.shoe).to receive(:new_aces)
620
664
  blackjack.new_deck_type
621
665
  expect(blackjack.shoe).to have_received(:new_aces)
666
+ expect(blackjack).to have_received(:save_game)
622
667
  end
623
668
 
624
669
  it 'builds a new jacks' do
@@ -626,6 +671,7 @@ RSpec.describe Blackjack do
626
671
  allow(blackjack.shoe).to receive(:new_jacks)
627
672
  blackjack.new_deck_type
628
673
  expect(blackjack.shoe).to have_received(:new_jacks)
674
+ expect(blackjack).to have_received(:save_game)
629
675
  end
630
676
 
631
677
  it 'builds a new aces_jacks' do
@@ -633,6 +679,7 @@ RSpec.describe Blackjack do
633
679
  allow(blackjack.shoe).to receive(:new_aces_jacks)
634
680
  blackjack.new_deck_type
635
681
  expect(blackjack.shoe).to have_received(:new_aces_jacks)
682
+ expect(blackjack).to have_received(:save_game)
636
683
  end
637
684
 
638
685
  it 'builds a new sevens' do
@@ -640,6 +687,7 @@ RSpec.describe Blackjack do
640
687
  allow(blackjack.shoe).to receive(:new_sevens)
641
688
  blackjack.new_deck_type
642
689
  expect(blackjack.shoe).to have_received(:new_sevens)
690
+ expect(blackjack).to have_received(:save_game)
643
691
  end
644
692
 
645
693
  it 'builds a new eights' do
@@ -647,6 +695,7 @@ RSpec.describe Blackjack do
647
695
  allow(blackjack.shoe).to receive(:new_eights)
648
696
  blackjack.new_deck_type
649
697
  expect(blackjack.shoe).to have_received(:new_eights)
698
+ expect(blackjack).to have_received(:save_game)
650
699
  end
651
700
  end
652
701
 
@@ -656,13 +705,56 @@ RSpec.describe Blackjack do
656
705
  allow(blackjack).to receive(:draw_hands)
657
706
  blackjack.new_deck_type
658
707
  expect(blackjack).to have_received(:draw_hands)
708
+ expect(blackjack).to have_received(:save_game).twice
709
+ end
710
+ end
711
+ end
712
+
713
+ describe '#new_face_type' do
714
+ before do
715
+ blackjack.dealer_hand = dealer_hand
716
+ allow(blackjack).to receive(:puts)
717
+ end
718
+
719
+ context 'when choosing a new face type' do
720
+ it 'draws options' do
721
+ allow(described_class).to receive(:getc).and_return('1')
722
+ blackjack.new_face_type
723
+ expected = ' (1) 🂡 (2) A♠'
724
+ expect(blackjack).to have_received(:puts).with(expected)
725
+ end
726
+
727
+ it 'sets regular faces' do
728
+ allow(described_class).to receive(:getc).and_return('1')
729
+ allow(blackjack).to receive(:save_game)
730
+ allow(blackjack).to receive(:face_type=).with(1)
731
+ blackjack.new_face_type
732
+ expect(blackjack).to have_received(:face_type=).with(1)
733
+ expect(blackjack).to have_received(:save_game)
734
+ end
735
+
736
+ it 'sets alternate faces' do
737
+ allow(described_class).to receive(:getc).and_return('2')
738
+ allow(blackjack).to receive(:save_game)
739
+ allow(blackjack).to receive(:face_type=).with(2)
740
+ blackjack.new_face_type
741
+ expect(blackjack).to have_received(:face_type=).with(2)
742
+ expect(blackjack).to have_received(:save_game)
743
+ end
744
+ end
745
+
746
+ context 'when invalid input' do
747
+ it 'gets the action again' do
748
+ allow(described_class).to receive(:getc).and_return('x', '1')
749
+ allow(blackjack).to receive(:draw_hands)
750
+ blackjack.new_face_type
751
+ expect(blackjack).to have_received(:draw_hands)
659
752
  end
660
753
  end
661
754
  end
662
755
 
663
756
  describe '#ask_insurance' do
664
757
  before do
665
- # blackjack.dealer_hand = dealer_hand
666
758
  allow(blackjack).to receive(:puts)
667
759
  allow(blackjack).to receive(:insure_hand)
668
760
  allow(blackjack).to receive(:no_insurance)
data/spec/spec_helper.rb CHANGED
@@ -7,12 +7,9 @@ SimpleCov.start do
7
7
  primary_coverage :branch
8
8
  end
9
9
 
10
- require 'coveralls'
11
- Coveralls.wear!
12
-
13
10
  Dir.glob(File.join(File.dirname(__FILE__),
14
11
  "..#{File::SEPARATOR}lib", '**',
15
- '*.rb')).sort.each(&method(:require))
12
+ '*.rb')).each(&method(:require))
16
13
 
17
14
  require 'factory_bot'
18
15
  require 'pry'
data/ss1.png ADDED
Binary file
data/ss2.png ADDED
Binary file
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.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Donald
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-15 00:00:00.000000000 Z
11
+ date: 2022-03-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Blackjack for your console, full version.
14
14
  email: gdonald@gmail.com
@@ -23,10 +23,10 @@ files:
23
23
  - README.md
24
24
  - Rakefile
25
25
  - bin/console-blackjack
26
- - bj.png
27
26
  - bj.txt
28
27
  - console-blackjack-1.0.7.gem
29
28
  - console-blackjack-1.0.8.gem
29
+ - console-blackjack-1.0.9.gem
30
30
  - console-blackjack.gemspec
31
31
  - lib/blackjack.rb
32
32
  - lib/blackjack/card.rb
@@ -54,11 +54,14 @@ files:
54
54
  - spec/lib/blackjack/shoe_spec.rb
55
55
  - spec/lib/blackjack_spec.rb
56
56
  - spec/spec_helper.rb
57
+ - ss1.png
58
+ - ss2.png
57
59
  homepage: https://github.com/gdonald/console-blackjack-ruby
58
60
  licenses:
59
61
  - MIT
60
62
  metadata:
61
63
  source_code_uri: https://github.com/gdonald/console-blackjack-ruby
64
+ rubygems_mfa_required: 'true'
62
65
  post_install_message: |2+
63
66
 
64
67
  Type `console-blackjack` to run!
@@ -70,15 +73,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
73
  requirements:
71
74
  - - ">="
72
75
  - !ruby/object:Gem::Version
73
- version: 2.7.5
76
+ version: '3.0'
74
77
  required_rubygems_version: !ruby/object:Gem::Requirement
75
78
  requirements:
76
79
  - - ">="
77
80
  - !ruby/object:Gem::Version
78
81
  version: '0'
79
82
  requirements: []
80
- rubygems_version: 3.1.6
81
- signing_key:
83
+ rubygems_version: 3.2.32
84
+ signing_key:
82
85
  specification_version: 4
83
86
  summary: Console Blackjack
84
87
  test_files: []
88
+ ...
data/bj.png DELETED
Binary file