How to let other turtles inherit event from other turtle? In my code I have this simple setup that has 50 turtles. I have also a panic button that if it is clicked some turtle will set their mood to panic and color to orange.
I have some changes with this one. Disregard the percentage. Now all turtles will check around them if they found/see turtles with mood = panic and color orange they will also go to panic and color orange.
turtles-own[
mood
]
to setup
__clear-all-and-reset-ticks
create-Humans
end
to create-humans
crt 50[
setxy random-pxcor random-pycor
set color blue
set mood "calm"
]
end
to panic
ask n-of initial-panic turtles [
set mood "panic"
set color orange
]
end
I tried this.
to go
ask turtles[
fd 1
lt random 90]
ask turtles[
ask turtles in-cone 3 60
[ if any? turtles with [ color orange]
set mood "panic"] ]
end
But it doesn't work.
welcome to StackOverflow, you can try this:
turtles-own[
mood
]
to setup
__clear-all-and-reset-ticks
create-Humans
panic
end
to create-humans
crt 50[
setxy random-pxcor random-pycor
set color blue
set mood "calm"
]
end
to panic
ask n-of initial-panic turtles [
set mood "panic"
set color orange
]
end
to go
ask turtles[
fd 1
lt random 90
if any? turtles in-cone 3 60 with [ color = orange]
[set mood "panic"
set color orange
]
]
end
Related
I am trying to build a model where turtle move one patch per tick with random movement. I am looking for a solution to increase the number of turtle per tick based on the percentage. For ex. In the beginning there are 7 turtles, by each tick they should increase by following percentage:
10.72%
10.83%
10.93%
11.03%
11.11%
11.19%
11.27%
11.33%
11.39%
11.45%
Not sure if this is possible? If needed this can be round up to whole number.
If this is not possible, how can I increase the turtle number by 11% each tick for 10 ticks then after 12% each tick for another 10 ticks and so on?
Below is the code that I am using.
to setup
clear-all
setup-turtles
setup-patches
reset-ticks
end
to setup-patches
ask patches [ set pcolor green ]
end
to setup-turtles
create-turtles tourists [setxy random-xcor random-ycor ]
ask turtles [ set shape "person" set size 2 ]
end
to go
if ticks >= 130 [ stop ]
move-turtles
eat
tick
end
to move-turtles
ask turtles [ right random 360 forward 1]
end
to eat
ask turtles [ if pcolor = green [ set pcolor black ] ]
end
Thank you for your support.
Avi
I think your model is very similar to 'Rabbits Grass Weeds' in the Models Library so you might want to have a look at that to get some ideas. Focusing just on the revised question of moving to a green patch, you need with, which will restrict choices. Note that the code below will break if there are no neighbouring patches that are green.
to setup
clear-all
setup-turtles
setup-patches
reset-ticks
end
to setup-patches
ask patches [ set pcolor green ]
end
to setup-turtles
create-turtles 7 [setxy random-xcor random-ycor ]
ask turtles [ set shape "person" set size 2 ]
end
to go
if ticks >= 130 [ stop ]
move-turtles
increase-turtles
tick
end
to move-turtles
ask turtles [ move-to one-of neighbors with [pcolor = green] ]
end
to increase-turtles
ask one-of turtles [ hatch 1 ]
end
I used hatch in this code, which gets one turtle to create another turtle at the same place with the same colour etc. If you want to just create a new turtle in exactly the same way as your original turtles, then you want something more like this.
to setup
clear-all
make-turtles 7
setup-patches
reset-ticks
end
to setup-patches
ask patches [ set pcolor green ]
end
to make-turtles [ num ]
create-turtles num
[ setxy random-xcor random-ycor
set shape "person"
set size 2
]
end
to go
if ticks >= 130 [ stop ]
move-turtles
increase-turtles
tick
end
to move-turtles
ask turtles [ move-to one-of neighbors with [pcolor = green] ]
end
to increase-turtles
make-turtles 1
end
In this case, I have made a new procedure (called make-turtles) that creates as many turtles as you specify, randomly locates them etc. In setup, I call it to make 7 turtles, and then later on just make 1 each time.
I start developping with Netlogo and I face the problem that I want to make all Turtles moving in one way which has the Black Color. How can I do that ? I tried with patch-ahead but I didn't success.
Anyone have a solution ? I will be grateful.
to setup
clear-all
import-drawing "patch.png"
create-turtles 10 [set xcor -10 set ycor -13]
ask turtles [set color white]
ask turtles [set shape "bug"]
reset-ticks
end
to bouge
ask turtles[
fd 1
]
end
to go
bouge
ask turtles [if [pcolor] of patch-ahead 6 != black [set heading heading - 100] ]
end
enter image description here
You should use something like these:
set black-patches patches with [pcolor = black]
ask turtles [
face one-of black-patches
]
Bests, Ervin
When the turtles have covered the world in patches, I would like the turtles to stop on the last one so that I can record the amount of ticks it took.
Here is my code so far:
globals [marked-patches angle nextangle]
to setup ca ask patches [ set pcolor black ] crt turtle_amount
[set color red
set size 1
setxy (random 20) (random 20)] reset-ticks
end
to go ask turtles [
fd 1
rt random trt_ang
lt random trt_ang
if pcolor = black [set pcolor yellow] ]
tick end
In go, specifically in the turtle command, you can add:
to go
ask turtles [
fd 1
rt random trt_ang
lt random trt_ang
if pcolor = black [
set pcolor yellow
if count patches with [pcolor = black] = 0 [
stop
]
]
]
tick
end
turtles-own [wages]
to setup
clear-all
setup-patches
setup-turtles
reset-ticks
end
to go
move-turtles
get-employed
tick
end
to move-turtles
ask turtles [
right random 360
forward 1
]
end
to get-employed
ask turtles [
if pcolor = blue [
set color green
set wages wages + 10
]
ifelse show-wages?
[ set label wages ]
[ set label " " ]
]
end
to setup-patches
ask patches [set pcolor pink ]
patch 0 0 [ set pcolor blue ]
end
to setup-turtles
create-turtles 80
ask turtles [ setxy random-xcor random-ycor ]
ask turtles [ set color red]
end
I want to add the code to select the first 20 percent of the 80 turtles who comes in contact with the patch having color blue.
In your question is not clear how you will use the first 20% of turtles who get the blue patch so i assume you just want to store them in order to use this information later.
I would add a turtles-own called is-first-20-percent? set to false for every turtle.
Then, at the end of the go procedure, before the tick i would execute the check-20 procedure as following:
to check-20
if count turtles with [color = green] = (count turtles * 20 / 100) [
ask turtles with [color = green] [set is-first-20-percent? true]
]
end
In every moment you can retrieve the first 20% of turtles who reached the blu zone with the command:
ask turtles with [is-first-20-percent?] [ ... do something ... ]
This code is working because 20% of 80 is an integer number (16) but if you plan to modify the starting number of turtles i suggest to modify the check-20 procedure as following:
to check-20
if (count turtles with [color = green] >= (count turtles * 20 / 100)
and count turtles with [is-first-20-percent?] = 0) [
ask turtles with [color = green] [set is-first-20-percent? true]
]
end
this is my code , i need to fit the slider so i edit the pen size my global variable is turtle-pen-size
to setup
clear-all
ask patches [ set pcolor sky ]
setup-turtles
end
to setup-turtles
create-turtles turtles-to-create
[ set color lime setxy random-xcor random-ycor set size size-of-turtle]
set-default-shape turtles "circle"
end
to go
ask turtles[
ifelse pen-down? [ pen-down ] [ pen-up ]
fd 1
]
end
You could set pen-size where you are asking each turtle to pen-down
I am not exactly sure what you want to do in your code, the pen-down? is not defined in your code, I assume you have a turtle property which defines a pen-down? to one of values of true and false, if you define it a global value I believe all of your turtles end up with same value, for pen-size you can use following code
set pen-size turtle-pen-size
This is your completed code:
turtles-own[pen-down?]
to setup
clear-all
reset-ticks
ask patches [ set pcolor sky ]
setup-turtles
end
to setup-turtles
create-turtles turtles-to-create
[
set color lime
setxy random-xcor random-ycor
set size size-of-turtle
set pen-size turtle-pen-size
set pen-down? one-of [true false]
]
set-default-shape turtles "circle"
end
to go
ask turtles[
ifelse pen-down?
[ pen-down ]
[ pen-up ]
fd 1
]
tick
end