質問編集履歴

2

tuiki

2018/10/16 04:48

投稿

Untitled_Sample
Untitled_Sample

スコア192

test CHANGED
File without changes
test CHANGED
@@ -210,7 +210,7 @@
210
210
 
211
211
  # if x=='user01':if 'id02'==i and y in (2) and Flag in (1):#1
212
212
 
213
- # if x=='user02':if 'id02'==i and y in (2) and Flag in (2):#0
213
+ # if x=='user02':if 'id02'==i and y in (2) and Flag in (0):#0
214
214
 
215
215
  if 'id03'==i and y in (2,3):#1
216
216
 

1

変更

2018/10/16 04:48

投稿

Untitled_Sample
Untitled_Sample

スコア192

test CHANGED
File without changes
test CHANGED
@@ -1,14 +1,20 @@
1
+ 街コロ
2
+
3
+ https://ja.wikipedia.org/wiki/%E8%A1%97%E3%82%B3%E3%83%AD
4
+
5
+
6
+
7
+ 上記のテーブルゲームをコンソールで作成してますが、
8
+
1
- 1,0でユザーを共通化したいと思いした
9
+ 誰のタンか判別する仕組みが分かりせん
2
-
3
-
4
-
5
- 1=自分自身
10
+
6
-
7
- 0=相手
11
+
8
-
9
-
10
-
12
+
13
+
14
+
11
- #サプル
15
+ コードの中盤にコメトで描いてます。
16
+
17
+
12
18
 
13
19
  ```python
14
20
 
@@ -16,66 +22,352 @@
16
22
 
17
23
 
18
24
 
25
+
26
+
27
+ # 0=誰のターンでも可能
28
+
29
+ # 1=自分のターン
30
+
31
+ # 2=相手のターン Other
32
+
33
+
34
+
35
+
36
+
37
+ l=[
38
+
39
+ # id 購入費用 誰のターン有効か012 出目 報酬
40
+
41
+ [['id01'],[999],[0],[1],[1]],#購入不可 全ユーザに初期配置 1coin 1result Anyone 1blessing
42
+
43
+ [['id02'],[1],[0],[2],[1]],# 1coin 2result Anyone 1blessing
44
+
45
+ [['id03'],[1],[1],[2,3],[1]],# 1coin 2,3result Myself 1blessing
46
+
47
+ [['id04'],[2],[2],[3],[1]],# 1coin 1,2,3,4,5,6result Other 1blessing
48
+
49
+ [['id05'],[2],[1],[4],[3]],#3coin 4result myself 3blessing
50
+
51
+ [['id06'],[3],[0],[5],[1]],#1coin 5result 1blessing
52
+
53
+ [['id07'],[5],[1],[7],[3]],#5coin 7result myself id02*3blessing
54
+
55
+ [['id08'],[3],[1],[8],[3]],#3coin 8result myself (id06+id09)*3blessing
56
+
57
+ [['id09'],[6],[0],[9],[5]],#6coin 9result 5blessing
58
+
59
+ [['id10'],[3],[0],[9,10],[2]],#3coin 9,10result 2blessing
60
+
61
+ [['id11'],[3],[0],[10],[3]],#3coin 10result 3blessing
62
+
63
+ [['id12'],[2],[1],[11,12],[2]],#2coin 11,12result 2blessing (id11+id12)*2blessing
64
+
65
+
66
+
67
+ [['id13'],[6],[1],[6],[2]],#2coin oll 6result 2blessing 全員から
68
+
69
+ [['id14'],[6],[1],[6],[5]],#6coin 6result 5blessing 相手指定 5coin貰う
70
+
71
+ #[['id15'],[6],[1],[6],['-']],#6coin 6result 建物を1つ交換 未実装
72
+
73
+
74
+
75
+ [['id20'],[4],[1],[0],[0]],#4coin 効果:(常時)ダイスを2個同時に振れる
76
+
77
+ [['id21'],[10],[1],[6],[5]],#10coin 効果:(常時)自分の【飲食店】と【商店】で得られるコインを+1する
78
+
79
+ [['id22'],[16],[1],[6],[5]],#16coin 効果:(常時)ぞろ目を出したらもう一度自分のターン
80
+
81
+ [['id23'],[22],[1],[0],[0]],#22coin 効果:(常時)毎ターン一度だけダイスを振り直せる
82
+
83
+ ]
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+ #1,2 user
92
+
93
+ user01=[['id01'],[3]]
94
+
95
+ user02=[['id01'],[3]]
96
+
97
+
98
+
99
+
100
+
101
+ import random
102
+
103
+ saicoro=random.randint(1,6)
104
+
105
+
106
+
107
+ from pprint import pprint
108
+
109
+
110
+
111
+
112
+
113
+ #print(l[1][2][0]) # 0
114
+
115
+ #print(user01[1][0]) #3
116
+
117
+ #print(l[1][0][0]) #id01
118
+
119
+ #print(l[1][1][0]) # 1
120
+
121
+
122
+
123
+ # 購入とカードの追加 簡易 後処理必要
124
+
125
+ def Sample01_Demo01(x,y):
126
+
127
+ try:
128
+
129
+ if x[1][0]-l[y][1][0]>=0:
130
+
131
+ x[1][0]=x[1][0]-l[y][1][0]
132
+
133
+ x[0].append(l[y][0][0])
134
+
135
+ except:
136
+
137
+ pass
138
+
139
+
140
+
141
+
142
+
19
- def Sample01(x):
143
+ #def Sample01_Demo02(x):
144
+
145
+
146
+
147
+
148
+
149
+
150
+
20
-
151
+ # 購入費用が足りてれば購入 yで継続 Enterでターンエンド
152
+
153
+ def Sample01_Demo02(xxx):
154
+
155
+ xyz=input()
156
+
157
+ try:
158
+
159
+ if xyz.isdecimal()==True:
160
+
161
+ Sample01_Demo01(xxx,int(xyz))
162
+
163
+ print(xxx)
164
+
165
+
166
+
167
+ Bu=input()
168
+
169
+ if Bu=='y':
170
+
171
+ Sample01_Demo02(xxx)
172
+
173
+ else:
174
+
175
+ pass
176
+
177
+
178
+
179
+ except TypeError:
180
+
181
+ pass
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+ # x=user01 y=saicoro z=Flag 01
190
+
191
+ def Sample01_Demo03(x,y,z):
192
+
193
+
194
+
195
+ for i in x[0]:
196
+
197
+ if 'id01'==i:#0
198
+
199
+ if 0==x[1][0]:
200
+
201
+ x[1][0]+=1
202
+
203
+
204
+
205
+ if 'id02'==i and y in (2):#0
206
+
207
+ x[1][0]+=1
208
+
209
+ # userによって、自分自身を表す。Flagの値が変化してしまう。
210
+
211
+ # if x=='user01':if 'id02'==i and y in (2) and Flag in (1):#1
212
+
213
+ # if x=='user02':if 'id02'==i and y in (2) and Flag in (2):#0
214
+
215
+ if 'id03'==i and y in (2,3):#1
216
+
217
+ x[1][0]+=1
218
+
219
+ if 'id04'==i and y in (3):#2
220
+
221
+ x[1][0]+=1
222
+
223
+ if 'id05'==i and y in (4):#1
224
+
225
+ x[1][0]+=3
226
+
227
+ if 'id06'==i and y in (5):#0
228
+
229
+ x[1][0]+=1
230
+
231
+ if 'id07'==i and y in (7):#1
232
+
233
+ x[1][0]+=3
234
+
235
+ if 'id08'==i and y in (8):#1
236
+
237
+ x[1][0]+=3
238
+
239
+ if 'id09'==i and y in (9):#1
240
+
241
+ x[1][0]+=5
242
+
243
+ if 'id10'==i and y in (9,10):#2
244
+
245
+ x[1][0]+=2
246
+
247
+ if 'id11'==i and y in (10):#0
248
+
249
+ x[1][0]+=3
250
+
251
+ if 'id12'==i and y in (11,12):#1
252
+
253
+ x[1][0]+=2
254
+
255
+
256
+
257
+ if 'id13'==i and y in (6):#
258
+
259
+ x[1][0]+=2
260
+
261
+ if 'id14'==i and y in (6):#
262
+
263
+ x[1][0]+=5
264
+
265
+
266
+
267
+ if 'id20'==i and y in (6):#
268
+
269
+ pass
270
+
271
+ if 'id21'==i and y in (0):#
272
+
273
+ x[1][0]+=5
274
+
275
+ if 'id22'==i and y in (6):#
276
+
277
+ x[1][0]+=5
278
+
279
+ if 'id23'==i and y in (0):#
280
+
281
+ pass
282
+
283
+
284
+
285
+
286
+
287
+ print(i)
288
+
289
+
290
+
291
+ Flag=1
292
+
293
+
294
+
295
+ Sample01_Demo03(user01,saicoro,Flag%2)
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+ """
310
+
311
+
312
+
313
+
314
+
315
+ print('1から17を入力してカードを購入')
316
+
317
+ print('購入を続けるなら、yを入力')
318
+
319
+ print('Enterでターン終了')
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+ Flag=0
330
+
331
+
332
+
333
+ while 1:
334
+
335
+ Flag+=1
336
+
21
- if x==1:
337
+ if Flag%2==1:
22
338
 
23
339
  print('user01')
24
340
 
341
+
342
+
343
+ Sample01_Demo02(user01)
344
+
345
+ saicoro=random.randint(1,6)
346
+
347
+ Sample01_Demo03(user01,saicoro,Flag%2)
348
+
349
+
350
+
351
+
352
+
25
- elif x==0:
353
+ elif Flag%2==0:
26
354
 
27
355
  print('user02')
28
356
 
29
-
30
-
31
-
32
-
33
- Flag=0
357
+
34
-
35
-
36
-
358
+
37
- while 1:
359
+ Sample01_Demo02(user02)
38
-
360
+
39
- Flag+=1
361
+ saicoro=random.randint(1,6)
362
+
363
+ Sample01_Demo03(user02,saicoro,Flag$2)
364
+
365
+
366
+
367
+
40
368
 
41
369
 
42
370
 
43
- if Flag%2==1:
44
-
45
- #print('user01')
371
+ """
46
-
47
- Sample01(int(Flag%2))
48
-
49
- print(Flag%2)
50
-
51
-
52
-
53
- elif Flag%2==0:
54
-
55
- #print('user02')
56
-
57
- Sample01(int(Flag%2))
58
-
59
- print(Flag%2)
60
-
61
-
62
-
63
- if Flag==5:
64
-
65
- break
66
-
67
-
68
372
 
69
373
  ```
70
-
71
- #
72
-
73
- サンプルでは、Flagの0と1でユーザーを判別してますが、
74
-
75
- ユーザー1が選択された時やユーザー2が選択された時に、自分自身=1
76
-
77
- として扱う方法は無いでしょうか?
78
-
79
-
80
-
81
- 関数内にif文を書き込むとコード量が2倍になってしまいます。