質問編集履歴

5

Code Block Mod

2018/04/14 15:37

投稿

songyong
songyong

score21

test CHANGED
File without changes
test CHANGED
@@ -38,10 +38,308 @@
38
38
 
39
39
  SyntaxError: unexpected EOF while parsing
40
40
 
41
+
42
+
41
43
  ### 該当のソースコード
42
44
 
45
+
46
+
43
47
  ```Python3
44
48
 
49
+ import random;
50
+
51
+ def win_lose(dealer_hand, player_hand, bet, player_money):
52
+
53
+ player_point = get_point(player_hand)
54
+
55
+ dealer_point = get_point(dealer_hand)
56
+
57
+ if player_point <= 21:
58
+
59
+ if (player_point > dealer_point) or (dealer_point > 21) :
60
+
61
+ if player_point == 21:
62
+
63
+ return('<<Player WIN !!>>',player_money + int(bet*2.5))
64
+
65
+ else:
66
+
67
+ return('<<Player WIN !!>>',player_money + bet*2)
68
+
69
+ elif player_point == dealer_point:
70
+
71
+ return('<<PUSH>>',player_money + bet)
72
+
73
+ else:
74
+
75
+ return('<<YOU LOSE>>', player_money)
76
+
77
+ else:
78
+
79
+ return('<<YOU LOSE>>', player_money)
80
+
81
+
82
+
83
+ def player_op(deck, player_hand, op):
84
+
85
+ doubled, ending = False, False
86
+
87
+ if op == '1':
88
+
89
+ print('[PLAYER : STAND]')
90
+
91
+ doubled, ending = False, True
92
+
93
+ print(op)
94
+
95
+ print(doubled)
96
+
97
+ print(ending)
98
+
99
+ import pdb; pdb.set_trace()
100
+
101
+ elif op == '2':
102
+
103
+ print('[PLAYER : HIT]')
104
+
105
+ player_hand.append(deck.pop())
106
+
107
+ print_player_hand(player_hand)
108
+
109
+ doubled, ending = False, False
110
+
111
+ elif op == '3':
112
+
113
+ if len(player_hand) == 2:
114
+
115
+ print('[PLAYER : DOUBLE]')
116
+
117
+ player_hand.append(deck.pop())
118
+
119
+ print_player_hand(player_hand)
120
+
121
+ doubled, ending = True, True
122
+
123
+ else:
124
+
125
+ print('(DOUBLE CAN NOT BE ENTERED)')
126
+
127
+
128
+
129
+ if get_point(player_hand) > 21:
130
+
131
+ print('[PLAYER BUSTED]')
132
+
133
+ ending = True
134
+
135
+ elif get_point(player_hand) == 21:
136
+
137
+ print('YOUR POINT IS 21')
138
+
139
+ ending = True
140
+
141
+
142
+
143
+ return doubled, ending
144
+
145
+
146
+
147
+ def dealer_op(deck,player_hand,dealer_hand):
148
+
149
+ while get_point(player_hand) <= 21:
150
+
151
+ if get_point(dealer_hand) >= 17:
152
+
153
+ print('[DEALER : STAND]')
154
+
155
+ break
156
+
157
+ else:
158
+
159
+ print('[DEALER : HIT]')
160
+
161
+ dealer_hand.append(deck.pop())
162
+
163
+ print_dealer_hand(dealer_hand, False)
164
+
165
+
166
+
167
+ def get_point(hand):
168
+
169
+ result = 0
170
+
171
+ ace_flag = False
172
+
173
+ for card in hand:
174
+
175
+
176
+
177
+ if card[RANK] == 1:
178
+
179
+ ace_flag = True
180
+
181
+
182
+
183
+ if card[RANK] > 10:
184
+
185
+ num = 10
186
+
187
+ else:
188
+
189
+ num = card[RANK]
190
+
191
+ result += num
192
+
193
+
194
+
195
+ if ace_flag and result <= 11:
196
+
197
+ result += 10
198
+
199
+ return result
200
+
201
+
202
+
203
+ def print_player_hand(player_hand):
204
+
205
+ print('PLAYER(', get_point(player_hand), '): ')
206
+
207
+ for card in player_hand:
208
+
209
+ print('[', card[SUIT], card[RANK], ']')
210
+
211
+ print()
212
+
213
+
214
+
215
+ def print_dealer_hand(dealer_hand, uncovered):
216
+
217
+ if uncovered:
218
+
219
+ print('DEALER(', get_point(dealer_hand), '): ')
220
+
221
+ else:
222
+
223
+ print('DEALER (??) : ')
224
+
225
+ flag = True
226
+
227
+ for card in dealer_hand:
228
+
229
+ if flag or uncovered:
230
+
231
+ print('[', card[SUIT], card[RANK], ']')
232
+
233
+ flag = False
234
+
235
+ print()
236
+
237
+
238
+
239
+ RANK , SUIT = 0,1
240
+
241
+
242
+
243
+ def make_deck():
244
+
245
+ suits = ['S','H','D','C']
246
+
247
+ ranks = range(1,14)
248
+
249
+ deck = [(x,y) for x in ranks for y in suits]
250
+
251
+ random.shuffle(deck)
252
+
253
+ return deck
254
+
255
+
256
+
257
+ def main():
258
+
259
+
260
+
261
+ turn = 1
262
+
263
+ player_money = 100
264
+
265
+ deck = make_deck()
266
+
267
+
268
+
269
+ while player_money > 0:
270
+
271
+
272
+
273
+ print('-'*20)
274
+
275
+ print('Turn', turn)
276
+
277
+ print('Amount:', player_money)
278
+
279
+ print('-'*20)
280
+
281
+
282
+
283
+ player_hand = []
284
+
285
+ dealer_hand = []
286
+
287
+
288
+
289
+ try:
290
+
291
+ bet = int(input('ベット額 >'))
292
+
293
+ except:
294
+
295
+ print('整数で入力してください')
296
+
297
+ continue
298
+
299
+
300
+
301
+ if bet > player_money:
302
+
303
+ print('所持金が不足しています')
304
+
305
+ elif bet <= 0:
306
+
307
+ print('ベットできる額は1円以上です')
308
+
309
+ continue
310
+
311
+
312
+
313
+ player_money -= bet
314
+
315
+ if len(deck) < 10:
316
+
317
+ deck = make_deck()
318
+
319
+
320
+
321
+ for i in range(2):
322
+
323
+ player_hand.append(deck.pop())
324
+
325
+ dealer_hand.append(deck.pop())
326
+
327
+
328
+
329
+
330
+
331
+ print('-'*20)
332
+
333
+ print_player_hand(player_hand)
334
+
335
+ print_dealer_hand(dealer_hand, False)
336
+
337
+ print('-'*20)
338
+
339
+
340
+
341
+
342
+
45
343
  while True:
46
344
 
47
345
  op = input('STAND:1, HIT:2, DOUBLE:3 > ')
@@ -60,418 +358,42 @@
60
358
 
61
359
 
62
360
 
63
-
64
-
361
+
362
+
65
- ### Source Code ALL
363
+ dealer_op(deck,player_hand,dealer_hand)
66
-
67
- ```Python3
364
+
68
-
365
+
366
+
69
- # -*-coding:utf-8-*-
367
+ print('-'*20)
70
-
71
-
72
-
368
+
73
- import random;
369
+ print_player_hand(player_hand)
74
-
75
-
76
-
370
+
77
- #勝敗判定とそれに伴って変化するチップを計算する関数(win_lose)の定義
371
+ print_dealer_hand(dealer_hand, True)
78
-
372
+
79
- ```Python3
373
+ print('-'*20)
80
-
374
+
375
+
376
+
377
+
378
+
81
- def win_lose(dealer_hand, player_hand, bet, player_money):
379
+ message,player_money = win_lose(dealer_hand,player_hand,bet,player_money)
82
-
380
+
83
- player_point = get_point(player_hand)
381
+ print(message)
84
-
382
+
383
+
384
+
85
- dealer_point = get_point(dealer_hand)
385
+ turn += 1
86
-
386
+
87
- if player_point <= 21:
387
+ input('次のターンへ')
88
-
89
- if (player_point > dealer_point) or (dealer_point > 21) :
388
+
90
-
389
+
390
+
91
- if player_point == 21:
391
+ print('ゲームオーバー')
92
-
93
- return('<<Player WIN !!>>',player_money + int(bet*2.5))
392
+
94
-
95
- else:
393
+
96
-
97
- return('<<Player WIN !!>>',player_money + bet*2)
394
+
98
-
99
- elif player_point == dealer_point:
395
+ if __name__ == '__main__':
100
-
101
- return('<<PUSH>>',player_money + bet)
396
+
102
-
103
- else:
397
+ main()
104
-
105
- return('<<YOU LOSE>>', player_money)
106
-
107
- else:
108
-
109
- return('<<YOU LOSE>>', player_money)
110
398
 
111
399
  ```
112
-
113
-
114
-
115
- ```Python3
116
-
117
- #プレイヤーの思考パターンを記述する関数(player_op)
118
-
119
- def player_op(deck, player_hand, op):
120
-
121
- doubled, ending = False, False
122
-
123
- if op == '1':
124
-
125
- print('[PLAYER : STAND]')
126
-
127
- doubled, ending = False, True
128
-
129
- print(op)
130
-
131
- print(doubled)
132
-
133
- print(ending)
134
-
135
- import pdb; pdb.set_trace()
136
-
137
- elif op == '2':
138
-
139
- print('[PLAYER : HIT]')
140
-
141
- player_hand.append(deck.pop())
142
-
143
- print_player_hand(player_hand)
144
-
145
- doubled, ending = False, False
146
-
147
- elif op == '3':
148
-
149
- if len(player_hand) == 2:
150
-
151
- print('[PLAYER : DOUBLE]')
152
-
153
- player_hand.append(deck.pop())
154
-
155
- print_player_hand(player_hand)
156
-
157
- doubled, ending = True, True
158
-
159
- else:
160
-
161
- print('(DOUBLE CAN NOT BE ENTERED)')
162
-
163
-
164
-
165
- if get_point(player_hand) > 21:
166
-
167
- print('[PLAYER BUSTED]')
168
-
169
- ending = True
170
-
171
- elif get_point(player_hand) == 21:
172
-
173
- print('YOUR POINT IS 21')
174
-
175
- ending = True
176
-
177
-
178
-
179
- return doubled, ending
180
-
181
-
182
-
183
- ```Python3
184
-
185
- ```Python3
186
-
187
- #ディーラーの思考パターンを記述する関数(dealer_op)
188
-
189
- def dealer_op(deck,player_hand,dealer_hand):
190
-
191
- while get_point(player_hand) <= 21:
192
-
193
- if get_point(dealer_hand) >= 17:
194
-
195
- print('[DEALER : STAND]')
196
-
197
- break
198
-
199
- else:
200
-
201
- print('[DEALER : HIT]')
202
-
203
- dealer_hand.append(deck.pop())
204
-
205
- print_dealer_hand(dealer_hand, False)
206
-
207
- ```
208
-
209
- ```
210
-
211
-
212
-
213
- #ポイントの換算をする関数(get_point)
214
-
215
- def get_point(hand):
216
-
217
- result = 0
218
-
219
- ace_flag = False
220
-
221
- for card in hand:
222
-
223
-
224
-
225
- if card[RANK] == 1:
226
-
227
- ace_flag = True
228
-
229
-
230
-
231
- if card[RANK] > 10:
232
-
233
- num = 10
234
-
235
- else:
236
-
237
- num = card[RANK]
238
-
239
- result += num
240
-
241
-
242
-
243
- if ace_flag and result <= 11:
244
-
245
- result += 10
246
-
247
- return result
248
-
249
- ```
250
-
251
- ```Python3
252
-
253
- #手札の情報を表示する関数(print_dealer_hand, print_player_hand)
254
-
255
-
256
-
257
- def print_player_hand(player_hand):
258
-
259
- print('PLAYER(', get_point(player_hand), '): ')
260
-
261
- for card in player_hand:
262
-
263
- print('[', card[SUIT], card[RANK], ']')
264
-
265
- print()
266
-
267
-
268
-
269
- def print_dealer_hand(dealer_hand, uncovered):
270
-
271
- if uncovered:
272
-
273
- print('DEALER(', get_point(dealer_hand), '): ')
274
-
275
- else:
276
-
277
- print('DEALER (??) : ')
278
-
279
- flag = True
280
-
281
- for card in dealer_hand:
282
-
283
- if flag or uncovered:
284
-
285
- print('[', card[SUIT], card[RANK], ']')
286
-
287
- flag = False
288
-
289
- print()
290
-
291
-
292
-
293
- ```
294
-
295
- ```Python3
296
-
297
- #使う変数の宣言(player_hand, player_money, dealer_hand)と制定変数(RANK, SUIT)
298
-
299
- RANK , SUIT = 0,1
300
-
301
-
302
-
303
- ```Python3
304
-
305
- ```#トランプのデッキを作ってシャッフルする関数(make_deck)の定義
306
-
307
- def make_deck():
308
-
309
- suits = ['S','H','D','C']
310
-
311
- ranks = range(1,14)
312
-
313
- deck = [(x,y) for x in ranks for y in suits]
314
-
315
- random.shuffle(deck)
316
-
317
- return deck
318
-
319
-
320
-
321
- ```
322
-
323
- ```Python3
324
-
325
- def main():
326
-
327
- #変数の初期化
328
-
329
- turn = 1
330
-
331
- player_money = 100
332
-
333
- deck = make_deck()
334
-
335
-
336
-
337
- while player_money > 0:
338
-
339
-
340
-
341
- #ターンの初めにターン数と所持金の情報を表示
342
-
343
- print('-'*20)
344
-
345
- print('Turn', turn)
346
-
347
- print('Amount:', player_money)
348
-
349
- print('-'*20)
350
-
351
-
352
-
353
- player_hand = []
354
-
355
- dealer_hand = []
356
-
357
-
358
-
359
- try:
360
-
361
- bet = int(input('ベット額 >'))
362
-
363
- except:
364
-
365
- print('整数で入力してください')
366
-
367
- continue
368
-
369
-
370
-
371
- if bet > player_money:
372
-
373
- print('所持金が不足しています')
374
-
375
- elif bet <= 0:
376
-
377
- print('ベットできる額は1円以上です')
378
-
379
- continue
380
-
381
-
382
-
383
- #ベットする額の選択とその対応
384
-
385
- player_money -= bet
386
-
387
- if len(deck) < 10:
388
-
389
- deck = make_deck()
390
-
391
-
392
-
393
- #お互いのカードを2枚ずつ引く
394
-
395
- for i in range(2):
396
-
397
- player_hand.append(deck.pop())
398
-
399
- dealer_hand.append(deck.pop())
400
-
401
-
402
-
403
- #手札の情報を表示
404
-
405
- print('-'*20)
406
-
407
- print_player_hand(player_hand)
408
-
409
- print_dealer_hand(dealer_hand, False)
410
-
411
- print('-'*20)
412
-
413
-
414
-
415
- #プレイヤーのターン
416
-
417
- while True:
418
-
419
- op = input('STAND:1, HIT:2, DOUBLE:3 > ')
420
-
421
- doubled, ending = player_op(deck, player_hand, op)
422
-
423
- if doubled:
424
-
425
- player_money -= bet
426
-
427
- bet += bet
428
-
429
- if ending:
430
-
431
- break
432
-
433
-
434
-
435
- #ディーラーのターン
436
-
437
- dealer_op(deck,player_hand,dealer_hand)
438
-
439
-
440
-
441
-
442
-
443
- #手札の公開
444
-
445
- print('-'*20)
446
-
447
- print_player_hand(player_hand)
448
-
449
- print_dealer_hand(dealer_hand, True)
450
-
451
- print('-'*20)
452
-
453
-
454
-
455
- #勝敗の判定
456
-
457
- message,player_money = win_lose(dealer_hand,player_hand,bet,player_money)
458
-
459
- print(message)
460
-
461
-
462
-
463
- turn += 1
464
-
465
- input('次のターンへ')
466
-
467
-
468
-
469
- print('ゲームオーバー')
470
-
471
-
472
-
473
- if __name__ == '__main__':
474
-
475
- main()
476
-
477
- ```

4

Python Ver Add

2018/04/14 15:37

投稿

songyong
songyong

score21

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- 環境はatomを使用しております。
11
+ 環境はatomを使用しております。Python 3.6.5
12
12
 
13
13
 
14
14
 

3

CodeBlock Mod

2018/04/14 15:30

投稿

songyong
songyong

score21

test CHANGED
File without changes
test CHANGED
@@ -112,6 +112,8 @@
112
112
 
113
113
 
114
114
 
115
+ ```Python3
116
+
115
117
  #プレイヤーの思考パターンを記述する関数(player_op)
116
118
 
117
119
  def player_op(deck, player_hand, op):
@@ -178,6 +180,10 @@
178
180
 
179
181
 
180
182
 
183
+ ```Python3
184
+
185
+ ```Python3
186
+
181
187
  #ディーラーの思考パターンを記述する関数(dealer_op)
182
188
 
183
189
  def dealer_op(deck,player_hand,dealer_hand):
@@ -198,6 +204,10 @@
198
204
 
199
205
  print_dealer_hand(dealer_hand, False)
200
206
 
207
+ ```
208
+
209
+ ```
210
+
201
211
 
202
212
 
203
213
  #ポイントの換算をする関数(get_point)
@@ -236,7 +246,9 @@
236
246
 
237
247
  return result
238
248
 
239
-
249
+ ```
250
+
251
+ ```Python3
240
252
 
241
253
  #手札の情報を表示する関数(print_dealer_hand, print_player_hand)
242
254
 
@@ -278,11 +290,19 @@
278
290
 
279
291
 
280
292
 
293
+ ```
294
+
295
+ ```Python3
296
+
281
297
  #使う変数の宣言(player_hand, player_money, dealer_hand)と制定変数(RANK, SUIT)
282
298
 
283
299
  RANK , SUIT = 0,1
284
300
 
301
+
302
+
303
+ ```Python3
304
+
285
- #トランプのデッキを作ってシャッフルする関数(make_deck)の定義
305
+ ```#トランプのデッキを作ってシャッフルする関数(make_deck)の定義
286
306
 
287
307
  def make_deck():
288
308
 
@@ -298,6 +318,10 @@
298
318
 
299
319
 
300
320
 
321
+ ```
322
+
323
+ ```Python3
324
+
301
325
  def main():
302
326
 
303
327
  #変数の初期化

2

コードブロックの修正

2018/04/14 15:22

投稿

songyong
songyong

score21

test CHANGED
File without changes
test CHANGED
@@ -76,6 +76,8 @@
76
76
 
77
77
  #勝敗判定とそれに伴って変化するチップを計算する関数(win_lose)の定義
78
78
 
79
+ ```Python3
80
+
79
81
  def win_lose(dealer_hand, player_hand, bet, player_money):
80
82
 
81
83
  player_point = get_point(player_hand)
@@ -106,6 +108,8 @@
106
108
 
107
109
  return('<<YOU LOSE>>', player_money)
108
110
 
111
+ ```
112
+
109
113
 
110
114
 
111
115
  #プレイヤーの思考パターンを記述する関数(player_op)

1

コードブロックを修正。

2018/04/14 15:08

投稿

songyong
songyong

score21

test CHANGED
File without changes
test CHANGED
@@ -8,6 +8,10 @@
8
8
 
9
9
 
10
10
 
11
+ 環境はatomを使用しております。
12
+
13
+
14
+
11
15
  ### 発生している問題・エラーメッセージ
12
16
 
13
17
  STAND:1, HIT:2, DOUBLE:3 > 1
@@ -36,7 +40,7 @@
36
40
 
37
41
  ### 該当のソースコード
38
42
 
39
-
43
+ ```Python3
40
44
 
41
45
  while True:
42
46
 
@@ -58,11 +62,9 @@
58
62
 
59
63
 
60
64
 
65
+ ### Source Code ALL
66
+
61
- ```パイソン3
67
+ ```Python3
62
-
63
- ソースコード
64
-
65
-
66
68
 
67
69
  # -*-coding:utf-8-*-
68
70
 
@@ -443,3 +445,5 @@
443
445
  if __name__ == '__main__':
444
446
 
445
447
  main()
448
+
449
+ ```