Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- breed [comiloes comilao ]
- breed [limpadores limpador]
- turtles-own [energia]
- globals [Quant-transportada acumulado-no-deposito]
- to setup
- clear-all
- setup-patches
- setup-turtles
- reset-ticks
- end
- to setup-patches
- set-patch-size 15
- ask patches with [pcolor = black]
- [
- if random 101 < nLixoNormal
- [
- set pcolor yellow
- ]
- ]
- ask patches with [pcolor = black]
- [
- if random 101 < nLixoToxico
- [
- set pcolor red
- ]
- ]
- ask patches with [pcolor = black]
- [
- if random 101 < nComida
- [
- set pcolor green
- ]
- ]
- ask patches with [pcolor = black ]
- [
- if random 101 < nCaixoteLixo
- [
- set pcolor blue
- ]
- ]
- set Quant-transportada 0
- end
- to setup-turtles
- create-comiloes nComiloes
- [
- set size 2
- set color pink
- set shape "person"
- setxy random-xcor random-ycor
- set energia Energiacomida
- ]
- create-limpadores nlimpadores
- [
- set size 2
- set color blue
- set shape "person"
- setxy random-xcor random-ycor
- set energia Energiacomida
- ]
- end
- to go
- move-comiloes
- move-limpadores
- verificar-morte
- if count turtles = 0
- [
- stop
- ]
- tick
- end
- to move-comiloes
- ask comiloes
- [
- ifelse [pcolor] of patch-ahead 1 = green
- [
- fd 1
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-left-and-ahead 90 1 = green
- [
- left 90
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-right-and-ahead 90 1 = green
- [
- rt 90
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-here = green
- [
- set pcolor black
- set energia energia + EnergiaComida
- ask n-of 1 patches with [pcolor = black] [ set pcolor green ]
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-ahead 1 = red
- [
- set energia energia - energia / 10
- rt 90
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-left-and-ahead 90 1 = red
- [
- fd 1
- set energia energia - energia / 10
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-right-and-ahead 90 1 = red
- [
- fd 1
- set energia energia - energia / 10
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-ahead 1 = yellow
- [
- set energia energia - energia / 20
- rt 90
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-left-and-ahead 90 1 = yellow
- [
- fd 1
- set energia energia - energia / 20
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-right-and-ahead 90 1 = yellow
- [
- fd 1
- set energia energia - energia / 20
- set energia energia - 1
- ]
- [
- ifelse random 101 < 90
- [
- fd 1
- set energia energia - 1
- ]
- [
- ifelse random 101 < 50
- [
- rt 90
- set energia energia - 1
- ]
- [
- lt 90
- set energia energia - 1
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- end
- to move-limpadores
- ask limpadores
- [
- ifelse ( Quant-transportada < nQuant-Trasporte )
- [
- ifelse [pcolor] of patch-ahead 1 = green
- [
- fd 1
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-here = green
- [
- set pcolor black
- ask n-of 1 patches with [pcolor = black ] [ set pcolor green ]
- ifelse ( Quant-transportada < nQuant-trasporte / 2)
- [
- set energia energia + EnergiaComida
- ]
- [
- set energia energia + EnergiaComida / 2
- ]
- ]
- [
- ifelse [pcolor] of patch-right-and-ahead 90 1 = green
- [
- rt 90
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-ahead 1 = red
- [
- fd 1
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-right-and-ahead 90 1 = red
- [
- rt 90
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-here = red
- [
- ifelse ( Quant-transportada < nQuant-Trasporte )
- [
- set pcolor black
- ask n-of 1 patches with [pcolor = black ] [ set pcolor red ]
- set Quant-transportada Quant-transportada + 1
- ]
- [
- procurar-azul
- ]
- ]
- [
- ifelse [pcolor] of patch-ahead 1 = yellow
- [
- fd 1
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-right-and-ahead 90 1 = yellow
- [
- rt 90
- set energia energia - 1
- ]
- [
- ifelse [pcolor] of patch-here = yellow
- [
- ifelse ( Quant-transportada + 2 <= nQuant-trasporte )
- [
- set pcolor black
- ask n-of 1 patches with [pcolor = black ] [ set pcolor yellow ]
- set quant-transportada quant-transportada + 2
- ]
- [
- procurar-azul
- ]
- ]
- [
- ifelse (Quant-transportada = nQuant-Trasporte)
- [
- if [pcolor] of patch-here = blue
- [
- set acumulado-no-deposito acumulado-no-deposito + Quant-transportada
- set energia energia + 10 * Quant-transportada
- set Quant-transportada 0
- ]
- ]
- [
- ifelse random 101 < 50
- [
- fd 1
- set energia energia - 1
- ]
- [
- rt 90
- set energia energia - 1
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- ]
- [
- procurar-azul
- ]
- ]
- end
- to procurar-azul
- if (Quant-transportada = nQuant-Trasporte )
- [
- ifelse ( [pcolor] of patch-here = blue )
- [
- set acumulado-no-deposito acumulado-no-deposito + Quant-transportada
- set energia energia + 10 * Quant-transportada
- set Quant-transportada 0
- ]
- [
- ifelse ( [pcolor] of patch-ahead 1 = blue )
- [
- fd 1
- set energia energia - 1
- ]
- [
- ifelse ( [pcolor] of patch-right-and-ahead 90 1 = blue )
- [
- rt 90
- set energia energia - 1
- ]
- [
- ifelse random 101 < 50
- [
- fd 1
- set energia energia - 1
- ]
- [
- rt 90
- set energia energia - 1 ]
- ]
- ]
- ]
- ]
- end
- to verificar-morte
- ask comiloes
- [
- if ( energia <= 0)
- [
- die
- ]
- ]
- ask limpadores
- [
- if( energia <= 0 )
- [
- die
- ]
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement