質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

694閲覧

ユーザーを表すフラグの共通化

Untitled_Sample

総合スコア192

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2018/10/16 04:01

編集2018/10/16 04:48

街コロ
https://ja.wikipedia.org/wiki/%E8%A1%97%E3%82%B3%E3%83%AD

上記のテーブルゲームをコンソールで作成してますが、
誰のターンか判別する仕組みが分かりません。

コードの中盤にコメントで描いてます。

python

1 2 3 4# 0=誰のターンでも可能 5# 1=自分のターン 6# 2=相手のターン Other 7 8 9l=[ 10# id 購入費用 誰のターン有効か012 出目 報酬 11[['id01'],[999],[0],[1],[1]],#購入不可 全ユーザに初期配置 1coin 1result Anyone 1blessing 12[['id02'],[1],[0],[2],[1]],# 1coin 2result Anyone 1blessing 13[['id03'],[1],[1],[2,3],[1]],# 1coin 2,3result Myself 1blessing 14[['id04'],[2],[2],[3],[1]],# 1coin 1,2,3,4,5,6result Other 1blessing 15[['id05'],[2],[1],[4],[3]],#3coin 4result myself 3blessing 16[['id06'],[3],[0],[5],[1]],#1coin 5result 1blessing 17[['id07'],[5],[1],[7],[3]],#5coin 7result myself id02*3blessing 18[['id08'],[3],[1],[8],[3]],#3coin 8result myself (id06+id09)*3blessing 19[['id09'],[6],[0],[9],[5]],#6coin 9result 5blessing 20[['id10'],[3],[0],[9,10],[2]],#3coin 9,10result 2blessing 21[['id11'],[3],[0],[10],[3]],#3coin 10result 3blessing 22[['id12'],[2],[1],[11,12],[2]],#2coin 11,12result 2blessing (id11+id12)*2blessing 23 24[['id13'],[6],[1],[6],[2]],#2coin oll 6result 2blessing 全員から 25[['id14'],[6],[1],[6],[5]],#6coin 6result 5blessing 相手指定 5coin貰う 26#[['id15'],[6],[1],[6],['-']],#6coin 6result 建物を1つ交換 未実装 27 28[['id20'],[4],[1],[0],[0]],#4coin 効果:(常時)ダイスを2個同時に振れる 29[['id21'],[10],[1],[6],[5]],#10coin 効果:(常時)自分の【飲食店】と【商店】で得られるコインを+1する 30[['id22'],[16],[1],[6],[5]],#16coin 効果:(常時)ぞろ目を出したらもう一度自分のターン 31[['id23'],[22],[1],[0],[0]],#22coin 効果:(常時)毎ターン一度だけダイスを振り直せる 32] 33 34 35 36#1,2 user 37user01=[['id01'],[3]] 38user02=[['id01'],[3]] 39 40 41import random 42saicoro=random.randint(1,6) 43 44from pprint import pprint 45 46 47#print(l[1][2][0]) # 0 48#print(user01[1][0]) #3 49#print(l[1][0][0]) #id01 50#print(l[1][1][0]) # 1 51 52# 購入とカードの追加 簡易 後処理必要 53def Sample01_Demo01(x,y): 54 try: 55 if x[1][0]-l[y][1][0]>=0: 56 x[1][0]=x[1][0]-l[y][1][0] 57 x[0].append(l[y][0][0]) 58 except: 59 pass 60 61 62#def Sample01_Demo02(x): 63 64 65 66# 購入費用が足りてれば購入 yで継続 Enterでターンエンド 67def Sample01_Demo02(xxx): 68 xyz=input() 69 try: 70 if xyz.isdecimal()==True: 71 Sample01_Demo01(xxx,int(xyz)) 72 print(xxx) 73 74 Bu=input() 75 if Bu=='y': 76 Sample01_Demo02(xxx) 77 else: 78 pass 79 80 except TypeError: 81 pass 82 83 84 85# x=user01 y=saicoro z=Flag 01 86def Sample01_Demo03(x,y,z): 87 88 for i in x[0]: 89 if 'id01'==i:#0 90 if 0==x[1][0]: 91 x[1][0]+=1 92 93 if 'id02'==i and y in (2):#0 94 x[1][0]+=1 95# userによって、自分自身を表す。Flagの値が変化してしまう。 96# if x=='user01':if 'id02'==i and y in (2) and Flag in (1):#1 97# if x=='user02':if 'id02'==i and y in (2) and Flag in (0):#0 98 if 'id03'==i and y in (2,3):#1 99 x[1][0]+=1 100 if 'id04'==i and y in (3):#2 101 x[1][0]+=1 102 if 'id05'==i and y in (4):#1 103 x[1][0]+=3 104 if 'id06'==i and y in (5):#0 105 x[1][0]+=1 106 if 'id07'==i and y in (7):#1 107 x[1][0]+=3 108 if 'id08'==i and y in (8):#1 109 x[1][0]+=3 110 if 'id09'==i and y in (9):#1 111 x[1][0]+=5 112 if 'id10'==i and y in (9,10):#2 113 x[1][0]+=2 114 if 'id11'==i and y in (10):#0 115 x[1][0]+=3 116 if 'id12'==i and y in (11,12):#1 117 x[1][0]+=2 118 119 if 'id13'==i and y in (6):# 120 x[1][0]+=2 121 if 'id14'==i and y in (6):# 122 x[1][0]+=5 123 124 if 'id20'==i and y in (6):# 125 pass 126 if 'id21'==i and y in (0):# 127 x[1][0]+=5 128 if 'id22'==i and y in (6):# 129 x[1][0]+=5 130 if 'id23'==i and y in (0):# 131 pass 132 133 134 print(i) 135 136Flag=1 137 138Sample01_Demo03(user01,saicoro,Flag%2) 139 140 141 142 143 144 145""" 146 147 148print('1から17を入力してカードを購入') 149print('購入を続けるなら、yを入力') 150print('Enterでターン終了') 151 152 153 154 155Flag=0 156 157while 1: 158 Flag+=1 159 if Flag%2==1: 160 print('user01') 161 162 Sample01_Demo02(user01) 163 saicoro=random.randint(1,6) 164 Sample01_Demo03(user01,saicoro,Flag%2) 165 166 167 elif Flag%2==0: 168 print('user02') 169 170 Sample01_Demo02(user02) 171 saicoro=random.randint(1,6) 172 Sample01_Demo03(user02,saicoro,Flag$2) 173 174 175 176"""

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hayataka2049

2018/10/16 04:11

質問の意図がよくわからないのでわかりやすく書き直してください。
t_obara

2018/10/16 05:17

データを配列ではなく、適切にオブジェクト化して、ロジックにはデザインパターンを適用するとか検討されるとよろしいかと。
guest

回答1

0

ベストアンサー

質問する時に、意図と異なる動作のソースを挙げてそれで説明終わりというのでは何も伝わりません。
どのように異なっているのかを日本語で書いてください。
とりあえず次のように書いても同じように動作します。
if 文を減らしたいという意図でしょうか?

Python

1def Sample02(x): 2 if x == 1: 3 print('user01') 4 else: 5 print('user02') 6 7for i in range(1, 6): 8 flag = i % 2 9 Sample02(flag) 10 print(flag) 11

投稿2018/10/16 04:19

Zuishin

総合スコア28660

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問