hazama_kuroo 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0d545f3eca90220fc0d1ac9de54de30422905e8cebdf870cc80ac8a7a761d0b
4
- data.tar.gz: 9e86136acf7975b6f7034f9217e620013baea6a8e74423064d7c0435d119b848
3
+ metadata.gz: 0cbf6d04d5196b2969f36c1a85c902ec7cb458beeee9127dc7425684ff03bef1
4
+ data.tar.gz: 4c13a822d68055f0192e051d309b6d0ff7097f783d1a98948055c24a3e0b2e50
5
5
  SHA512:
6
- metadata.gz: 87ba636df1ad7eb3073fd3b81b491ba1b5f85d8baa5f56d7cf4f82ab329de4388883b48ac37a7dfed2fbd42da9f72dd3ec0e72b0a2281ff59ecb5f8fa888413c
7
- data.tar.gz: 94db9a64bf3e24b09fd78e1345681627d36624c94c9f02deceb932e59de01e8ff2f6b377e70e532829f9e32ad52834f5c28fa8aa553293950f9690aba6b30e88
6
+ metadata.gz: a4750a94114732d51832fbccfc2c33973d6a5f8cb697e637d7017189d5ba032c10da65fe31e2ad6de6df1eaafef35cb9e43b188342b021861b48e86a4076a11e
7
+ data.tar.gz: 3b0ae5c5d1f2fc9859d53b114dc83b957c829c8a279ebf89921d740c95a3498ba79022b04b519c0ed123f868f4bbbb18401e54ad5411bebecc194e5d80a35a77
@@ -1,3 +1,3 @@
1
1
  module HazamaKuroo
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/hazama_kuroo.rb CHANGED
@@ -4,34 +4,31 @@ require "hazama_kuroo/version"
4
4
  module HazamaKuroo
5
5
  # 実行メソッド
6
6
  def self.run
7
- cards = generate_cards
7
+ cs = gen
8
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]
9
+ hk = dft cs
10
+ puts "HZM: #{hk[0][0]} ***"
11
+ yu = dft cs
12
+ puts "YOU: #{yu[0][0]} #{yu[1][0]}"
13
+ ooe yu[0]
14
+ sio yu[0]
15
+ ooe yu[1]
16
+ sio yu[1]
17
17
 
18
- flg = 1
19
- while flg
20
- puts 'Hit? [y/n]'
21
- while str = gets
22
- case str.chomp
18
+ f = 1
19
+ while f do
20
+ print 'Hit? [y/n] '
21
+ while s = gets do
22
+ case s.chomp
23
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
24
+ yu << (deal cs)
25
+ puts "YOU: #{yu[-1][0]}"
26
+ ooe yu[-1]
27
+ sio yu[-1]
28
+ (puts 'Lose'; f = false) if 21 < (sum yu)
32
29
  when 'n'
33
- stand you, dealer, cards
34
- flg = false
30
+ std yu, hk, cs
31
+ f = false
35
32
  else
36
33
  puts ope
37
34
  exit
@@ -42,7 +39,7 @@ module HazamaKuroo
42
39
  end
43
40
 
44
41
  # カードを 52 枚用意する
45
- def self.generate_cards
42
+ def self.gen
46
43
  ms = %w[S C H D]
47
44
  c = []
48
45
  ms.each do |m|
@@ -67,29 +64,27 @@ module HazamaKuroo
67
64
  end
68
65
 
69
66
  # 初期デッキを作る
70
- def self.default_deck cs
67
+ def self.dft cs
71
68
  [] << (deal cs) << (deal cs)
72
69
  end
73
70
 
74
71
  # カードを配る
75
72
  def self.deal cs
76
- while 1
73
+ while 1 do
77
74
  m = rand(4)
78
75
  n = rand(11)
79
- if 1 != cs[m][n][2]
80
- cs[m][n][2] = 1
81
- break
82
- end
76
+ (cs[m][n][2] = 1; break) if 0 == cs[m][n][2]
83
77
  end
84
78
  cs[m][n]
85
79
  end
86
80
 
87
81
  # Ace をどうするか
88
- def self.one_or_eleven a
82
+ def self.ooe a
89
83
  if 'A' == a[1] && 0 == a[3]
90
- puts "Is #{a[0]} 1 or 11?"
91
- str = gets
92
- case str.chomp
84
+
85
+ print "#{a[0]}? [1/11] "
86
+ s = gets
87
+ case s.chomp
93
88
  when '1'
94
89
  a[1] = 1
95
90
  when '11'
@@ -102,7 +97,7 @@ module HazamaKuroo
102
97
  end
103
98
 
104
99
  # 不正操作だったら強制終了
105
- def self.stop_if_ope c
100
+ def self.sio c
106
101
  if c[1].nil?
107
102
  puts ope
108
103
  exit
@@ -110,10 +105,10 @@ module HazamaKuroo
110
105
  end
111
106
 
112
107
  # 勝負する
113
- def self.stand y, d, cs
108
+ def self.std y, d, cs
114
109
  a = sum y
115
110
  puts "Hole Card: #{d[1][0]}"
116
- b = deal_by_dealer d, cs
111
+ b = dbd d, cs, a
117
112
  if 21 < b || b < a
118
113
  puts 'Win!'
119
114
  elsif a < b
@@ -133,26 +128,14 @@ module HazamaKuroo
133
128
  end
134
129
 
135
130
  # stand 後のディーラーの作業
136
- def self.deal_by_dealer d, cs
131
+ def self.dbd d, cs, a
137
132
  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
133
+ s = d[0][1] + ('A' == d[1][1] ? (11 == d[0][1] ? 1 : 11) : d[1][1])
147
134
 
148
- while s < 17
135
+ while s < 17 || s <= a do
149
136
  t = deal cs
150
137
  puts "HZM: #{t[0]}"
151
- if 'A' == t[1]
152
- s += 1
153
- else
154
- s += t[1]
155
- end
138
+ s += ('A' == t[1] ? (s < 10 ? 11 : 1) : t[1])
156
139
  end
157
140
  s
158
141
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hazama_kuroo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - jinroq