Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. breed [comiloes comilao ]
  2. breed [limpadores limpador]
  3. turtles-own [energia]
  4. globals [Quant-transportada acumulado-no-deposito]
  5. to setup
  6. clear-all
  7. setup-patches
  8. setup-turtles
  9. reset-ticks
  10. end
  11. to setup-patches
  12. set-patch-size 15
  13. ask patches with [pcolor = black]
  14. [
  15. if random 101 < nLixoNormal
  16. [
  17. set pcolor yellow
  18. ]
  19. ]
  20. ask patches with [pcolor = black]
  21. [
  22. if random 101 < nLixoToxico
  23. [
  24. set pcolor red
  25. ]
  26. ]
  27. ask patches with [pcolor = black]
  28. [
  29. if random 101 < nComida
  30. [
  31. set pcolor green
  32. ]
  33. ]
  34. ask patches with [pcolor = black ]
  35. [
  36. if random 101 < nCaixoteLixo
  37. [
  38. set pcolor blue
  39. ]
  40. ]
  41. set Quant-transportada 0
  42. end
  43. to setup-turtles
  44. create-comiloes nComiloes
  45. [
  46. set size 2
  47. set color pink
  48. set shape "person"
  49. setxy random-xcor random-ycor
  50. set energia Energiacomida
  51. ]
  52. create-limpadores nlimpadores
  53. [
  54. set size 2
  55. set color blue
  56. set shape "person"
  57. setxy random-xcor random-ycor
  58. set energia Energiacomida
  59. ]
  60. end
  61. to go
  62. move-comiloes
  63. move-limpadores
  64. verificar-morte
  65. if count turtles = 0
  66. [
  67. stop
  68. ]
  69. tick
  70. end
  71. to move-comiloes
  72. ask comiloes
  73. [
  74. ifelse [pcolor] of patch-ahead 1 = green
  75. [
  76. fd 1
  77. set energia energia - 1
  78. ]
  79. [
  80. ifelse [pcolor] of patch-left-and-ahead 90 1 = green
  81. [
  82. left 90
  83. set energia energia - 1
  84. ]
  85. [
  86. ifelse [pcolor] of patch-right-and-ahead 90 1 = green
  87. [
  88. rt 90
  89. set energia energia - 1
  90. ]
  91. [
  92. ifelse [pcolor] of patch-here = green
  93. [
  94. set pcolor black
  95. set energia energia + EnergiaComida
  96. ask n-of 1 patches with [pcolor = black] [ set pcolor green ]
  97. set energia energia - 1
  98. ]
  99. [
  100. ifelse [pcolor] of patch-ahead 1 = red
  101. [
  102. set energia energia - energia / 10
  103. rt 90
  104. set energia energia - 1
  105. ]
  106. [
  107. ifelse [pcolor] of patch-left-and-ahead 90 1 = red
  108. [
  109. fd 1
  110. set energia energia - energia / 10
  111. set energia energia - 1
  112. ]
  113. [
  114. ifelse [pcolor] of patch-right-and-ahead 90 1 = red
  115. [
  116. fd 1
  117. set energia energia - energia / 10
  118. set energia energia - 1
  119. ]
  120. [
  121. ifelse [pcolor] of patch-ahead 1 = yellow
  122. [
  123. set energia energia - energia / 20
  124. rt 90
  125. set energia energia - 1
  126. ]
  127. [
  128. ifelse [pcolor] of patch-left-and-ahead 90 1 = yellow
  129. [
  130. fd 1
  131. set energia energia - energia / 20
  132. set energia energia - 1
  133. ]
  134. [
  135. ifelse [pcolor] of patch-right-and-ahead 90 1 = yellow
  136. [
  137. fd 1
  138. set energia energia - energia / 20
  139. set energia energia - 1
  140. ]
  141. [
  142. ifelse random 101 < 90
  143. [
  144. fd 1
  145. set energia energia - 1
  146. ]
  147. [
  148. ifelse random 101 < 50
  149. [
  150. rt 90
  151. set energia energia - 1
  152. ]
  153. [
  154. lt 90
  155. set energia energia - 1
  156. ]
  157. ]
  158. ]
  159. ]
  160. ]
  161. ]
  162. ]
  163. ]
  164. ]
  165. ]
  166. ]
  167. ]
  168. ]
  169.  
  170. end
  171. to move-limpadores
  172. ask limpadores
  173. [
  174. ifelse ( Quant-transportada < nQuant-Trasporte )
  175. [
  176. ifelse [pcolor] of patch-ahead 1 = green
  177. [
  178. fd 1
  179. set energia energia - 1
  180. ]
  181. [
  182. ifelse [pcolor] of patch-here = green
  183. [
  184. set pcolor black
  185. ask n-of 1 patches with [pcolor = black ] [ set pcolor green ]
  186.  
  187. ifelse ( Quant-transportada < nQuant-trasporte / 2)
  188. [
  189. set energia energia + EnergiaComida
  190. ]
  191. [
  192. set energia energia + EnergiaComida / 2
  193. ]
  194.  
  195. ]
  196. [
  197. ifelse [pcolor] of patch-right-and-ahead 90 1 = green
  198. [
  199. rt 90
  200. set energia energia - 1
  201. ]
  202. [
  203. ifelse [pcolor] of patch-ahead 1 = red
  204. [
  205. fd 1
  206. set energia energia - 1
  207. ]
  208. [
  209. ifelse [pcolor] of patch-right-and-ahead 90 1 = red
  210. [
  211. rt 90
  212. set energia energia - 1
  213. ]
  214. [
  215. ifelse [pcolor] of patch-here = red
  216. [
  217. ifelse ( Quant-transportada < nQuant-Trasporte )
  218. [
  219. set pcolor black
  220. ask n-of 1 patches with [pcolor = black ] [ set pcolor red ]
  221. set Quant-transportada Quant-transportada + 1
  222. ]
  223. [
  224. procurar-azul
  225. ]
  226. ]
  227. [
  228. ifelse [pcolor] of patch-ahead 1 = yellow
  229. [
  230. fd 1
  231. set energia energia - 1
  232. ]
  233. [
  234. ifelse [pcolor] of patch-right-and-ahead 90 1 = yellow
  235. [
  236. rt 90
  237. set energia energia - 1
  238. ]
  239. [
  240. ifelse [pcolor] of patch-here = yellow
  241. [
  242. ifelse ( Quant-transportada + 2 <= nQuant-trasporte )
  243. [
  244. set pcolor black
  245. ask n-of 1 patches with [pcolor = black ] [ set pcolor yellow ]
  246. set quant-transportada quant-transportada + 2
  247. ]
  248. [
  249. procurar-azul
  250. ]
  251. ]
  252. [
  253. ifelse (Quant-transportada = nQuant-Trasporte)
  254. [
  255. if [pcolor] of patch-here = blue
  256. [
  257. set acumulado-no-deposito acumulado-no-deposito + Quant-transportada
  258. set energia energia + 10 * Quant-transportada
  259. set Quant-transportada 0
  260. ]
  261. ]
  262. [
  263. ifelse random 101 < 50
  264. [
  265. fd 1
  266. set energia energia - 1
  267. ]
  268. [
  269. rt 90
  270. set energia energia - 1
  271. ]
  272. ]
  273. ]
  274. ]
  275. ]
  276. ]
  277. ]
  278. ]
  279. ]
  280. ]
  281. ]
  282. ]
  283. [
  284. procurar-azul
  285. ]
  286. ]
  287.  
  288. end
  289. to procurar-azul
  290.  
  291. if (Quant-transportada = nQuant-Trasporte )
  292. [
  293. ifelse ( [pcolor] of patch-here = blue )
  294. [
  295. set acumulado-no-deposito acumulado-no-deposito + Quant-transportada
  296. set energia energia + 10 * Quant-transportada
  297. set Quant-transportada 0
  298. ]
  299. [
  300. ifelse ( [pcolor] of patch-ahead 1 = blue )
  301. [
  302. fd 1
  303. set energia energia - 1
  304. ]
  305. [
  306. ifelse ( [pcolor] of patch-right-and-ahead 90 1 = blue )
  307. [
  308. rt 90
  309. set energia energia - 1
  310. ]
  311. [
  312. ifelse random 101 < 50
  313. [
  314. fd 1
  315. set energia energia - 1
  316. ]
  317. [
  318. rt 90
  319. set energia energia - 1 ]
  320. ]
  321. ]
  322. ]
  323. ]
  324.  
  325. end
  326. to verificar-morte
  327. ask comiloes
  328. [
  329. if ( energia <= 0)
  330. [
  331. die
  332. ]
  333. ]
  334. ask limpadores
  335. [
  336. if( energia <= 0 )
  337. [
  338. die
  339. ]
  340. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement