Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. extensions [bitmap]
  2. breed [humans human]
  3. humans-own [behavior] ; comportamentul oamenilor (Stau pe loc [0] sau se pot misca [1])
  4. patches-own [exit-value]
  5. globals [dead saved c_id]
  6.  
  7. breed [sensors sensor]
  8. sensors-own [isfire x1 y1 x2 y2 isHallway]
  9. breed [alarms alarm]
  10. alarms-own [isfire]
  11. breed [controllers controller]
  12. controllers-own [isfire]
  13.  
  14. to setup-sensors
  15.  
  16. create-sensors 7
  17. [
  18. set shape "arrow"
  19. set color yellow
  20. set heading 180
  21. set isHallway 0
  22. ifelse who = 0 [setxy 5 4 set x1 0 set y1 0
  23. set x2 11 set y2 9]
  24. [ifelse who = 1 [setxy 5 18 set x1 0 set y1 15
  25. set x2 11 set y2 21]
  26. [ifelse who = 2 [setxy 25 4 set x1 19 set y1 0
  27. set x2 31 set y2 11]
  28. [ifelse who = 3 [setxy 25 17 set x1 19 set y1 13
  29. set x2 31 set y2 21]
  30. [ifelse who = 4 [setxy 5 29 set x1 0 set y1 27
  31. set x2 11 set y2 31]
  32. [ifelse who = 5 [setxy 25 27 set x1 19 set y1 23
  33. set x2 31 set y2 31]
  34. [ifelse who = 6 [setxy 15 14 set isHallway 1]
  35. [ifelse who = 7 [setxy 0 15]
  36. []]]]]]]]
  37. ]
  38. end
  39. to setup-alarms
  40. create-alarms 7
  41. [
  42. set shape "circle"
  43. set color pink
  44. set heading 180
  45. let offset 7
  46. ifelse who = offset + 0 [setxy 6 4]
  47. [ifelse who = offset + 1 [setxy 6 18]
  48. [ifelse who = offset + 2 [setxy 26 4]
  49. [ifelse who = offset + 3 [setxy 26 17]
  50. [ifelse who = offset + 4 [setxy 6 29]
  51. [ifelse who = offset + 5 [setxy 26 27]
  52. [ifelse who = offset + 6 [setxy 16 14]
  53. [ifelse who = offset + 7 [setxy 1 15]
  54. []]]]]]]]
  55. ]
  56. end
  57.  
  58. to setup-controllers
  59. create-controllers 1
  60. [
  61. set shape "square"
  62. set color green
  63. set heading 180
  64. setxy 12 10
  65. ]
  66.  
  67. end
  68.  
  69. to setup
  70. clear-all
  71.  
  72. setup-sensors
  73. setup-alarms
  74. setup-controllers
  75.  
  76. load-patches
  77. place-humans
  78.  
  79. reset-ticks
  80. end
  81.  
  82. to load-patches
  83. ; aici incarc culorile patchurilor
  84. import-pcolors "floor.bmp"
  85. end
  86.  
  87. to place-humans
  88. create-humans number-humans
  89. [
  90. set heading random 360
  91. set behavior random 2
  92. set shape "person"
  93. set color white
  94.  
  95. let invalid-location? true
  96. while [invalid-location?]
  97. [
  98. let xcoord random-pxcor
  99. let ycoord random-pycor
  100. let patch-color [pcolor] of patch xcoord ycoord
  101. if patch-color != 0 and patch-color != 64.5
  102. [
  103. setxy xcoord ycoord
  104. set invalid-location? false
  105. ]
  106. ]
  107. ]
  108. end
  109.  
  110. to go
  111. spread-fire ; raspandirea focului
  112. move-humans
  113. death-humans
  114. detect-fire
  115. process-exits
  116. tick-controllers
  117. tick
  118. end
  119.  
  120. to move-humans
  121. ask humans
  122. [
  123. ifelse count alarms with [color = magenta] != 0
  124. [
  125. uphill exit-value
  126. ]
  127. [
  128. if behavior = 1
  129. [
  130. if count patches with [pcolor = red] = 0
  131. [
  132. let invalid-destination? true
  133. while [invalid-destination?]
  134. [
  135. let destination patch-ahead 1
  136. ifelse destination = nobody or [pcolor] of destination = 0 or [pcolor] of destination = red
  137. [set heading random 360]
  138. [set invalid-destination? false]
  139. ]
  140. forward 1
  141. ]
  142. ]
  143. ]
  144. ]
  145. end
  146.  
  147. to fire-offices
  148. ask one-of patches with [pcolor = 105]
  149. [
  150. set pcolor red
  151. ]
  152. end
  153.  
  154. to fire-conference
  155. ask one-of patches with [pcolor = 115.3]
  156. [
  157. set pcolor red
  158. ]
  159. end
  160.  
  161. to spread-fire
  162. ask patches with [pcolor = red]
  163. [
  164. if random-float 100 < fire-speed
  165. [
  166. let neighbor one-of neighbors with [position pcolor [red 64.5 0] = false]
  167. if neighbor != nobody
  168. [
  169. ask neighbor [ set pcolor red ]
  170. ]
  171. ]
  172. ]
  173. end
  174.  
  175. to process-exits
  176. ask patches with [pcolor = 64.5] [ set exit-value exit-value + 10 ]
  177. diffuse exit-value 0.5
  178. ask patches [ set exit-value exit-value * 0.9 ]
  179. ask patches with [ pcolor = 0 ] [ set exit-value 0 ]
  180. end
  181.  
  182. to death-humans
  183. ask humans
  184. [
  185. if pcolor = red
  186. [
  187. set dead dead + 1
  188. die
  189. ]
  190. if pcolor = 64.5
  191. [
  192. set saved saved + 1
  193. die
  194. ]
  195. ]
  196. end
  197.  
  198.  
  199. to detect-fire
  200. ask sensors
  201. [
  202. let iisFire 0
  203. let x11 x1
  204. let x22 x2
  205. let y11 y1
  206. let y22 y2
  207.  
  208. let t self
  209.  
  210. ifelse isHallway = 1
  211. [
  212. ask patches with [pxcor >= 0 and pxcor <= 12 and pycor >= 23 and pycor <= 25]
  213. [if pcolor = red [set iisFire 1]]
  214.  
  215. ask patches with [pxcor >= 3 and pxcor <= 12 and pycor >= 11 and pycor <= 13]
  216. [if pcolor = red [set iisFire 1]]
  217.  
  218. ask patches with [pxcor >= 13 and pxcor <= 17 and pycor >= 0 and pycor <= 28]
  219. [if pcolor = red [set iisFire 1]]
  220. ][
  221. ask patches with [pxcor >= x11 and pxcor <= x22 and pycor >= y11 and pycor <= y22]
  222. [
  223. if pcolor = red
  224. [
  225. set iisFire 1
  226. ]
  227. ]
  228. ]
  229.  
  230. if iisFire = 1
  231. [
  232. set color orange
  233. set isFire 1
  234. ]
  235.  
  236. ]
  237. end
  238.  
  239.  
  240.  
  241. to tick-controllers
  242. ask sensors
  243. [
  244. if isFire = 1
  245. [
  246. ask alarms[
  247. set color magenta
  248. ]
  249. ]
  250. ]
  251. end
  252.  
  253. to check-alarm
  254. ask alarms[
  255. set color magenta
  256. ]
  257. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement