Advertisement
Weezle

Untitled

Jul 12th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.31 KB | None | 0 0
  1. import numpy as np
  2.  
  3.  
  4. def path_in_room1(x1, y1, x2, y2, room):
  5. room[x1, y1] = 10
  6. room[x2, y2] = 0
  7. d = 10
  8. Flag1 = True
  9. while (room[x2, y2] == 0) and Flag1:
  10. Flag1 = False
  11. for i in range(0, np.shape(room)[0]):
  12. for j in range(0, np.shape(room)[0]):
  13. if room[i, j] == d:
  14. if i + 1 != np.shape(room)[0]:
  15. if room[i + 1, j] == 0:
  16. room[i + 1, j] = d + 1
  17. Flag1 = True
  18. if i - 1 >= 0:
  19. if room[i - 1, j] == 0:
  20. room[i - 1, j] = d + 1
  21. Flag1 = True
  22. if j + 1 != np.shape(room)[1]:
  23. if room[i, j + 1] == 0:
  24. room[i, j + 1] = d + 1
  25. Flag1 = True
  26. if j - 1 >= 0:
  27. if room[i, j - 1] == 0:
  28. room[i, j - 1] = d + 1
  29. Flag1 = True
  30. d += 1
  31. if (room[x2, y2] != 0):
  32. return True
  33. else:
  34. return False
  35.  
  36.  
  37. class Furniture:
  38. space = []
  39. _x, _y = -1, -1
  40. wasplaced = False
  41.  
  42. def __init__(self, length=0, width=0):
  43. self.length = length
  44. self.width = width
  45.  
  46. def x(self):
  47. return self._x
  48.  
  49. def y(self):
  50. return self._y
  51.  
  52. def place(self, x, y):
  53. return False
  54.  
  55. def _check(self, x, y):
  56. if np.size(np.shape(self.space)) < 2:
  57. return False
  58. if x + np.shape(self.space)[0] > np.shape(room)[0]:
  59. return False
  60. if y + np.shape(self.space)[1] > np.shape(room)[1]:
  61. return False
  62. for i in range(0, np.shape(self.space)[0]):
  63. for j in range(0, np.shape(self.space)[1]):
  64. if room[x + i, y + j] > 0:
  65. return False
  66. copy = room.copy()
  67. if path_in_room1(x, y, dx, dy, copy):
  68. return True
  69. else:
  70. return False
  71. return True
  72.  
  73. def dele(self):
  74. for i in range(np.shape(self.space)[0]):
  75. for m in range(np.shape(self.space)[1]):
  76. self.space[i, m] = 0
  77. self._set(self._x, self._y)
  78.  
  79. def __str__(self):
  80. return str(self.__class__.__name__) + ' ' + 'Длина: ' + str(self.length) + ' ' + 'Ширина:' + str(
  81. self.width) + ' |' + 'В комнате:' + str(self.wasplaced)
  82.  
  83. def _set(self, x, y):
  84. self._x = x
  85. self._y = y
  86. for i in range(0, np.shape(self.space)[0]):
  87. for j in range(0, np.shape(self.space)[1]):
  88. room[x + i, y + j] = self.space[i, j]
  89.  
  90.  
  91. class Table(Furniture): # Стол
  92. length, width = 0, 0
  93. FREE_PLACE =1
  94. def __init__(self, length, width):
  95. super().__init__(length, width)
  96. self.space = np.ones((length, width + self.FREE_PLACE))
  97. self.space[0:length, width:width + self.FREE_PLACE] = 3
  98.  
  99. def place(self, x, y):
  100. if y == 0 or x == 0 or x == np.shape(room)[0] - 1 or y == np.shape(room)[1] - 1:
  101. if (x < 0) or (y < 0):
  102. return False
  103. if not self._check(x, y):
  104. return False
  105. self._set(x, y)
  106. return True
  107. else:
  108. return False
  109.  
  110.  
  111. def __str__(self):
  112. return str(self.__class__.__name__) + '| ' + 'Длина: ' + str(self.length) + '| ' + 'Ширина:' + str(
  113. self.width) + ' |' + 'В комнате:' + str(self.wasplaced)
  114.  
  115. class OperTable(Furniture): # Стол операционный
  116. length, width = 0, 0
  117. FREE_PLACE = 1
  118.  
  119. def __init__(self, length, width):
  120. super().__init__(length, width)
  121. self.space = np.ones((length, width + self.FREE_PLACE))
  122. self.space[0:length, width:width + self.FREE_PLACE] = 3
  123.  
  124. def place(self, x, y):
  125. if y == 0 or x == 0 or x == np.shape(room)[0] - 1 or y == np.shape(room)[1] - 1:
  126. if (x < 0) or (y < 0):
  127. return False
  128. if not self._check(x, y):
  129. return False
  130. self._set(x, y)
  131. return True
  132. else:
  133. return False
  134.  
  135.  
  136. def __str__(self):
  137. return str(self.__class__.__name__) + '| ' + 'Длина: ' + str(self.length) + '| ' + 'Ширина:' + str(
  138. self.width) + ' |' + 'В комнате:' + str(self.wasplaced)
  139.  
  140.  
  141. class Case(Furniture): # Тубмочка
  142. length, width = 0, 0
  143.  
  144. FREE_PLACE = 1 # ширина свободного места
  145.  
  146. def __init__(self, length, width):
  147. super().__init__(length, width)
  148. self.space = np.ones((length, width + self.FREE_PLACE))
  149. self.space[0:length, width:width + self.FREE_PLACE] = 3
  150.  
  151. def place(self, x, y):
  152. if y == 0 or x == 0 or x == np.shape(room)[0] - 1 or y == np.shape(room)[1] - 1:
  153. if (x < 0) or (y < 0):
  154. return False
  155. if not self._check(x, y):
  156. return False
  157. self._set(x, y)
  158. return True
  159. else:
  160. return False
  161.  
  162.  
  163. def __str__(self):
  164. return str(self.__class__.__name__) + '| ' + 'Длина: ' + str(self.length) + '| ' + 'Ширина:' + str(
  165. self.width) + ' |' + 'В комнате:' + str(self.wasplaced)
  166.  
  167.  
  168. class Bed(Furniture): # Кровать
  169. length, width = 0, 0
  170.  
  171. FREE_PLACE = 1 #
  172.  
  173. def __init__(self, length, width):
  174. super().__init__(length, width)
  175. self.space = np.ones((length, width + self.FREE_PLACE))
  176. self.space[0:length, width:width + self.FREE_PLACE] = 3
  177.  
  178. def place(self, x, y):
  179. if y == 0 or x == 0 or x == np.shape(room)[0] - 1 or y == np.shape(room)[1] - 1:
  180. if (x < 0) or (y < 0):
  181. return False
  182. if not self._check(x, y):
  183. return False
  184. self._set(x, y)
  185. return True
  186. else:
  187. return False
  188.  
  189.  
  190. def __str__(self):
  191. return str(self.__class__.__name__) + '| ' + 'Длина: ' + str(self.length) + '| ' + 'Ширина:' + str(
  192. self.width) + ' |' + 'В комнате:' + str(self.wasplaced)
  193.  
  194. class TableWithInstruments(Furniture): # Стол с инструментами
  195. FREE_PLACE = 1
  196.  
  197. def __init__(self, length, width):
  198. super().__init__(length, width)
  199. self.space = np.ones((length, width + self.FREE_PLACE))
  200. self.space[0:length, width:width + self.FREE_PLACE] = 3
  201.  
  202. def place(self, x, y):
  203. if y == 0 or x == 0 or x == np.shape(room)[0] - 1 or y == np.shape(room)[1] - 1:
  204. if (x < 0) or (y < 0):
  205. return False
  206. if not self._check(x, y):
  207. return False
  208. self._set(x, y)
  209. return True
  210. else:
  211. return False
  212.  
  213.  
  214. def __str__(self):
  215. return str(self.__class__.__name__) + '| ' + 'Длина: ' + str(self.length) + '| ' + 'Ширина:' + str(
  216. self.width) + ' |' + 'В комнате:' + str(self.wasplaced)
  217.  
  218.  
  219. class Chest(Furniture):
  220. length, width = 0, 0
  221.  
  222. FREE_PLACE = 2 # ширина свободного места перед шкафом
  223.  
  224. def __init__(self, length, width):
  225. super().__init__(length, width)
  226. self.space = np.ones((length, width + self.FREE_PLACE)) * 2
  227. self.space[0:length, width:width + self.FREE_PLACE] = 3
  228.  
  229. def place(self, x, y):
  230. if y == 0 or x == 0 or x == np.shape(room)[0] - 1 or y == np.shape(room)[1] - 1:
  231. if (x < 0) or (y < 0):
  232. return False
  233. if not self._check(x, y):
  234. return False
  235. self._set(x, y)
  236. return True
  237. else:
  238. return False
  239.  
  240.  
  241. def __str__(self):
  242. return str(self.__class__.__name__) + '| ' + 'Длина: ' + str(self.length) + '| ' + 'Ширина:' + str(
  243. self.width) + ' |' + 'В комнате:' + str(self.wasplaced)
  244.  
  245.  
  246. fcount = 0
  247. type_room = 0
  248. s = input('Выберите тип помещения(Операционная, Палата, Столовая)')
  249. if (s=='Операционная'):
  250. type_room = 1
  251. if (s=='Палата'):
  252. type_room=2
  253. if (s=='Столовая'):
  254. type_room=3
  255.  
  256. while True:
  257. inp0 = input('Размер комнаты?(Длина Ширина):').split(' ')
  258. doorinp = input('Координаты двери(x y):').split(' ')
  259. furnituresinp = int(input('Кол-во мебели: '))
  260. furnitures = []
  261. try:
  262. room = np.zeros((int(inp0[0]), int(inp0[1])))
  263. dx = int(doorinp[0])
  264. dy = int(doorinp[1])
  265. room[dx][dy] = 4
  266. except:
  267. print('Вы ввели некоректные данные, повторите попытку')
  268. continue
  269. break
  270. while True:
  271. while True:
  272. inpmenu = input(
  273. 'Что вы хотите сделать? Добавить эллемент мебели в список, Поставить мебель в комнату, Вывести информацию о мебели, Удалить из комнаты?(Добавить, Поставить, Информация, Удалить):')
  274. if inpmenu == 'Добавить':
  275. if (type_room==1):
  276. inp1 = input('ЧтоО вы хотите добавить?(Тумбочка, Стол, Cтол с инструментами, Шкаф, Операционный стол):')
  277. if (type_room==2):
  278. inp1 = input('Что вы хотите добавить?(Кровать, Тумбочки, Стол, Шкаф):')
  279. if (type_room==3):
  280. inp1 = input('Что вы хотите добавить?(Тумбочка, Стол):')
  281. try:
  282. if inp1 == 'Тумбочка':
  283. inp0 = input('Размер Тумбочки?(Длина Ширина):')
  284. if fcount < furnituresinp:
  285. new = Case(int(inp0.split(' ')[0]), int(inp0.split(' ')[1]))
  286. furnitures.append(new)
  287. fcount += 1
  288. else:
  289. print('Вы уже добавили максимальное кол-во мебели')
  290. if inp1 == 'Стол':
  291. inp0 = input('Размер стола?(Длина Ширина):')
  292. if fcount < furnituresinp:
  293. new = Table(int(inp0.split(' ')[0]), int(inp0.split(' ')[1]))
  294. furnitures.append(new)
  295. fcount += 1
  296. else:
  297. print('Вы уже добавили максимальное кол-во мебели')
  298. if inp1 == 'Шкаф':
  299. inp0 = input('Размер шкафа?(Длина Ширина):')
  300. if fcount < furnituresinp:
  301. new = Bed(int(inp0.split(' ')[0]), int(inp0.split(' ')[1]))
  302. furnitures.append(new)
  303. fcount += 1
  304. else:
  305. print('Вы уже добавили максимальное кол-во мебели')
  306. if inp1 == 'Кровать':
  307. inp0 = input('Размер кровати?(Длина Ширина):')
  308. if fcount < furnituresinp:
  309. new = Bed(int(inp0.split(' ')[0]), int(inp0.split(' ')[1]))
  310. furnitures.append(new)
  311. fcount += 1
  312. else:
  313. print('Вы уже добавили максимальное кол-во мебели')
  314. if inp1 == 'Cтол с инструментами':
  315. inp0 = input('Размер стола?(Длина Ширина):')
  316. if fcount < furnituresinp:
  317. new = TableWithInstruments(int(inp0.split(' ')[0]), int(inp0.split(' ')[1]))
  318. furnitures.append(new)
  319. fcount += 1
  320. else:
  321. print('Вы уже добавили максимальное кол-во мебели')
  322. except:
  323. print('Вы ввели некоректные данные, повторите попытку')
  324. continue
  325. elif inpmenu == 'Информация':
  326. cnt = 0
  327. for i in furnitures:
  328. print(str(cnt) + ' |' + str(i))
  329. cnt += 1
  330. elif inpmenu == 'Удалить':
  331. cnt = 0
  332. for i in furnitures:
  333. print(str(cnt) + ' |' + str(i))
  334. cnt += 1
  335. inpdelete = int(input('Номер удаляемого эллемента?:'))
  336. if furnitures[inpdelete].wasplaced:
  337. furnitures[inpdelete].dele()
  338. furnitures.remove(furnitures[inpdelete])
  339. print('Предмет удален')
  340. else:
  341. print('Этот предмет мебели не стоит в комнате')
  342. elif inpmenu == 'Поставить':
  343. errs = False
  344. for i in range(len(furnitures)):
  345. if not furnitures[i].wasplaced:
  346. errs = False
  347. for x in range(np.shape(room)[0]):
  348. for y in range(np.shape(room)[1]):
  349. x = furnitures[i].place(x, y)
  350. if not x:
  351. furnitures[i].wasplaced = False
  352. errs = True
  353. else:
  354. furnitures[i].wasplaced = True
  355. errs = False
  356. if not errs:
  357. break
  358. if not errs:
  359. break
  360. if errs:
  361. print('Не удалось установить:')
  362. for i in range(len(furnitures)):
  363. if not furnitures[i].wasplaced:
  364. print(str(furnitures[i]))
  365. print(room)
  366. else:
  367. print('Вы ввели неверную команду')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement