fork download
  1.  
  2. # 街コロ+ブロックス簡易2Dゲーム
  3.  
  4.  
  5. import random
  6. import numpy as np
  7. import collections
  8. from pprint import pprint
  9.  
  10. # サイコロの準備
  11. Dice=[i for i in range(1,12)]
  12. # MAP
  13. #l=[['0' for i in range(9)] for j in range(9)]
  14.  
  15. l=[
  16. ['0', '0', '0', '0', '0', '0', '0', '0', '0'],
  17. ['0', '0', '0', '0', '0', '0', '0', '0', '0'],
  18. ['0', '0', '0', '0', '0', '0', '0', '0', '0'],
  19. ['0', '0', '0', '0', 'A', '0', '0', '0', '0'],
  20. ['0', '0', '0', 'B', '0', 'D', '0', '0', '0'],
  21. ['0', '0', '0', '0', 'C', '0', '0', '0', '0'],
  22. ['0', '0', '0', '0', '0', '0', '0', '0', '0'],
  23. ['0', '0', '0', '0', '0', '0', '0', '0', '0'],
  24. ['0', '0', '0', '0', '0', '0', '0', '0', '0']]
  25.  
  26. # ターン 回数識別用
  27. Times=0
  28.  
  29. # 最終目標 必要ないかも
  30. Final_Goal=250
  31. # 誰が目的を達成したか判定用 配列
  32. Final_Goal_Flag=[0,0,0,0]
  33.  
  34.  
  35. # ユーザー情報 ポイント
  36. USE=[5,5,5,5]
  37.  
  38.  
  39. # 回転済み ブロック
  40. Warehouse_Slot=[[[['1', '0', '0'], ['0', '0', '0'], ['0', '0', '0']], [['0', '0', '1'], ['0', '0', '0'], ['0', '0', '0']], [['0', '0', '0'], ['0', '0', '0'], ['0', '0', '1']], [['0', '0', '0'], ['0', '0', '0'], ['1', '0', '0']]], [[['2', '2', '0'], ['0', '0', '0'], ['0', '0', '0']], [['0', '0', '2'], ['0', '0', '2'], ['0', '0', '0']], [['0', '0', '0'], ['0', '0', '0'], ['0', '2', '2']], [['0', '0', '0'], ['2', '0', '0'], ['2', '0', '0']]], [[['2', '0', '2'], ['0', '0', '0'], ['0', '0', '0']], [['0', '0', '2'], ['0', '0', '0'], ['0', '0', '2']], [['0', '0', '0'], ['0', '0', '0'], ['2', '0', '2']], [['2', '0', '0'], ['0', '0', '0'], ['2', '0', '0']]], [[['2', '0', '0'], ['0', '2', '0'], ['0', '0', '0']], [['0', '0', '2'], ['0', '2', '0'], ['0', '0', '0']], [['0', '0', '0'], ['0', '2', '0'], ['0', '0', '2']], [['0', '0', '0'], ['0', '2', '0'], ['2', '0', '0']]], [[['0', '3', '0'], ['3', '3', '3'], ['0', '0', '0']], [['0', '3', '0'], ['0', '3', '3'], ['0', '3', '0']], [['0', '0', '0'], ['3', '3', '3'], ['0', '3', '0']], [['0', '3', '0'], ['3', '3', '0'], ['0', '3', '0']]], [[['3', '3', '0'], ['3', '0', '0'], ['0', '0', '0']], [['0', '3', '3'], ['0', '0', '3'], ['0', '0', '0']], [['0', '0', '0'], ['0', '0', '3'], ['0', '3', '3']], [['0', '0', '0'], ['3', '0', '0'], ['3', '3', '0']]], [[['0', '5', '0'], ['0', '5', '0'], ['5', '5', '5']], [['5', '0', '0'], ['5', '5', '5'], ['5', '0', '0']], [['5', '5', '5'], ['0', '5', '0'], ['0', '5', '0']], [['0', '0', '5'], ['5', '5', '5'], ['0', '0', '5']]], [[['6', '6', '0'], ['6', '0', '0'], ['6', '6', '0']], [['6', '6', '6'], ['6', '0', '6'], ['0', '0', '0']], [['0', '6', '6'], ['0', '0', '6'], ['0', '6', '6']], [['0', '0', '0'], ['6', '0', '6'], ['6', '6', '6']]], [[['0', '7', '7'], ['7', '7', '0'], ['7', '0', '0']], [['7', '7', '0'], ['0', '7', '7'], ['0', '0', '7']], [['0', '0', '7'], ['0', '7', '7'], ['7', '7', '0']], [['7', '0', '0'], ['7', '7', '0'], ['0', '7', '7']]]]
  41. # ブロックの費用と報酬
  42. Warehouse_Slot_Bloku=[1,4,4,4,12,12,25,30,35]
  43.  
  44.  
  45.  
  46.  
  47. # サイコロの値
  48. def Sample_Demo_New_Bloku_Random_Number():
  49. global Dice
  50. return random.choice(Dice)
  51.  
  52.  
  53.  
  54. # x=座標x y=座標y z=埋め込む配列 Warehouse_Slot[][] ,xyz=0,1,2,3ユーザー識別
  55. def Sample_Demo01(x,y,z,xyz):
  56.  
  57. # ポイントからブロック費用 購入処理
  58. for k,v in enumerate(Warehouse_Slot):
  59. for i in v:
  60. if i==z:
  61. if USE[xyz]-Warehouse_Slot_Bloku[k]>=0:
  62. USE[xyz]-=Warehouse_Slot_Bloku[k]
  63. else:
  64. return 0
  65.  
  66.  
  67.  
  68. # ユーザー識別用 IDの付与
  69. Local_Block=z
  70. Local_Block2=[]
  71. Local_Block3=[]
  72. for i in Local_Block:
  73. for j in i:
  74. if '0'==j:
  75. Local_Block2.append(j)
  76. else:
  77. if xyz==0:
  78. j='A'+j
  79. Local_Block2.append(j)
  80. elif xyz==1:
  81. j='B'+j
  82. Local_Block2.append(j)
  83. elif xyz==2:
  84. j='C'+j
  85. Local_Block2.append(j)
  86. elif xyz==3:
  87. j='D'+j
  88. Local_Block2.append(j)
  89. Local_Block2=list(zip(*[iter(Local_Block2)]*3))
  90. for i in Local_Block2:Local_Block3.append(list(i))
  91. #pprint(Local_Block3)
  92.  
  93.  
  94.  
  95.  
  96. # MAPへの配置
  97. for i_r, i_l in enumerate(range(x, min((x+3, 9)))):
  98. for j_r, j_l in enumerate(range(y, min((y+3, 9)))):
  99. if l[j_l][i_l]=='0':
  100. l[j_l][i_l]=Local_Block3[j_r][i_r]
  101. else:
  102. # ユーザー別 初回のみ座標
  103. if l[j_l][i_l]=='A':
  104. l[3][4]#A
  105. elif l[j_l][i_l]=='B':
  106. l[4][3]#B
  107. elif l[j_l][i_l]=='C':
  108. l[5][4]#C
  109. elif l[j_l][i_l]=='D':
  110. l[4][5]#D
  111. # pass
  112. else:
  113. pass
  114.  
  115.  
  116. return l
  117.  
  118.  
  119.  
  120.  
  121. # 各MAP要素の合計
  122. def Sample_Demo_New_Bloku_Initialization(xyz):
  123. c=[]
  124. for i in range(len(xyz)):
  125. c.append(collections.Counter(xyz[i]))
  126. for j in range(len(c)-1):
  127. c[0]+=c[j+1]
  128. return c[0]
  129.  
  130.  
  131.  
  132.  
  133.  
  134. # ブロックの中央座標から隣接マスの取得
  135. INDEX01=[]
  136. INDEX02=[]
  137. # ブロックの置ける中央座標を取得
  138. def Sample_Demo00_index01(xyz):
  139. for k,v in enumerate(l):
  140. if xyz in v:INDEX01.append([k,v.index(xyz)])
  141. Sample_Demo00_index02()
  142. # ブロックの置ける周囲座標を取得
  143. def Sample_Demo00_index02():
  144. global INDEX01
  145. INDEX02.append([[INDEX01[0][0]-1,INDEX01[0][1]-1],[INDEX01[0][0]-1,INDEX01[0][1]],[INDEX01[0][0]-1,INDEX01[0][1]+1],[INDEX01[0][0],INDEX01[0][1]-1],INDEX01[0],[INDEX01[0][0],INDEX01[0][1]+1],[INDEX01[0][0-1],INDEX01[0][1]-1],[INDEX01[0][0]+1,INDEX01[0][1]],[INDEX01[0][0]+1,INDEX01[0][1]+1]])
  146.  
  147.  
  148.  
  149.  
  150. # MAPの再編集 計算用
  151. def Sample_Demo02(x):
  152. global l
  153. Re_Edit=[]
  154. for i in x:
  155. for j in i:
  156. if j=='0':Re_Edit.append(j)
  157. elif len(j)==2:Re_Edit.append([j[0],int(j[1])])
  158. elif len(j)==3:Re_Edit.append([j[0],int(j[1])+int(j[2])])
  159. Re_Edit=list(zip(*[iter(Re_Edit)]*9))
  160. return Re_Edit
  161.  
  162.  
  163.  
  164.  
  165.  
  166. # 取得するポイントの取得 NG
  167. def Sample_Demo03(xyz):
  168. global Nasa
  169. # 一時保留倉庫
  170. Nasa=[0,0,0,0]
  171.  
  172. # MAPに配置されてるブロック別 ポイント取得
  173. Hangout=Sample_Demo_New_Bloku_Initialization(xyz)
  174. for i in Hangout:
  175. if i=='0' or i=='A' or i=='B' or i=='C' or i=='D':
  176. pass
  177. else:
  178. if 'A' in i:
  179. if len(i)==2:
  180. Nasa[0]+=int(i[1])*Hangout[i]
  181. elif len(i)==3:
  182. Nasa[0]+=int(str(i[1])+str(i[2]))*Hangout[i]
  183. elif 'B' in i:
  184. if len(i)==2:
  185. Nasa[1]+=int(i[1])*Hangout[i]
  186. elif len(i)==3:
  187. Nasa[1]+=int(str(i[1])+str(i[2]))*Hangout[i]
  188. elif 'C' in i:
  189. if len(i)==2:
  190. Nasa[2]+=int(i[1])*Hangout[i]
  191. elif len(i)==3:
  192. Nasa[2]+=int(str(i[1])+str(i[2]))*Hangout[i]
  193. elif 'D' in i:
  194. if len(i)==2:
  195. Nasa[3]+=int(i[1])*Hangout[i]
  196. elif len(i)==3:
  197. Nasa[3]+=int(str(i[1])+str(i[2]))*Hangout[i]
  198. else:
  199. print(i,Hangout[i])
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206. print()
  207. # ユーザーポイント 皆
  208. print('ユーザーポイント [','A',USE[0],'','B',USE[1],'','C',USE[2],'','D',USE[3],']')
  209.  
  210. # ユーザーAが置ける範囲のindexを取得
  211. Sample_Demo00_index01('A')
  212. # indexの表示
  213. print('Aユーザーが置ける範囲',INDEX02),print()
  214.  
  215. # ブロックを置く ユーザーID
  216. try:pprint(Sample_Demo01(0,0,Warehouse_Slot[2][0],1))
  217. except IndexError:pass
  218.  
  219. # ポイント取得 仮
  220. Sample_Demo03(l)
  221. # 表示
  222. print('ABCD 仮ポイント',Nasa)
  223.  
  224. print('サイコロの値',Sample_Demo_New_Bloku_Random_Number())
  225. print()
  226.  
  227.  
  228.  
  229. # ユーザーポイント 皆
  230. print('ユーザーポイント [','A',USE[0],'','B',USE[1],'','C',USE[2],'','D',USE[3],']')
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237. """
  238. while 250>=USE[0] or 250>=USE[1] or 250>=USE[2] or 250>=USE[3]:
  239. # ターン処理
  240. # Aユーザー
  241. if Times%4==1:
  242. pass
  243.  
  244. # Bユーザー
  245. elif Times%4==2:
  246. pass
  247. # Cユーザー
  248. elif Times%4==3:
  249. pass
  250. # Dユーザー
  251. elif Times%4==0:
  252. pass
  253. """
  254.  
Success #stdin #stdout 0.13s 24608KB
stdin
Standard input is empty
stdout
ユーザーポイント [ A 5  B 5  C 5  D 5 ]
Aユーザーが置ける範囲 [[[2, 3], [2, 4], [2, 5], [3, 3], [3, 4], [3, 5], [4, 3], [4, 4], [4, 5]]]

[['B2', '0', 'B2', '0', '0', '0', '0', '0', '0'],
 ['0', '0', '0', '0', '0', '0', '0', '0', '0'],
 ['0', '0', '0', '0', '0', '0', '0', '0', '0'],
 ['0', '0', '0', '0', 'A', '0', '0', '0', '0'],
 ['0', '0', '0', 'B', '0', 'D', '0', '0', '0'],
 ['0', '0', '0', '0', 'C', '0', '0', '0', '0'],
 ['0', '0', '0', '0', '0', '0', '0', '0', '0'],
 ['0', '0', '0', '0', '0', '0', '0', '0', '0'],
 ['0', '0', '0', '0', '0', '0', '0', '0', '0']]
ABCD 仮ポイント [0, 4, 0, 0]
サイコロの値 5

ユーザーポイント [ A 5  B 1  C 5  D 5 ]