teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

Code Block Mod

2018/04/14 15:37

投稿

songyong
songyong

スコア21

title CHANGED
File without changes
body CHANGED
@@ -18,26 +18,11 @@
18
18
 
19
19
  ^
20
20
  SyntaxError: unexpected EOF while parsing
21
+
21
22
  ### 該当のソースコード
22
- ```Python3
23
- while True:
24
- op = input('STAND:1, HIT:2, DOUBLE:3 > ')
25
- doubled, ending = player_op(deck, player_hand, op)
26
- if doubled:
27
- player_money -= bet
28
- bet += bet
29
- if ending:
30
- break
31
23
 
32
-
33
- ### Source Code ALL
34
24
  ```Python3
35
- # -*-coding:utf-8-*-
36
-
37
25
  import random;
38
-
39
- #勝敗判定とそれに伴って変化するチップを計算する関数(win_lose)の定義
40
- ```Python3
41
26
  def win_lose(dealer_hand, player_hand, bet, player_money):
42
27
  player_point = get_point(player_hand)
43
28
  dealer_point = get_point(dealer_hand)
@@ -53,10 +38,7 @@
53
38
  return('<<YOU LOSE>>', player_money)
54
39
  else:
55
40
  return('<<YOU LOSE>>', player_money)
56
- ```
57
41
 
58
- ```Python3
59
- #プレイヤーの思考パターンを記述する関数(player_op)
60
42
  def player_op(deck, player_hand, op):
61
43
  doubled, ending = False, False
62
44
  if op == '1':
@@ -89,9 +71,6 @@
89
71
 
90
72
  return doubled, ending
91
73
 
92
- ```Python3
93
- ```Python3
94
- #ディーラーの思考パターンを記述する関数(dealer_op)
95
74
  def dealer_op(deck,player_hand,dealer_hand):
96
75
  while get_point(player_hand) <= 21:
97
76
  if get_point(dealer_hand) >= 17:
@@ -101,10 +80,7 @@
101
80
  print('[DEALER : HIT]')
102
81
  dealer_hand.append(deck.pop())
103
82
  print_dealer_hand(dealer_hand, False)
104
- ```
105
- ```
106
83
 
107
- #ポイントの換算をする関数(get_point)
108
84
  def get_point(hand):
109
85
  result = 0
110
86
  ace_flag = False
@@ -122,9 +98,6 @@
122
98
  if ace_flag and result <= 11:
123
99
  result += 10
124
100
  return result
125
- ```
126
- ```Python3
127
- #手札の情報を表示する関数(print_dealer_hand, print_player_hand)
128
101
 
129
102
  def print_player_hand(player_hand):
130
103
  print('PLAYER(', get_point(player_hand), '): ')
@@ -144,13 +117,8 @@
144
117
  flag = False
145
118
  print()
146
119
 
147
- ```
148
- ```Python3
149
- #使う変数の宣言(player_hand, player_money, dealer_hand)と制定変数(RANK, SUIT)
150
120
  RANK , SUIT = 0,1
151
121
 
152
- ```Python3
153
- ```#トランプのデッキを作ってシャッフルする関数(make_deck)の定義
154
122
  def make_deck():
155
123
  suits = ['S','H','D','C']
156
124
  ranks = range(1,14)
@@ -158,17 +126,14 @@
158
126
  random.shuffle(deck)
159
127
  return deck
160
128
 
161
- ```
162
- ```Python3
163
129
  def main():
164
- #変数の初期化
130
+
165
131
  turn = 1
166
132
  player_money = 100
167
133
  deck = make_deck()
168
134
 
169
135
  while player_money > 0:
170
136
 
171
- #ターンの初めにターン数と所持金の情報を表示
172
137
  print('-'*20)
173
138
  print('Turn', turn)
174
139
  print('Amount:', player_money)
@@ -189,23 +154,21 @@
189
154
  print('ベットできる額は1円以上です')
190
155
  continue
191
156
 
192
- #ベットする額の選択とその対応
193
157
  player_money -= bet
194
158
  if len(deck) < 10:
195
159
  deck = make_deck()
196
160
 
197
- #お互いのカードを2枚ずつ引く
198
161
  for i in range(2):
199
162
  player_hand.append(deck.pop())
200
163
  dealer_hand.append(deck.pop())
201
164
 
202
- #手札の情報を表示
165
+
203
166
  print('-'*20)
204
167
  print_player_hand(player_hand)
205
168
  print_dealer_hand(dealer_hand, False)
206
169
  print('-'*20)
207
170
 
208
- #プレイヤーのターン
171
+
209
172
  while True:
210
173
  op = input('STAND:1, HIT:2, DOUBLE:3 > ')
211
174
  doubled, ending = player_op(deck, player_hand, op)
@@ -215,17 +178,15 @@
215
178
  if ending:
216
179
  break
217
180
 
218
- #ディーラーのターン
181
+
219
182
  dealer_op(deck,player_hand,dealer_hand)
220
183
 
221
-
222
- #手札の公開
223
184
  print('-'*20)
224
185
  print_player_hand(player_hand)
225
186
  print_dealer_hand(dealer_hand, True)
226
187
  print('-'*20)
227
188
 
228
- #勝敗の判定
189
+
229
190
  message,player_money = win_lose(dealer_hand,player_hand,bet,player_money)
230
191
  print(message)
231
192
 

4

Python Ver Add

2018/04/14 15:37

投稿

songyong
songyong

スコア21

title CHANGED
File without changes
body CHANGED
@@ -3,7 +3,7 @@
3
3
  ブラックジャックゲームを作成しています。
4
4
  実行時にエラーが発生します。スタンドかヒットかダブルかをインプットで数字を入力したあと、後続の処理に進みません。
5
5
 
6
- 環境はatomを使用しております。
6
+ 環境はatomを使用しております。Python 3.6.5
7
7
 
8
8
  ### 発生している問題・エラーメッセージ
9
9
  STAND:1, HIT:2, DOUBLE:3 > 1

3

CodeBlock Mod

2018/04/14 15:30

投稿

songyong
songyong

スコア21

title CHANGED
File without changes
body CHANGED
@@ -55,6 +55,7 @@
55
55
  return('<<YOU LOSE>>', player_money)
56
56
  ```
57
57
 
58
+ ```Python3
58
59
  #プレイヤーの思考パターンを記述する関数(player_op)
59
60
  def player_op(deck, player_hand, op):
60
61
  doubled, ending = False, False
@@ -88,6 +89,8 @@
88
89
 
89
90
  return doubled, ending
90
91
 
92
+ ```Python3
93
+ ```Python3
91
94
  #ディーラーの思考パターンを記述する関数(dealer_op)
92
95
  def dealer_op(deck,player_hand,dealer_hand):
93
96
  while get_point(player_hand) <= 21:
@@ -98,6 +101,8 @@
98
101
  print('[DEALER : HIT]')
99
102
  dealer_hand.append(deck.pop())
100
103
  print_dealer_hand(dealer_hand, False)
104
+ ```
105
+ ```
101
106
 
102
107
  #ポイントの換算をする関数(get_point)
103
108
  def get_point(hand):
@@ -117,7 +122,8 @@
117
122
  if ace_flag and result <= 11:
118
123
  result += 10
119
124
  return result
120
-
125
+ ```
126
+ ```Python3
121
127
  #手札の情報を表示する関数(print_dealer_hand, print_player_hand)
122
128
 
123
129
  def print_player_hand(player_hand):
@@ -138,9 +144,13 @@
138
144
  flag = False
139
145
  print()
140
146
 
147
+ ```
148
+ ```Python3
141
149
  #使う変数の宣言(player_hand, player_money, dealer_hand)と制定変数(RANK, SUIT)
142
150
  RANK , SUIT = 0,1
151
+
152
+ ```Python3
143
- #トランプのデッキを作ってシャッフルする関数(make_deck)の定義
153
+ ```#トランプのデッキを作ってシャッフルする関数(make_deck)の定義
144
154
  def make_deck():
145
155
  suits = ['S','H','D','C']
146
156
  ranks = range(1,14)
@@ -148,6 +158,8 @@
148
158
  random.shuffle(deck)
149
159
  return deck
150
160
 
161
+ ```
162
+ ```Python3
151
163
  def main():
152
164
  #変数の初期化
153
165
  turn = 1

2

コードブロックの修正

2018/04/14 15:22

投稿

songyong
songyong

スコア21

title CHANGED
File without changes
body CHANGED
@@ -37,6 +37,7 @@
37
37
  import random;
38
38
 
39
39
  #勝敗判定とそれに伴って変化するチップを計算する関数(win_lose)の定義
40
+ ```Python3
40
41
  def win_lose(dealer_hand, player_hand, bet, player_money):
41
42
  player_point = get_point(player_hand)
42
43
  dealer_point = get_point(dealer_hand)
@@ -52,6 +53,7 @@
52
53
  return('<<YOU LOSE>>', player_money)
53
54
  else:
54
55
  return('<<YOU LOSE>>', player_money)
56
+ ```
55
57
 
56
58
  #プレイヤーの思考パターンを記述する関数(player_op)
57
59
  def player_op(deck, player_hand, op):

1

コードブロックを修正。

2018/04/14 15:08

投稿

songyong
songyong

スコア21

title CHANGED
File without changes
body CHANGED
@@ -3,6 +3,8 @@
3
3
  ブラックジャックゲームを作成しています。
4
4
  実行時にエラーが発生します。スタンドかヒットかダブルかをインプットで数字を入力したあと、後続の処理に進みません。
5
5
 
6
+ 環境はatomを使用しております。
7
+
6
8
  ### 発生している問題・エラーメッセージ
7
9
  STAND:1, HIT:2, DOUBLE:3 > 1
8
10
  STAND:1, HIT:2, DOUBLE:3 > 1
@@ -17,7 +19,7 @@
17
19
  ^
18
20
  SyntaxError: unexpected EOF while parsing
19
21
  ### 該当のソースコード
20
-
22
+ ```Python3
21
23
  while True:
22
24
  op = input('STAND:1, HIT:2, DOUBLE:3 > ')
23
25
  doubled, ending = player_op(deck, player_hand, op)
@@ -28,9 +30,8 @@
28
30
  break
29
31
 
30
32
 
33
+ ### Source Code ALL
31
- ```パイソン3
34
+ ```Python3
32
- ソースコード
33
-
34
35
  # -*-coding:utf-8-*-
35
36
 
36
37
  import random;
@@ -220,4 +221,5 @@
220
221
  print('ゲームオーバー')
221
222
 
222
223
  if __name__ == '__main__':
223
- main()
224
+ main()
225
+ ```