console-blackjack 1.0.0 → 1.0.5

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: 6d6b53cff41f5f86ff9b279267559148007288ad2d6a64002308bd2c60b15519
4
- data.tar.gz: 35c2c4bc1d8fe0f20fdab6a22da8f8395724b8a7c0eb8c72a0a384f8072dd0b2
3
+ metadata.gz: 0e53727e957fb5e163cc56ac04e0c1e79e027d58834691e6290059ac8d653ddf
4
+ data.tar.gz: 3cc3c0b725b9592d85d92735a3bc4ce1208170f7369ace802ea15b9b1e3ef86e
5
5
  SHA512:
6
- metadata.gz: ded02e0f2f976b44fe6c24300d58c1107d6555a7fd35bcdb4908cf5dbabfa7ea9c0c5fe6d3d47da7ee34be4728df00baf744b4a13f3de4c7af70687e18b07b8e
7
- data.tar.gz: 24294265189ea7d8cc29973c2a3a285b38d5ac41fae3d6b8fb88f331599381828d640c6cb92b1be629bd31281f8ba0d8d8298c12c85193e0f82028ffaf177e99
6
+ metadata.gz: 109ceb08d745fc3c6848c8872e7e7e6d4f354dfbb21361d1daedd5211c308cbe3673acdbc54e212540d57560ee986ddc92c07a001d8712b81e771bebcc391957
7
+ data.tar.gz: 89d6b9c4d3fbb0dcc557868125f5591cc7cd551fb33ce9de568255223273e4f33784b12f33ba99c792398ab150504167a1352df854f77606dca00e27db145159
@@ -1,15 +1,15 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (6.0.1)
4
+ activesupport (6.0.3.1)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.2)
6
6
  i18n (>= 0.7, < 2)
7
7
  minitest (~> 5.1)
8
8
  tzinfo (~> 1.1)
9
- zeitwerk (~> 2.2)
9
+ zeitwerk (~> 2.2, >= 2.2.2)
10
10
  ast (2.4.0)
11
11
  coderay (1.1.2)
12
- concurrent-ruby (1.1.5)
12
+ concurrent-ruby (1.1.6)
13
13
  coveralls (0.7.1)
14
14
  multi_json (~> 1.3)
15
15
  rest-client
@@ -20,75 +20,78 @@ GEM
20
20
  docile (1.3.2)
21
21
  domain_name (0.5.20190701)
22
22
  unf (>= 0.0.5, < 1.0.0)
23
- factory_bot (5.1.1)
23
+ factory_bot (5.2.0)
24
24
  activesupport (>= 4.2.0)
25
25
  http-accept (1.7.0)
26
26
  http-cookie (1.0.3)
27
27
  domain_name (~> 0.5)
28
- i18n (1.7.0)
28
+ i18n (1.8.2)
29
29
  concurrent-ruby (~> 1.0)
30
- jaro_winkler (1.5.4)
31
- json (2.2.0)
32
- method_source (0.9.2)
33
- mime-types (3.3)
30
+ method_source (1.0.0)
31
+ mime-types (3.3.1)
34
32
  mime-types-data (~> 3.2015)
35
- mime-types-data (3.2019.1009)
36
- minitest (5.13.0)
33
+ mime-types-data (3.2020.0512)
34
+ minitest (5.14.1)
37
35
  multi_json (1.14.1)
38
36
  netrc (0.11.0)
39
- parallel (1.18.0)
40
- parser (2.6.5.0)
37
+ parallel (1.19.1)
38
+ parser (2.7.1.3)
41
39
  ast (~> 2.4.0)
42
- pry (0.12.2)
43
- coderay (~> 1.1.0)
44
- method_source (~> 0.9.0)
40
+ pry (0.13.1)
41
+ coderay (~> 1.1)
42
+ method_source (~> 1.0)
45
43
  rainbow (3.0.0)
46
- rake (13.0.0)
44
+ rake (13.0.1)
47
45
  rest-client (2.1.0)
48
46
  http-accept (>= 1.7.0, < 2.0)
49
47
  http-cookie (>= 1.0.2, < 2.0)
50
48
  mime-types (>= 1.16, < 4.0)
51
49
  netrc (~> 0.8)
50
+ rexml (3.2.4)
52
51
  rspec (3.9.0)
53
52
  rspec-core (~> 3.9.0)
54
53
  rspec-expectations (~> 3.9.0)
55
54
  rspec-mocks (~> 3.9.0)
56
- rspec-core (3.9.0)
57
- rspec-support (~> 3.9.0)
58
- rspec-expectations (3.9.0)
55
+ rspec-core (3.9.2)
56
+ rspec-support (~> 3.9.3)
57
+ rspec-expectations (3.9.2)
59
58
  diff-lcs (>= 1.2.0, < 2.0)
60
59
  rspec-support (~> 3.9.0)
61
- rspec-mocks (3.9.0)
60
+ rspec-mocks (3.9.1)
62
61
  diff-lcs (>= 1.2.0, < 2.0)
63
62
  rspec-support (~> 3.9.0)
64
- rspec-support (3.9.0)
65
- rubocop (0.76.0)
66
- jaro_winkler (~> 1.5.1)
63
+ rspec-support (3.9.3)
64
+ rubocop (0.84.0)
67
65
  parallel (~> 1.10)
68
- parser (>= 2.6)
66
+ parser (>= 2.7.0.1)
69
67
  rainbow (>= 2.2.2, < 4.0)
68
+ rexml
69
+ rubocop-ast (>= 0.0.3)
70
70
  ruby-progressbar (~> 1.7)
71
- unicode-display_width (>= 1.4.0, < 1.7)
72
- rubocop-rspec (1.36.0)
71
+ unicode-display_width (>= 1.4.0, < 2.0)
72
+ rubocop-ast (0.0.3)
73
+ parser (>= 2.7.0.1)
74
+ rubocop-rspec (1.39.0)
73
75
  rubocop (>= 0.68.1)
74
76
  ruby-progressbar (1.10.1)
75
- simplecov (0.17.1)
77
+ simplecov (0.18.5)
76
78
  docile (~> 1.1)
77
- json (>= 1.8, < 3)
78
- simplecov-html (~> 0.10.0)
79
- simplecov-html (0.10.2)
79
+ simplecov-html (~> 0.11)
80
+ simplecov-html (0.12.2)
81
+ sync (0.5.0)
80
82
  term-ansicolor (1.7.1)
81
83
  tins (~> 1.0)
82
- thor (0.20.3)
84
+ thor (1.0.1)
83
85
  thread_safe (0.3.6)
84
- tins (1.22.0)
85
- tzinfo (1.2.5)
86
+ tins (1.25.0)
87
+ sync
88
+ tzinfo (1.2.7)
86
89
  thread_safe (~> 0.1)
87
90
  unf (0.1.4)
88
91
  unf_ext
89
- unf_ext (0.0.7.6)
90
- unicode-display_width (1.6.0)
91
- zeitwerk (2.2.1)
92
+ unf_ext (0.0.7.7)
93
+ unicode-display_width (1.7.0)
94
+ zeitwerk (2.3.0)
92
95
 
93
96
  PLATFORMS
94
97
  ruby
@@ -105,4 +108,4 @@ DEPENDENCIES
105
108
  simplecov
106
109
 
107
110
  BUNDLED WITH
108
- 2.0.2
111
+ 2.1.4
data/README.md CHANGED
@@ -1,28 +1,23 @@
1
- # blackjack-ruby
1
+ # console-blackjack-ruby
2
2
 
3
- ## Console
4
-
5
- ![Blackjack](https://raw.githubusercontent.com/gdonald/blackjack-ruby/master/bj.png)
3
+ ![Blackjack](https://raw.githubusercontent.com/gdonald/console-blackjack-ruby/master/bj.png)
6
4
 
7
5
  ## Getting Started
8
6
 
9
- Install gems:
10
-
11
- bundle install
12
-
13
- Run tests:
7
+ Install:
14
8
 
15
- rake
9
+ gem install console-blackjack
16
10
 
17
11
  Run:
18
12
 
19
- ruby blackjack.rb
13
+ console-blackjack
20
14
 
21
15
  ## Status
22
16
 
23
- [![Build Status](https://travis-ci.org/gdonald/blackjack-ruby.svg?branch=master)](https://travis-ci.org/gdonald/blackjack-ruby)
24
- [![Coverage Status](https://coveralls.io/repos/github/gdonald/blackjack-ruby/badge.svg?branch=master)](https://coveralls.io/github/gdonald/blackjack-ruby?branch=master)
17
+ [![Build Status](https://travis-ci.org/gdonald/console-blackjack-ruby.svg?branch=master)](https://travis-ci.org/gdonald/console-blackjack-ruby)
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
+ [![Downloads](https://ruby-gem-downloads-badge.herokuapp.com/console-blackjack?color=blue&type=total&total_label=)](https://rubygems.org/gems/console-blackjack)
25
20
 
26
21
  ## License
27
22
 
28
- blackjack-ruby is released under the [MIT License](http://www.opensource.org/licenses/MIT)
23
+ [![GitHub](https://img.shields.io/github/license/gdonald/console-blackjack-ruby?color=aa0000)](https://github.com/gdonald/console-blackjack-ruby/blob/master/LICENSE)
data/bj.txt CHANGED
@@ -1 +1 @@
1
- 8|1153000|500
1
+ 1|10000|500
@@ -4,8 +4,8 @@ require 'rake'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'console-blackjack'
7
- spec.version = '1.0.0'
8
- spec.date = '2019-11-09'
7
+ spec.version = '1.0.5'
8
+ spec.date = '2020-05-26'
9
9
  spec.summary = 'Console Blackjack'
10
10
  spec.description = 'Blackjack for your console, full version.'
11
11
  spec.author = 'Greg Donald'
@@ -1,14 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'blackjack/shoe'
4
3
  require_relative 'blackjack/dealer_hand'
4
+ require_relative 'blackjack/format'
5
+ require_relative 'blackjack/menus'
5
6
  require_relative 'blackjack/player_hand'
7
+ require_relative 'blackjack/shoe'
8
+ require_relative 'blackjack/split_hand'
9
+ require_relative 'blackjack/utils'
6
10
 
7
11
  SAVE_FILE = 'bj.txt'
8
12
  MIN_BET = 500
9
13
  MAX_BET = 10_000_000
10
14
 
11
15
  class Blackjack
16
+ include Menus
17
+ include SplitHand
18
+ include Utils
19
+
12
20
  attr_accessor :shoe, :money, :player_hands, :dealer_hand, :num_decks, :current_bet, :current_hand
13
21
 
14
22
  def initialize
@@ -72,8 +80,7 @@ class Blackjack
72
80
  if current_player_hand.done?
73
81
  current_player_hand.process
74
82
  else
75
- draw_hands
76
- current_player_hand.action?
83
+ draw_hands_current_hand_action
77
84
  end
78
85
  end
79
86
 
@@ -84,16 +91,6 @@ class Blackjack
84
91
  false
85
92
  end
86
93
 
87
- def normalize_current_bet
88
- if current_bet < MIN_BET
89
- self.current_bet = MIN_BET
90
- elsif current_bet > MAX_BET
91
- self.current_bet = MAX_BET
92
- end
93
-
94
- self.current_bet = money if current_bet > money
95
- end
96
-
97
94
  def pay_hands
98
95
  dealer_hand_value = dealer_hand.value(SOFT)
99
96
  dealer_busted = dealer_hand.busted?
@@ -116,76 +113,41 @@ class Blackjack
116
113
  clear
117
114
  out = String.new
118
115
  out << "\n Dealer:\n#{dealer_hand.draw}\n"
119
-
120
116
  out << "\n Player $"
121
- out << Blackjack.format_money(money / 100.0)
117
+ out << Format.money(money / 100.0)
122
118
  out << ":\n"
119
+ out << draw_player_hands
120
+ puts out
121
+ end
123
122
 
123
+ def draw_player_hands
124
+ out = String.new('')
124
125
  player_hands.each_with_index do |player_hand, index|
125
126
  out << player_hand.draw(index)
126
127
  end
127
-
128
- puts out
128
+ out
129
129
  end
130
130
 
131
131
  def new_bet
132
132
  clear
133
133
  draw_hands
134
134
 
135
- puts " Current Bet: $#{Blackjack.format_money(current_bet / 100)}\n"
135
+ puts " Current Bet: $#{Format.money(current_bet / 100)}\n"
136
136
  print ' Enter New Bet: $'
137
137
 
138
- tmp = STDIN.gets.to_i
139
- self.current_bet = tmp * 100
138
+ self.current_bet = STDIN.gets.to_i * 100
140
139
 
141
140
  normalize_current_bet
142
141
  deal_new_hand
143
142
  end
144
143
 
145
- def draw_game_options
146
- puts ' (N) Number of Decks (T) Deck Type (B) Back'
147
-
148
- loop do
149
- br = false
150
- case Blackjack.getc
151
- when 'n'
152
- br = true
153
- clear
154
- draw_hands
155
- new_num_decks
156
- when 't'
157
- br = true
158
- clear
159
- draw_hands
160
- new_deck_type
161
- clear
162
- draw_hands
163
- draw_bet_options
164
- when 'b'
165
- br = true
166
- clear
167
- draw_hands
168
- draw_bet_options
169
- else
170
- clear
171
- draw_hands
172
- draw_game_options
173
- end
174
-
175
- break if br
176
- end
177
- end
178
-
179
144
  def new_num_decks
180
145
  puts " Number Of Decks: #{num_decks}"
181
146
  print ' New Number Of Decks (1-8): '
182
147
  self.num_decks = STDIN.gets.to_i
183
148
 
184
149
  normalize_num_decks
185
-
186
- clear
187
- draw_hands
188
- draw_game_options
150
+ clear_draw_hands_game_options
189
151
  end
190
152
 
191
153
  def normalize_num_decks
@@ -193,62 +155,6 @@ class Blackjack
193
155
  self.num_decks = 8 if num_decks > 8
194
156
  end
195
157
 
196
- def new_deck_type
197
- puts ' (1) Regular (2) Aces (3) Jacks (4) Aces & Jacks (5) Sevens (6) Eights'
198
-
199
- loop do
200
- br = false
201
- case Blackjack.getc
202
- when '1'
203
- br = true
204
- shoe.new_regular
205
- when '2'
206
- br = true
207
- shoe.new_aces
208
- when '3'
209
- br = true
210
- shoe.new_jacks
211
- when '4'
212
- br = true
213
- shoe.new_aces_jacks
214
- when '5'
215
- br = true
216
- shoe.new_sevens
217
- when '6'
218
- br = true
219
- shoe.new_eights
220
- else
221
- clear
222
- draw_hands
223
- new_deck_type
224
- end
225
-
226
- break if br
227
- end
228
- end
229
-
230
- def ask_insurance
231
- puts ' Insurance? (Y) Yes (N) No'
232
-
233
- loop do
234
- br = false
235
- case Blackjack.getc
236
- when 'y'
237
- br = true
238
- insure_hand
239
- when 'n'
240
- br = true
241
- no_insurance
242
- else
243
- clear
244
- draw_hands
245
- ask_insurance
246
- end
247
-
248
- break if br
249
- end
250
- end
251
-
252
158
  def insure_hand
253
159
  player_hand = current_player_hand
254
160
  player_hand.bet /= 2
@@ -281,89 +187,18 @@ class Blackjack
281
187
  end
282
188
  end
283
189
 
284
- def play_dealer_hand
285
- dealer_hand.play
286
- draw_hands
287
- draw_bet_options
288
- end
289
-
290
- def split_current_hand
291
- if current_player_hand.can_split?
292
- player_hands << PlayerHand.new(self, current_bet)
293
-
294
- x = player_hands.size - 1
295
- while x > current_hand
296
- player_hands[x] = player_hands[x - 1].clone
297
- x -= 1
298
- end
299
-
300
- this_hand = player_hands[current_hand]
301
- split_hand = player_hands[current_hand + 1]
302
-
303
- split_hand.cards = []
304
- split_hand.cards << this_hand.cards.last
305
- this_hand.cards.pop
306
-
307
- this_hand.cards << shoe.next_card
308
- if this_hand.done?
309
- this_hand.process
310
- else
311
- draw_hands
312
- current_player_hand.action?
313
- end
314
- else
315
- draw_hands
316
- current_player_hand.action?
317
- end
318
- end
319
-
320
- def draw_bet_options
321
- puts ' (D) Deal Hand (B) Change Bet (O) Options (Q) Quit'
322
-
323
- loop do
324
- br = false
325
- case Blackjack.getc
326
- when 'd'
327
- br = true
328
- deal_new_hand
329
- when 'b'
330
- br = true
331
- new_bet
332
- when 'o'
333
- br = true
334
- clear
335
- draw_hands
336
- draw_game_options
337
- when 'q'
338
- clear
339
- exit
340
- else
341
- clear
342
- draw_hands
343
- draw_bet_options
344
- end
345
-
346
- break if br
347
- end
348
- end
349
-
350
190
  def all_bets
351
191
  player_hands.inject(0) { |sum, player_hand| sum + player_hand.bet }
352
192
  end
353
193
 
354
- def save_game
355
- File.open(SAVE_FILE, 'w') do |file|
356
- file.puts "#{num_decks}|#{money}|#{current_bet}"
194
+ def normalize_current_bet
195
+ if current_bet < MIN_BET
196
+ self.current_bet = MIN_BET
197
+ elsif current_bet > MAX_BET
198
+ self.current_bet = MAX_BET
357
199
  end
358
- end
359
-
360
- def load_game
361
- return unless File.readable?(SAVE_FILE)
362
200
 
363
- a = File.read(SAVE_FILE).split('|')
364
- self.num_decks = a[0].to_i
365
- self.money = a[1].to_i
366
- self.current_bet = a[2].to_i
201
+ self.current_bet = money if current_bet > money
367
202
  end
368
203
 
369
204
  def self.getc
@@ -375,8 +210,4 @@ class Blackjack
375
210
  end
376
211
  c.chr
377
212
  end
378
-
379
- def self.format_money(value)
380
- format('%.2f', value)
381
- end
382
213
  end