Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.64 KB | None | 0 0
  1. breed [comiloes comilao ]
  2. breed [limpadores limpador]
  3. turtles-own [energia]
  4. globals [acumulado-no-deposito]
  5. limpadores-own [Quant-transportada]
  6. to setup
  7. clear-all
  8. setup-patches
  9. setup-turtles
  10. reset-ticks
  11. end
  12. to setup-patches
  13. set-patch-size 15
  14. ask patches with [pcolor = black]
  15. [
  16. if random 101 < nLixoNormal
  17. [
  18. set pcolor yellow
  19. ]
  20. ]
  21. ask patches with [pcolor = black]
  22. [
  23. if random 101 < nLixoToxico
  24. [
  25. set pcolor red
  26. ]
  27. ]
  28. ask patches with [pcolor = black]
  29. [
  30. if random 101 < nComida
  31. [
  32. set pcolor green
  33. ]
  34. ]
  35. ask patches with [pcolor = black ]
  36. [
  37. if random 101 < nCaixoteLixo
  38. [
  39. set pcolor blue
  40. ]
  41. ]
  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.  
  173. ask limpadores
  174. [
  175. ifelse [pcolor] of patch-ahead 1 = green
  176. [
  177. fd 1
  178. set energia energia - 1
  179. ]
  180. [
  181. ifelse [pcolor] of patch-here = green
  182. [
  183. set pcolor black
  184. ask n-of 1 patches with [pcolor = black ] [ set pcolor green ]
  185.  
  186. ifelse ( Quant-transportada < nQuant-trasporte / 2)
  187. [
  188. set energia energia + EnergiaComida
  189. ]
  190. [
  191. set energia energia + EnergiaComida / 2
  192. ]
  193. ]
  194. [
  195. ifelse [pcolor] of patch-right-and-ahead 90 1 = green
  196. [
  197. rt 90
  198. set energia energia - 1
  199. ]
  200. [
  201. ifelse [pcolor] of patch-ahead 1 = red
  202. [
  203. fd 1
  204. set energia energia - 1
  205. ]
  206. [
  207. ifelse [pcolor] of patch-right-and-ahead 90 1 = red
  208. [
  209. rt 90
  210. set energia energia - 1
  211. ]
  212. [
  213. ifelse [pcolor] of patch-here = red
  214. [
  215. ifelse ( Quant-transportada + 2 < nQuant-Trasporte )
  216. [
  217. set pcolor black
  218. ask n-of 1 patches with [pcolor = black ] [ set pcolor red ]
  219. set Quant-transportada Quant-transportada + 2
  220. set energia energia - 1
  221. ]
  222. [
  223. procurar-azul
  224. ]
  225. ]
  226. [
  227. ifelse [pcolor] of patch-ahead 1 = yellow
  228. [
  229. fd 1
  230. set energia energia - 1
  231. ]
  232. [
  233. ifelse [pcolor] of patch-right-and-ahead 90 1 = yellow
  234. [
  235. rt 90
  236. set energia energia - 1
  237. ]
  238. [
  239. ifelse [pcolor] of patch-here = yellow
  240. [
  241. ifelse ( Quant-transportada <= nQuant-trasporte )
  242. [
  243. set pcolor black
  244. ask n-of 1 patches with [pcolor = black ] [ set pcolor yellow ]
  245. set quant-transportada quant-transportada + 1
  246. set energia energia - 1
  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 (quant-transportada = nQuant-trasporte)
  264. [
  265. procurar-azul
  266. ]
  267.  
  268. [
  269. ifelse random 101 < 50
  270. [
  271. fd 1
  272. set energia energia - 1
  273. ]
  274. [
  275. rt 90
  276. set energia energia - 1
  277. ]
  278. ]
  279. ]
  280. ]
  281. ]
  282. ]
  283. ]
  284. ]
  285. ]
  286. ]
  287. ]
  288.  
  289. ]
  290. ]
  291.  
  292. end
  293. to procurar-azul
  294.  
  295. ifelse ( [pcolor] of patch-here = blue )
  296. [
  297. set acumulado-no-deposito acumulado-no-deposito + Quant-transportada
  298. set energia energia + 10 * Quant-transportada
  299. set Quant-transportada 0
  300. ]
  301. [
  302. ifelse ( [pcolor] of patch-ahead 1 = blue )
  303. [
  304. fd 1
  305. set energia energia - 1
  306. ]
  307. [
  308. ifelse ( [pcolor] of patch-right-and-ahead 90 1 = blue )
  309. [
  310. rt 90
  311. set energia energia - 1
  312. ]
  313. [
  314. ifelse random 101 < 50
  315. [
  316. fd 1
  317. set energia energia - 1
  318. ]
  319. [
  320. rt 90
  321. set energia energia - 1 ]
  322. ]
  323. ]
  324. ]
  325.  
  326.  
  327. end
  328. to verificar-morte
  329. ask comiloes
  330. [
  331. if ( energia <= 0)
  332. [
  333. die
  334. ]
  335. ]
  336. ask limpadores
  337. [
  338. if( energia <= 0 )
  339. [
  340. die
  341. ]
  342. ]
  343.  
  344.  
  345. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement