hazama_kuroo 0.1.0 → 0.2.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: 555c43e928150202ed4223b1138317e10e0d813fec57df78ad12135912c348f0
4
- data.tar.gz: 798117cfbe4ccda35fb747a20370202a8005f279cc0fb8001936ea3a0199a909
3
+ metadata.gz: b0d545f3eca90220fc0d1ac9de54de30422905e8cebdf870cc80ac8a7a761d0b
4
+ data.tar.gz: 9e86136acf7975b6f7034f9217e620013baea6a8e74423064d7c0435d119b848
5
5
  SHA512:
6
- metadata.gz: 1b74232780e0859dd444a501a4c0f01f929b42868168b622e605e0483796e9b475ea924ebae9bd1d127b1d193c78fff0ca109da598dff352f0a57388038bb134
7
- data.tar.gz: e1410c0724812471e453817a59bcdb1be1f632a3269248139d7c439a266c89e6d4f8337972cd1f316e1148329862ac309591c86bae3636ace6919b886ccb98c4
6
+ metadata.gz: 87ba636df1ad7eb3073fd3b81b491ba1b5f85d8baa5f56d7cf4f82ab329de4388883b48ac37a7dfed2fbd42da9f72dd3ec0e72b0a2281ff59ecb5f8fa888413c
7
+ data.tar.gz: 94db9a64bf3e24b09fd78e1345681627d36624c94c9f02deceb932e59de01e8ff2f6b377e70e532829f9e32ad52834f5c28fa8aa553293950f9690aba6b30e88
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # HazamaKuroo
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hazama_kuroo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ This gem is very simple Blackjack.
6
4
 
7
5
  ## Installation
8
6
 
data/exe/kuroo ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'hazama_kuroo'
3
+ HazamaKuroo.run
data/lib/hazama_kuroo.rb CHANGED
@@ -1,9 +1,164 @@
1
+ # coding: utf-8
1
2
  require "hazama_kuroo/version"
2
3
 
3
4
  module HazamaKuroo
4
- class Error < StandardError; end
5
+ # 実行メソッド
6
+ def self.run
7
+ cards = generate_cards
8
+ puts 'Game Start'
9
+ dealer = default_deck cards
10
+ puts "HZM: #{dealer[0][0]} ***"
11
+ you = default_deck cards
12
+ puts "YOU: #{you[0][0]} #{you[1][0]}"
13
+ one_or_eleven you[0]
14
+ stop_if_ope you[0]
15
+ one_or_eleven you[1]
16
+ stop_if_ope you[1]
5
17
 
6
- def self.greet
7
- puts("I am HAZAMA Kuroo.")
18
+ flg = 1
19
+ while flg
20
+ puts 'Hit? [y/n]'
21
+ while str = gets
22
+ case str.chomp
23
+ when 'y'
24
+ you << (deal cards)
25
+ puts "YOU: #{you[-1][0]}"
26
+ one_or_eleven you[-1]
27
+ stop_if_ope you[-1]
28
+ if 21 < (sum you)
29
+ puts lose
30
+ flg = false
31
+ end
32
+ when 'n'
33
+ stand you, dealer, cards
34
+ flg = false
35
+ else
36
+ puts ope
37
+ exit
38
+ end
39
+ break
40
+ end
41
+ end
42
+ end
43
+
44
+ # カードを 52 枚用意する
45
+ def self.generate_cards
46
+ ms = %w[S C H D]
47
+ c = []
48
+ ms.each do |m|
49
+ ns = []
50
+ [*1..13].each do |n|
51
+ case n
52
+ when 1
53
+ ns << ([] << "#{m}-A" << 'A' << 0 << 0)
54
+ when 11
55
+ ns << ([] << "#{m}-J" << 10 << 0)
56
+ when 12
57
+ ns << ([] << "#{m}-Q" << 10 << 0)
58
+ when 13
59
+ ns << ([] << "#{m}-K" << 10 << 0)
60
+ else
61
+ ns << ([] << "#{m}-#{n}" << n << 0)
62
+ end
63
+ end
64
+ c << ns
65
+ end
66
+ c
67
+ end
68
+
69
+ # 初期デッキを作る
70
+ def self.default_deck cs
71
+ [] << (deal cs) << (deal cs)
72
+ end
73
+
74
+ # カードを配る
75
+ def self.deal cs
76
+ while 1
77
+ m = rand(4)
78
+ n = rand(11)
79
+ if 1 != cs[m][n][2]
80
+ cs[m][n][2] = 1
81
+ break
82
+ end
83
+ end
84
+ cs[m][n]
85
+ end
86
+
87
+ # Ace をどうするか
88
+ def self.one_or_eleven a
89
+ if 'A' == a[1] && 0 == a[3]
90
+ puts "Is #{a[0]} 1 or 11?"
91
+ str = gets
92
+ case str.chomp
93
+ when '1'
94
+ a[1] = 1
95
+ when '11'
96
+ a[1] = 11
97
+ else
98
+ a[1] = nil
99
+ end
100
+ a[3] = 1
101
+ end
102
+ end
103
+
104
+ # 不正操作だったら強制終了
105
+ def self.stop_if_ope c
106
+ if c[1].nil?
107
+ puts ope
108
+ exit
109
+ end
110
+ end
111
+
112
+ # 勝負する
113
+ def self.stand y, d, cs
114
+ a = sum y
115
+ puts "Hole Card: #{d[1][0]}"
116
+ b = deal_by_dealer d, cs
117
+ if 21 < b || b < a
118
+ puts 'Win!'
119
+ elsif a < b
120
+ puts 'Lose'
121
+ else
122
+ puts 'Draw'
123
+ end
124
+ end
125
+
126
+ # 合計
127
+ def self.sum a
128
+ s = 0
129
+ a.each do |b|
130
+ s += b[1]
131
+ end
132
+ s
133
+ end
134
+
135
+ # stand 後のディーラーの作業
136
+ def self.deal_by_dealer d, cs
137
+ d[0][1] = 11 if 'A' == d[0][1]
138
+ if 'A' == d[1][1]
139
+ if 11 == d[0][1]
140
+ s = d[0][1] + 1
141
+ else
142
+ s = d[0][1] + 11
143
+ end
144
+ else
145
+ s = d[0][1] + d[1][1]
146
+ end
147
+
148
+ while s < 17
149
+ t = deal cs
150
+ puts "HZM: #{t[0]}"
151
+ if 'A' == t[1]
152
+ s += 1
153
+ else
154
+ s += t[1]
155
+ end
156
+ end
157
+ s
158
+ end
159
+
160
+ # 不正操作
161
+ def self.ope
162
+ 'Failed The Ops.'
8
163
  end
9
164
  end
@@ -1,3 +1,3 @@
1
1
  module HazamaKuroo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hazama_kuroo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jinroq
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-27 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,7 +55,8 @@ dependencies:
55
55
  description: This is a sample gem. However, it may evolve someday.
56
56
  email:
57
57
  - jinroq@gmail.com
58
- executables: []
58
+ executables:
59
+ - kuroo
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
@@ -69,6 +70,7 @@ files:
69
70
  - Rakefile
70
71
  - bin/console
71
72
  - bin/setup
73
+ - exe/kuroo
72
74
  - hazama_kuroo.gemspec
73
75
  - lib/hazama_kuroo.rb
74
76
  - lib/hazama_kuroo/version.rb